Jun's Blog

Output, activities, memo and etc.

Format USB drive on Fedora

This blog is a note on how to format a USB drive on Fedora Linux 36. I have Framework Laptop, and I have a 256 GB expansion card. So, I formatted the USB disk to use on Fedora Linux 36.

Even when it is not formatted, you can see the device. I referred to the [1] mainly.

The nvme0n1 is the main internal disk, 2 TB. The sda is the USB disk, 256 GB. In my case, the sda is not recognized at first. When using the storage expansion card on another, USB-C port, it was recognized.

Detect the storage

$ lsblk
NAME                                          MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
loop0                                           7:0    0     4K  1 loop  /var/lib/snapd/snap/bare/5
...
loop12                                          7:12   0   219M  1 loop  /var/lib/snapd/snap/gnome-3-34-1804/77
sda                                             8:0    0 232.9G  0 disk  
└─sda1                                          8:1    0 232.9G  0 part  
zram0                                         252:0    0     8G  0 disk  [SWAP]
nvme0n1                                       259:0    0   1.8T  0 disk  
├─nvme0n1p1                                   259:1    0   600M  0 part  /boot/efi
├─nvme0n1p2                                   259:2    0     1G  0 part  /boot
└─nvme0n1p3                                   259:3    0   1.8T  0 part  
  └─luks-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX 253:0    0   1.8T  0 crypt /home
                                                                         /

Another useful command is inxi. The command below prints many information.

$ sudo dnf install inxi

$ inxi -Fzx
...

The command below only prints the drives information.

$ inxi -D
Drives:
  Local Storage: total: 2.05 TiB
    used: 20.31 GiB (1.0%)
  ID-1: /dev/nvme0n1 vendor: Western Digital
    model: WD BLACK SN750 2TB size: 1.82 TiB
  ID-2: /dev/sda type: USB model: USB DISK 3.2
    size: 232.89 GiB

Create partition.

$ which fdisk
/usr/sbin/fdisk

$ rpm -qf /usr/sbin/fdisk
util-linux-2.38-1.fc36.x86_64
$ sudo fdisk /dev/sda

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

Command (m for help):
Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

Then create DOS disklabel.

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x5160f91d.

Added a new partition. Proceeded with default choices. It's just one partition of the full size.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-488397167, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-488397167, default 488397167): 

Wrote table to disk and exit

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

You can see the partition.

$ ls -l /dev/sda1
brw-rw----. 1 root disk 8, 1 Aug 23 21:56 /dev/sda1

Then formatted with the vfat file type.

$ sudo mkfs.vfat /dev/sda1

If I ran a filer, the drive was automatically mounted.

$ nautilus . &

Then I could check the USB storage from df command.

$ df -hT | grep sda
/dev/sda1      vfat      233G   64K  233G   1% /run/media/jaruga/1A53-9E55

References