Tutorials

Add Secondary Drives to CentOS / RHEL

Adding a secondary drive to CentOS/RHEL (verbose version)

1) Get a list of current drives attached:

[root@centos ~]# fdisk -l

Disk /dev/vda: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003b59f

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1               3        6242     3144704   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            6242        8323     1048576   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.

2) Add the secondary drive in your VDC and connect it to the target server:

3) On your server, you should now see the secondary drive:

[root@centos ~]# fdisk -l /dev/vdb

Disk /dev/vdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

4) Partition the drive using fdisk. You will want to pay close attention to the size of the partition you want, extended or primary, etc:

[root@centos ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x85f08528.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-8322, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-8322, default 8322):
Using default value 8322

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

5) You should now see the secondary drives partitioned space:

[root@centos ~]# fdisk -l /dev/vdb

Disk /dev/vdb: 4294 MB, 4294967296 bytes
16 heads, 63 sectors/track, 8322 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x85f08528

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1        8322     4194256+  83  Linux

6) Create an ext4 file system on this partition using mkfs.ext4 /dev/vdb1.

[root@centos ~]# mkfs.ext4 /dev/vdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 1048564 blocks
52428 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1073741824
32 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

7) Create a mount point and mount the secondary drive to this mount point:

[root@centos ~]# mkdir /mnt/secondary
[root@centos ~]# mount /dev/vdb1 /mnt/secondary/

Get the drive/partition UUID with the following:

[root@centos ~]# ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx. 1 root root 10 Feb  5 21:40 4b4c9ae0-5d88-4eb7-b163-cab3f3adef74 -> ../../vdb1
lrwxrwxrwx. 1 root root 10 Feb  5 21:18 c77264f7-bb39-4a57-b25a-5e679aa6a77e -> ../../vda2
lrwxrwxrwx. 1 root root 10 Feb  5 21:18 fd433c28-f7da-46a3-afa8-e188a1a75905 -> ../../vda1

8) Add the drive to auto-mount via /etc/fstab using the partitions UUID:

UUID=4b4c9ae0-5d88-4eb7-b163-cab3f3adef74 /mnt/secondary        ext4    defaults        1 1

9) You should now see the drive via $ df -h:

[root@centos ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1       3.0G  721M  2.1G  26% /
tmpfs           495M     0  495M   0% /dev/shm
/dev/vdb1       3.9G  8.0M  3.7G   1% /mnt/secondary