LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to add a Linux partition to a USB thumb drive? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-add-a-linux-partition-to-a-usb-thumb-drive-4175688687/)

pathfinder027 01-16-2021 11:20 AM

How to add a Linux partition to a USB thumb drive?
 
I just got the 2018 Sixth Edition of the book, _Linux in Easy Steps_, and on pages 22-23 it suggests using a USB memory stick ("thumb drive") as a backup medium. I deleted all the Windows files from a 64GB Patriot thumb drive, but it still has the Windows file system on it. When I tried to back up Linux to it I got the message, "Selected device does not have Linux partition."

How do I add a Linux partition to the USB memory stick?

jsbjsb001 01-16-2021 11:30 AM

Quote:

Originally Posted by pathfinder027 (Post 6208419)
I just got the 2018 Sixth Edition of the book, _Linux in Easy Steps_, and on pages 22-23 it suggests using a USB memory stick ("thumb drive") as a backup medium. I deleted all the Windows files from a 64GB Patriot thumb drive, but it still has the Windows file system on it. When I tried to back up Linux to it I got the message, "Selected device does not have Linux partition."

How do I add a Linux partition to the USB memory stick?

You can just use a partitioning utility to do it, there are several of them available. Gparted is a popular utility, and it can also format a newly created partition with a filesystem too (including both Linux and windows filesystems).

How exactly are you trying to "back up Linux to it" though? As you would normally use a program to backup an operating system rather than just copying the files manually.

hazel 01-16-2021 12:05 PM

A lot of the memory sticks you buy these days aren't partitioned at all. They just have one single Windows FAT32 filesystem stretching across the whole drive. There are about three different ways that I can think of to back up onto a drive like that:

1) jsb's suggestion. Use gparted to create a partition table on the stick and make one or more linux partitions on it. This is the most flexible solution. For example, you could use one of those partitions for a periodic backup of your system and another for day-to-day data file backups.
2) Use the mkfs.ext4 program to turn your unpartitioned stick into a single Linux filesystem which you can then dump onto. This is a bit more dangerous because you have to be very sure you are formatting the stick and not any part of your hard drive. In Linux as in Windows, formatting destroys data!
3) Use the modprobe command to load the vfat driver into your kernel. You should then be able to copy onto your stick as is. This is probably the safest way, but tiresome as you have to do it each time you make a copy.

fatmac 01-16-2021 12:27 PM

It'll likely make your learning a bit easier if you put an ext4 file system onto it.

(You can save some extra MBs by using the -m option when creating it, I use -m0 for small drives.)

jsbjsb001 01-17-2021 09:01 AM

Quote:

Originally Posted by hazel (Post 6208427)
A lot of the memory sticks you buy these days aren't partitioned at all. They just have one single Windows FAT32 filesystem stretching across the whole drive. ...

While I know floppy disks don't have partitions; I don't honestly buy the argument that "some USB sticks don't have partitions at all". Surely there would still be at least one partition that, in that case, covers the whole drive. How would you format a USB drive with a filesystem that isn't partitioned? I don't see how you would able to.

hazel 01-17-2021 09:02 AM

Quote:

Originally Posted by jsbjsb001 (Post 6208726)
How would you format a USB drive with a filesystem that isn't partitioned? I don't see how you would able to.

You format /dev/sdb or whatever.

computersavvy 01-17-2021 09:27 AM

Quote:

Originally Posted by hazel (Post 6208727)
You format /dev/sdb or whatever.

Remember that /dev/sdb is the device. /dev/sdb1 would be the partition.

I have never seen a flash drive that did not have a partition. Yes, they usually have a single vfat partition, but always have a partition when purchased new.

@pathfinder027
As was said before, partitioning can be done with any of the partitioning tools, and gparted is the gui version of parted. You probably have parted, fdisk, and possibly gdisk available with a new install. gparted may need to be installed. Any of those can be used to change the partition type from msdos to linux.
Gparted can also do the formatting as ext4 or you can use mkfs.ext4 to format it for you. Remember, the partition (ie. /dev/sdb1) is what needs to be formatted, not /dev/sdb.

michaelk 01-17-2021 09:29 AM

I have not purchased a USB drive without being partitioned in awhile and can not say that it is still true but yes as an example Imation which no longer exists sold flash drives without partitions. They mounted on both linux and Windows without any problems.

We expect a drive to be partitioned by convention and for various reasons but it does not matter. I know formatting ext filesystems actually reserves the first sector so that grub can be installed without a partition table. Totally unrelated but DVRs in the early days wrote video data to an unformatted raw disk for performance.

hazel 01-17-2021 09:39 AM

It's easy to find out one way or another. Plug in your device and look at dmesg|tail. If it reports both sd? and sd?1, there is a partition table on the device. If only sd?, there isn't.

jsbjsb001 01-17-2021 09:40 AM

Quote:

Originally Posted by computersavvy (Post 6208739)
...
I have never seen a flash drive that did not have a partition.

Same here.

Quote:

Yes, they usually have a single vfat partition, but always have a partition when purchased new.
...
That's always been the case as far as I've seen.

hazel 01-17-2021 09:43 AM

I just plugged in the most recent one I bought and it says:
Code:

[19333.398840] scsi 2:0:0:0: Direct-Access    hp      v212w            8.07 PQ: 0 ANSI: 4
[19333.400676] sd 2:0:0:0: [sdb] 30871552 512-byte logical blocks: (15.8 GB/14.7 GiB)
[19333.401423] sd 2:0:0:0: [sdb] Write Protect is off
[19333.401429] sd 2:0:0:0: [sdb] Mode Sense: 23 00 00 00
[19333.402119] sd 2:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[19333.414144]  sdb:
[19333.418434] sd 2:0:0:0: [sdb] Attached SCSI removable disk

See? No partition table on that one.

ondoho 01-17-2021 11:12 AM

Quote:

Originally Posted by hazel (Post 6208727)
You format /dev/sdb or whatever.

It is possible.
I just did
Code:

mkfs.ext4 /dev/sde
on a USB stick. Or fat.
And it's usable.
I've also created encrypted USB sticks like this.


All times are GMT -5. The time now is 02:38 PM.