How to format drive to ext4 and mount

Find the path of your drive with the following:

lsblk

This will show you the name of the drive such as sda, sdb etc. Assuming the drive name is sdb, you can format the drive with ext4 as follows:

mkfs -t ext4 /dev/sdb

This will format the whole drive with ext4, and not just a partition. If you would like a partition, you can create one with fdisk, and then format the partition with ext4.

The next step is to create the mount point, and actually mount the newly formatted ext4 drive to the created mount point. Start with creating the directory to where the disk will be mounted:

mkdir /mnt/my_drive

Next, mount the drive as follows:

mount -t auto /dev/sdb /mnt/my_drive/

You’ll notice your drive will now be mounted to the mount point by running the following:

df -h

If you reboot the machine, you’ll notice that the drive will no longer be mounted to the mount point. This has to be achieved by editing /etc/fstab. But first, you need to get the UUID of the drive as follows:

blkid

Assuming you see that /dev/sdb has the following UUID: 04e8dc52-0a0d-4e9b-930c-89cbde33a79f you can now add a new entry into /etc/fstab:

nano /etc/fstab

Paste the following:

UUID=05e8dd52-0a0d-4f9b-330c-89cbde33a79d  /mnt/my_drive  ext4  defaults  0  0

Now when you reboot your machine, the drive will be auto mounted to /mnt/my_drive