View Categories

Mount an additional storage drive in Linux

2 min read

When a dedicated server is configured with additional storage drives, the server will be delivered with these drives unmounted from the operating system. This allows the flexibility to mount the drive in the preferred location for your application.

A drive can be easily prepared, mounted and added to startup config so it is available to use…

 

Identify drive #

Identify the additional drive that we want to setup.

First, confirm the device name for the new drive by entering:

lsblk

In this example output, the 18TB (16.4T) drive named sda is blank and ready to add. Its full location will be /dev/sda:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 16.4T 0 disk
nvme0n1 259:0 0 894.3G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 892.8G 0 part /
└─nvme0n1p3 259:3 0 976M 0 part [SWAP]

 

Partition drive #

Its best practice to first create a partition table on the drive for greater flexibility and data integrity.

Use fdisk to select and configure the drive:

fdisk /dev/sda

Type g and press enter to create a new GPT partition table:

g

Type n and press enter to create a new partition:

n

In the next section you’ll be promtped for a partition number, first and last sectors. Pressing enter accepts the default value and will assign all available drive space.

Example output:

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-35156656094, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-35156656094, default 35156654079):
 
Created a new partition 1 of type ‘Linux filesystem’ and of size 16.4 TiB.

Type w and press enter to write these changes to the drive and exit fdisk:

w

If you now revisit the lsblk command, you’ll see a partition sda1 has been created on drive sda:

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 16.4T 0 disk
└─sda1 8:1 0 16.4T 0 part
nvme0n1 259:0 0 894.3G 0 disk
├─nvme0n1p1 259:1 0 512M 0 part /boot/efi
├─nvme0n1p2 259:2 0 892.8G 0 part /
└─nvme0n1p3 259:3 0 976M 0 part [SWAP]

 

Format partition #

Create a filsystem on the new partition that the system can use.

Enter the following to format the new parition with an ext4 filesystem:

mkfs.ext4 /dev/sda1

This may take some time for larger drives.

 

Mount drive #

The drive is ready for use, but accessing it requires a mount point.

Create a new directory for the drive to mount to, in this example we’ll mount to /storage:

mkdir /storage

Now the drive can be mounted to this directory, enter:

mount /dev/sda1 /storage

The mount can be verified by using df -h, this is the example output:

Filesystem Size Used Avail Use% Mounted on
udev 32G 0 32G 0% /dev
tmpfs 6.3G 936K 6.3G 1% /run
/dev/nvme0n1p2 878G 1.8G 832G 1% /
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/nvme0n1p1 511M 5.9M 506M 2% /boot/efi
tmpfs 6.3G 0 6.3G 0% /run/user/0
/dev/sda1 17T 24K 16T 1% /storage

 

Auto-mount on boot #

At this point, the mount would not survive a reboot. We’ll need to add it to fstab to have it automatically mount at system boot.

Find the drive’s UUID with:

blkid /dev/sda1

This will output the following, copy the UUID value (excluding quotation marks):

/dev/sda1: UUID=”XXXX-XXXX-XXXX-XXXX” BLOCK_SIZE=”4096″ TYPE=”ext4″ PARTUUID=”332…

Use a text editor to modify the fstab:

/etc/fstab

At the bottom of the file, add this line at the bottom, replacing XXXX-XXXX-XXXX-XXXX with the actual UUID discovered above:

UUID=XXXX-XXXX-XXXX-XXXX /storage ext4 defaults 0 2

The drive will now automatically mount to /storage after each reboot.