Format USB drive to ext4 and mount

Posted under » Linux » Raspberry Pi on 10 Mar 2022

Before formatting, locate a partition you wish to format. To do so, run the 'lsblk' command that displays block devices. Block devices are files that represent devices such as hard drives, RAM disks, USB drives, and CD/ROM drives. The lsblk command without additional options does not display information about the devices’ file systems. To display a list containing file system information, add the -f option

NAME        FSTYPE   FSVER LABEL       UUID       FSAVAIL FSUSE% MOUNTPOINTS
sda         ext4     1.0   satu        a9462bc5-11ac-45ca  199.7G     4% /kioxia
mmcblk0                                                                                    
├─mmcblk0p1 vfat     FAT32 system-boot D7A9-3EE6           110.4M    56% /boot/firmware
└─mmcblk0p2 ext4     1.0   writable    09799e9f-8009-4b0c    5.2G    59% /

For a more detailed info use 'fdisk l'. Note : I have ommitted the loops. You will notice, the SSD is much bigger and faster

$ fdisk -l

Disk /dev/mmcblk0: 14.84 GiB, 15931539456 bytes, 31116288 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x2da91795

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1 *      2048   526335   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      526336 31116254 30589919 14.6G 83 Linux

Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: XCERIA SATA SSD 
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes

If you want to know the systems configuration, you use the lshw command.

to know the exact partition, you use the parted command.

$ parted -l
Model: SMI USB DISK (scsi)
Disk /dev/sda: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  16.1GB  16.1GB  primary  fat32        boot, lba

Model: SD SU16G (sd/mmc)
Disk /dev/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  269MB   268MB   primary  fat32        boot, lba
 2      269MB   15.9GB  15.7GB  primary  ext4

I have identified that the USB drive that I want to format is /dev/sda.

The general syntax for formatting disk partitions in Linux is:

$ mkfs [options] [-t type fs-options] device [size]
$ sudo mkfs -t ext4 /dev/sda
$ sudo mkfs -t vfat /dev/sda
$ sudo mkfs -t ntfs /dev/sda

In my case I want to use ext4. You don't need to create a linux partition if you don't need to delete or split the existing partition. After executing the mkfs command. Run lsblk or parted command to see that the usb drive has indeed been formated.

$ mkdir /mnt/purple
$ mount /dev/sda /mnt/purple

You are now able to store files on the USB disk. Make sure you chown the directory appropriately.

You might also want to fstab the drive to make the mount permanent or automatically.

However, to boot from your USB SSD disk could be a better option.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT