How to add a second hard drive using ext4 and UUID
Second hard drive using ext4
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 servers.
If you have recently had a hard drive faliure and are a customer of First2Host the support team we will perfrom this for you when we replace your drive. There is no need to complete this yourself.
First, 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
Create Partition
Next, we need to partition the new disk using the following command just like our original ext3 guide:
cfdisk /dev/sdb
- New -> Primary -> Specify size in MB
- Write -> yes
- Quit
Format The Disk
Format the new disk using the ext4 file system
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? – second hard drive using ext4
More from Dedicated Servers
Enable Mod_RemoteIP – See Visitors Real IP address when using Cloudflare & Apache
If you are using Cloudflare on your Apache server you will always see Cloudflare IPs in your logs and not …
Fix 413 Request Entity Too Large Errors When Using NGINX
Just like Apache, NGINX imposes default limits on the size of files that can be uploaded. A 413 Request Entity …
Cloud-init Modules That Automate and Customize Deployments
Cloud-init is a popular way to automate deployments of instances in a cloud or none cloud environment. To save having …