How to add a second hard drive using ext4 and UUID

How to add a second hard drive using ext4 and UUID

Adding an additional or second hard disk to your workstation or server is easy and often required. We’ve already covered how to add a second drive using ext3 so now we’re going add a second hard drive using ext4. Here’s how to prepare and mount it by referencing UUID which is a preferred method today. This should work on CentOS / Debian and Ubuntu 

A. Figure out the device name for the new device

fdisk -l
 

This will give you output similar to this:

Disk /dev/sda: 17.2 GB, 17179869184 bytes
 255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x000299d1
Device Boot Start End Blocks Id System
 /dev/sda1 * 2048 32088063 16043008 83 Linux
 /dev/sda2 32090110 33552383 731137 5 Extended
 /dev/sda5 32090112 33552383 731136 82 Linux swap / Solaris
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
 255 heads, 63 sectors/track, 2088 cylinders, total 33554432 sectors
 Units = sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk identifier: 0x00000000
Disk /dev/sdb doesn't contain a valid partition table

B. Next we need to partition the new disk using the following command just like our original ext3 guide:

cfdisk /dev/sdb
  1.  New -> Primary -> Specify size in MB
  2. Write -> yes
  3. Quit

Cheap Dedicated Server Hosting

C. Format the new disk using the ext4 filessystem

mkfs.ext4 /dev/sdb1
 

D. You need to create a new directory where the disk will be mounted in the filesystem. We’re using /home1

mkdir /home1
 

You can name the folder whatever your want and place it in a subfolder of another mounting point, for example /var/home1

E. It’s preferred to use the device UUID (Universally Unique Identifier) instead of directly linking to the device path because while UUID always stays the same, the device path may change. This is how we find the UUID:

blkid
 

Which shows a list of all partitions and the assigned UUID. The list should look similar to this:

/dev/sda5: UUID="260cab2a-300a-4e3d-8c8e-0e1dg6s3c8f7" TYPE="swap"
 /dev/sda1: UUID="cd0c7b2c-cf50-4557-bc01-2484105a41d2" TYPE="ext4"
 /dev/sdb1: UUID="982d90df-f17a-52f6-ab13-df13bf715de7" TYPE="ext4"
 

F. Add the new disk to fstab to automatically mount it on boot using the UUID found when running blkid 

nano /etc/fstab

Then add the drive into the file

echo "UUID=982d90df-f17a-52f6-ab13-df13bf715de7 /home1 ext4 errors=remount-ro 0 1" >> /etc/fstab

G. Manually mount the disk (you can also reboot the machine and it will be automatically mounted)

mount /home1

/home1 is the directory created in step 4

How was this article?

How to add a second hard drive using ext4 and UUID
2 5 100%

Dedicated Servers

Select Language
We are currently updating our website. Please accept our apologies for any disruption you may see.
+