Format and Mount External Hard Drives in Linux

Assuming you’ve just bought a new external hard drive or you have one that’s already in use these are the steps you need to take to make it usable with Linux.

⚠️ Be aware that following these steps will reformat the drive causing all data to be permanently erased. You’ve been warned.

First connect the USB drive to the Linux computer and open a terminal session. Run the following command.

$ lsblk -o UUID,NAME,FSTYPE,SIZE,LABEL,MODEL

This will out put something like this.

UUID                                 NAME        FSTYPE   SIZE LABEL  MODEL
                                     sda                931,5G        External_USB_3.0
19b2561e-cd18-46dd-bf87-b176c7cdd7a0 └─sda1      ext4   931,5G        
                                     mmcblk0              7,4G        
5203-DB74                            ├─mmcblk0p1 vfat     256M boot   
2ab3f8e1-7dc6-43f5-b0db-dd5759d51d4e └─mmcblk0p2 ext4     7,2G rootfs 

Note the name of the attached drive, in my case sda1 and run the command below using the name of your drive. This command will format the drive as ext4.

$ sudo mkfs.ext4 /dev/sda1

The output of this command will include a UUID, copy this string for the next step. Open the /etc/fstab file using a text editor and (nano in my example) add this line using the UUID you copied from the previous command.

$ sudo nano /etc/fstab

# add this line
 UUID=this_is_your_uuid /mnt/hdd ext4 rw,nosuid,dev,noexec,noatime,nodiratime,auto,nouser,async,nofail 0 2

Make a directory to mount the drive to, /mnt/hdd in this example, and mount the drive. The mount point should match the fstab file you just created.

$ sudo mkdir /mnt/hdd
$ sudo mount -a

Check the file is mounted by running df (disk free).

$ df /mnt/hdd/
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sda1      960379496 78000 911447092   1% /mnt/hdd

Finally change the owner of the mounted drive to your normal user, in my case pi (it’s currently owned by root).

$ sudo chown -R pi:pi /mnt/hdd/

Join the conversation

1 Comment

Leave a comment

Your email address will not be published. Required fields are marked *