Adding a hard drive in CentOS 7

August 23, 2017
Phil

Whether installing a new physical hard drive to a server or adding an additional disk to your cloud server or VPS, you’ll need to configure CentOS to be able to use it.

We’re going to assume the drive is connected, so first of all we need to find it.

First of all, we need to know the naming convention your server is using for drives, and we can find this with the ‘df’ command.

[user@server ~] df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda2       24733776 2521604  20942668  11% /
/dev/vda1        1007512  203260    751824  22% /boot

The two lines above show that this particular server is using the vd* notation, but sd* is also used.  Here the primary drive, vda, has two partitions – vda1 and vda2.

We can now use the following command to find other disks:

[user@server ~] ls -1 /dev/[sv]d[a-z]
/dev/vda
/dev/vdb

We can see both our original disk, vda, and the new disk vdb.  Now to create a filesystem the new disk with the ‘mkfs.ext4’ utility.

[user@server ~] sudo mkfs.ext4 /dev/vdb

This will just take a few seconds.

To use the new disk we now need to mount it.  When you’ve decided where you want to mount the disk, first create that folder on your server.  We’re going to use ‘home2’ for our disk.

[user@server ~] sudo mkdir /home2

We can now mount the disk to that location:

[user@server ~] sudo mount /dev/vdb /home2

Revisiting the df command we can now see that the new disk is mounted.

[user@server ~] df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda2       24733776 2521604  20942668  11% /
/dev/vda1        1007512  203260    751824  22% /boot
/dev/vdb        25000000     100  24999900   1% /home2

To ensure the disk is automatically mounted when the server is rebooted, we also need to add it to fstab.  Our preferred editor is ‘nano’ so we type

[user@server ~] sudo nano /etc/fstab

We add, to the end of the file, the line:

/dev/vdb /home2 ext4 defaults 0 0

Then CTRL + O to save and CTRL + X to exit.

The disk will now stay mounted after reboot and you can begin using it.

No comments

Leave a Reply

Your email address will not be published. Required fields are marked *