Mounting a new disk in Linux

This guide will assume the new disk is empty. If this is not the case, ignore the steps marked red, as the disk will be partitioned and formatted.
If you already have a partition and only wish to mount it, you may skip to the blue steps.

Parted will be used to create a new partition on the presumably unpartitioned disk, so ensure you have parted installed to follow this guide.
First, we need to determine which disk we wish to create a partition for and mount it. This can be done with 'fdisk'.

fdisk -l

The guide will assume you wish to format, partition and mount /dev/sdb. So we'll open up parted, using /dev/sdb.

parted /dev/sdb

Assuming the disk currently has no partition table yet, we'll need to create one. Doing this will render all data on the disk unusable.

For disks 2 terabytes or smaller an msdos partition table may be selected, for disks greater than 2 terabytes a GUID partition table (GPT) is required.

mklabel msdos


mklabel gpt

We'll now create a partition the size of the whole disk. If you wish to only partition a portion of the disk, change the variables to your wishes. Whilst still in parted, use the command below.

mkpart primary 0% 100%

The newly created partition in this case is now named /dev/sdb1, but is lacking a filesystem which we'll need to create before we are able to mount it. Parted would have to be quit either via using CTRL+C or entering to exit the software.

In most cases an ext4 filesystem will suffice, but for partitions bigger than 15.7TB an xfs filesystem is recommended. For the latter you might need to install xfsprogs.

mkfs.ext4 /dev/sdb1


mkfs.xfs /dev/sdb1

Now our disk/partition/filesystem is ready to mount, which we'll do using block ids, as these are unique per filesystem and will stay consistent among it's lifespan.
First, we'll need a mountpoint however. If you've not created one yet, now would be a good time to do so. In the example wel'll create the mountpoint /newdisk

mkdir /newdisk

To be able to mount the new filesystem, we'll need to determine it's block id, which can be done using the blkid command.


We've determined our new filesystem has block id  UUID="5e907812-590b-470a-9fdf-15465a1b62c7", this alters per your unique filesystem of course.
To ensure the system will mount the new filesystem on boot, we'll have to alter the fstab file. So use nano or your favourite text editor to create a new entry.

nano /etc/fstab

We'll create a new entry using the block id and the mountpoint created earlier.
In the example below we're using an ext4 filesystem with default options, not dumping the filesystem and running a filesystem check after the root partition has been checked.

UUID=5e907812-590b-470a-9fdf-15465a1b62c7 /newdisk ext4 defaults 0 2

Save the file and exit, and now we're ready to mount it, whilst at the same time testing our fstab entry.
This can be done by simply mounting all partitions defined in the fstab file.

mount -a

To determine the filesystem has been mounted properly, you may check all currently mounted partitions.

No Comments
Back to top