Using old disks to serve data using a VM and Linux software RAID on CentOS or Red Hat 7

By | 1 February 2015

I have been contemplating adding a 2nd NAS storage device to my home network for a while. I currently have a Netgear ReadyNAS 2100 system with 8 TB raw storage. The ReadyNAS works terrific but I have a few old hard drives laying around and I want to use them! I looked online and considered building an inexpensive Linux box and using md RAID (Linux software RAID). I could then share the disk via NFS, AFP, SMB or iSCSI, or any combination of them. After thinking about the options I decided to go another route. I have an ESXi host that I use for my admin systems (vCenter, vShield Manager, Domain Controller, etc.). This system is in a very empty case since it boots from an 8 GB USB stick. The motherboard on the system has 6 SATA ports and the PSU is plenty powerful enough to add some disks! I decided to throw a few of my spare HDD’s into the system, format them as VMFS and connect them (via a single large VMDK) to a CentOS 7 VM. I decided to start with 2 disks I had handy. A 750 GB Seagate and a 1 TB Western Digital. Both are 7200 RPM SATA 6. I created my CentOS 7 VM and then created two 600 GB disks for the VM. One of the disks is stored on the 750 GB and the other is on the 1 TB. I then set out to create the RAID volume and format it for Linux use.

Here is what the disks look like from a VMware perspective:

I needed to install the Linux software RAID management tools:

[root@nfs1 ~]# yum install mdadm

Find out where your 600 GB "disks" are (they are sdb and sdc on my VM):
[root@nfs1 ~]# cat /proc/partitions
major minor #blocks name

2 0 4 fd0
8 0 16777216 sda
8 1 512000 sda1
8 2 16264192 sda2
8 16 629145600 sdb
8 32 629145600 sdc
11 0 1048575 sr0
253 0 1679360 dm-0
253 1 14581760 dm-1

Create the RAID volume using the 2 disks from above. Note that I am configuring them as RAID-1 (mirrored). If you have more disks available you can do RAID-5, RAID-6, RAID-10, etc. You can also add spares if you want.
[root@nfs1 ~]# mdadm --create --verbose /dev/md0 --level=mirror --raid-devices=2 /dev/sdb /dev/sdc
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
mdadm: size set to 629014336K
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Now you wait… Building the RAID array takes some time. Start it up before you go to bed. 🙂
[root@nfs1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc[1] sdb[0]
629014336 blocks super 1.2 [2/2] [UU]
[>....................] resync = 0.4% (2818944/629014336) finish=464.2min speed=22478K/sec

unused devices:

When it is done, you should see something like this:
[root@nfs1 ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdc[1] sdb[0]
629014336 blocks super 1.2 [2/2] [UU]

unused devices:
[root@nfs1 ~]# mdadm --detail /dev/md0
Version : 1.2
Creation Time : Sat Jan 31 20:46:40 2015
Raid Level : raid1
Array Size : 629014336 (599.87 GiB 644.11 GB)
Used Dev Size : 629014336 (599.87 GiB 644.11 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent

Update Time : Sun Feb 1 05:21:18 2015
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

Name : nfs1:0 (local to host nfs1)
UUID : e53b81cf:1b1e55a3:729e9b12:160b8aa3
Events : 104

Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc

Now, create a file named /etc/mdadm.conf and add the following (adjust for your disks):
DEVICE /dev/sd[bc]
ARRAY /dev/md0 devices=/dev/sdb,/dev/sdc

You will want to be notified if a disk fails in the array.
mdadm -F -f --delay=1800 /dev/md0

Make sure the monitor starts up on system boot by adding this line to /etc/rc.d/rc.local (yah, yah… I know, systemd blah blah, no more rc.local, blah blah. It still works and its easy). This assumes email works on your server, if not you will need to get that workikng. Google it. 🙂
mdadm -F -f --delay=1800 /dev/md0
If you are on RedHat or CentOS 7, you will need to do this too:
chmod +x /etc/rc.d/rc.local

Now we need to put a filesystem on it. I like to use ext4 but you can use any filesystem you want.
mkfs.ext4 -m 1 /dev/md0
(the -m 1 option sets “root reserve” at 1%. By default, this is higher but since this is just a data drive, it can be set low.)

Make a directory to mount the new disk (I’m using /data):
mkdir /data

Add a new line to the bottom of /etc/fstab so the disk its mounted every time the VM boots. You could add options like noatime, etc. but since this is a home lab and I dont care about performace tweaks, we will not:
/dev/md0 /data ext4 defaults 1 1

Mount the disk:
mount /dev/md0 /data

Thats is. Now you have the device ready for use. In an upcoming article, I will discuss exporting the volume via NFS as well as creating an iSCSI target on the volume. Finally, I hope to be able to show how to set up a Time Machine backup target so you can back up you Mac computers to the shared volume.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.