Windows users and new Linux users are usually not aware of the steps to configure a new disk drive. Most disk drives are configured with Globally Unique Identifier (GUID) formatted partition tables which are required for booting via the Unified Extensible Firmware Interface (UEFI).
In this tutorial we will learn the steps necessary in preparing a new disk drive for use with Linux.
To view all of the block oriented devices on a Linux system.
lsblk
New disk drives which have not been used before have no partition table and an easy way to prepare a drive is to enter the “parted” utility. The following command assumes that your new and unused drive is “sdb”. The “lsblk” command will help you identify the drive name for your drive.
Be sure to identify the correct drive, because the following commands will destroy everything on the drive that you select.
sudo parted /dev/sdb
Create a GUID partition table on the new “sdb” drive:
mklabel gpt
My drive is 100GB in size, so I create a 100GB partition with a 1MB block size:
mkpart primary ext4 1MB 100GB
Quit the parted program:
quit
List the partitions on the new drive:
sudo fdisk -l /dev/sdb
In order to mount a partition, you will need a mount point. A mount point is a folder anywhere on the system. It is good practice to place mount point folders in /mnt:
sudo mkdir /mnt/mydrive
You can mount the drive for use on the system:
sudo mount -t auto /dev/sdb1 /mnt/mydrive
If you reboot, the drive will not continue to be mounted and you will need to mount it again.
To check to see the drive is mounted:
df
To dismount the drive:
sudo umount /dev/sdb1
To have the drive mounted when the system boots is often desirable. The first step in doing this is to find the UUID of the partition that you want to mount.
sudo blkid /dev/sdb1
Next edit the file systems table:
sudo nano /etc/fstab
Insert a line at the end of the fstab file indicating the UUID from the blkid command and the mount point as follows:
UUID=f486841f-aaf5-4cca-8fd3-3d6262b7ed08 /mnt/mydrive ext4 rw,exec 0 0
Save the file with a CTRL O followed by the enter key and a CTRL X to exit the nano editor.
Reboot your system:
sudo reboot now
When the system reboots, you should be able to see the drive is mounted with the following command:
df
To make accessing the drive easier, you can create a symbolic link in your home folder:
ln -s /mnt/mydrive
By default, mount points in /mnt are owned by the system. The assumption is that the system administrator will create folders owned by users.
In the tutorial I showed that if you change ownership of the mount point, you can own the entire drive.
sudo chown scott:scott /mnt/mydrive
You can delete the symbolic link we created above like you would delete any other file:
rm mydrive