DEV Community

hub
hub

Posted on

formating a USB stick on a linux machine

well i look for the most apropiate way to format a USB stick

in other words: what is the best practice for formatting a USB stick? Is it best to format the USB stick only for Linux use rather than for both Linux and Windows use?

i have heard that one of the best Filesystem is exFAT: Especially on USB pendrives and SD cards and the like the exFAT provides a good method to use a Filesystem.

i have made some investigations and did some google-search: the so called exFAT is, roughly speaking, a revision of the legendary system FAT32 without the 4GB max file size limitation.

i have had a look at some manpages and tried to find out which is the best way to get a usb-stick formated with exFAT

first of all: If not installed, we will have to install exFAT support.

$ sudo apt install exfatprogs # Debian/Ubuntu
$ sudo pacman -S exfatprogs # Arch Linux/Manjaro

From here, you have mainly two options: by the way: we wont make use a graphical tools like gparted or the command line (which is more fun).

first of all - we have to take care for the following things and steps:

  • Plug-in the USB pendrive/SD card into the system afterwards
  • we have to identify the device. It should be one of /dev/sd thats for sure.

If we use the commandline then we run the below command which will see the connected devices and all the partition mount points.

In this example, /dev/sdb is the device,

with two partitions, the first of which is mounted.

```$ lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 6:46 1 30G 0 disk
├─sdb1 6:47 1 256M 0 part /media/myuser/mydevice
└─sdb2 6:38 1 29,7G 0 part
nvme0n1 259:0 0 967,5G 0 disk
├─nvme0n1p1 259:1 0 532M 0 part /boot/efi
├─nvme0n1p2 259:2 0 74G 0 part /
├─nvme0n1p3 259:3 0 266G 0 part /home
├─nvme0n1p4 259:4 0 58G 0 part [SWAP]
├─nvme0n1p5 259:5 0 458G 0 part /data
├─nvme0n1p6 259:6 0 17M 0 part
└─nvme0n1p7 259:7 0 125G 0 part
Unmount mounted partitions.




and then afterwards ..


Enter fullscreen mode Exit fullscreen mode

$ umount /dev/sdb1



now - at this point we have to create a new partition table and partition of type



```HPFS/NTFS/ - and here we use exFAT.
$ sudo fdisk /dev/sdb # Pay attention! No final digit is used.```



Welcome to fdisk (util-linux 2.xy).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help):


```Create a new (dos) partition table: press o and enter.
Create a new partition: press n, enter and accept default options.
Change the partition type to HPFS/NTFS/exFAT: press t, enter, 7, enter.
Quit saving changes: press w and enter.
You can quit without saving changes: press q and enter.
Format the partition.
$ sudo mkfs.exfat -n "my label" /dev/sdb1 # Pay attention! Final digit is used.
mkexfatfs 1.x.y
Creating... done.
Flushing... done.
File system created successfully.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)