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

$ lsblk -f
..
sda
└─sda1      vfat     FAT32             9FBB-1CF1
mmcblk0
├─mmcblk0p1 vfat     FAT32 system-boot 00E2-9AC8      152.4M    40% /boot/firmware
└─mmcblk0p2 ext4     1.0   writable    fc897537-0991   10.9G    20% /

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.

After mounting the USB, you might want to boot from your USB SSD disk.

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