Linux Storage LAB: Extending Raid volume in LVM

This is a test performed on an Ubuntu 1604 virtual machine, to verify, how you can expand a SW RAID, which is used trough an LVM by a file system, without losing data.
In this LAB some of the operations are performed in the command line, while some are performed with Webmin. Webmin is a comfortable web based management interface for Linux, with good support for RAID and LVM.


For the test I have created 3 times 5 Gigabyte virtual disks.

1) Preparing disks for RAID usage

I used to create a primary partition on each disk and use that as the RAID device. This can be done with Webmin.
  1. Connect to webmin on https://server:10000
  2. Select Hardware/Partitions on Local Disks. 
  3. Select the first disk and Wipe Partitions. I used MSDOS format, for 5 Gbytes disk this is Ok.
  4. Then with the + sign in the upper right corner add a new partition. Select Linux RAID type and leave extent unchanged to use the full disk.
  5. Repeat this for all 3 disks
In my case the partitions were sdb1, sdc1 and sdd1.

1) Create a RAID5 with 2 of the disks

Even if you have only 2 disks it is a good idea to create a RAID5 disk instead of a RAID1 as in the first case you will be able to extend the capacity by adding more disks to it. Creating 2 disk RAID5 is not supported by webmin, so we have to do it by hand.

sudo mdadm --create /dev/md0 --level=5 --raid-devices=2 /dev/sdb1 /dev/sdc1

If you don't have the mdadm command, you can install it by typing:

sudo apt install mdadm

After creating the array you can check it with the command:

cat /proc/mdstat

Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdc1[2] sdb1[0]
      5231616 blocks super 1.2 level 5, 512k chunk, algorithm 2 [2/2] [UU]

unused devices:

Or you can check it in Webmin, in Hardware/Linux RAID. If you don't have Linux RAID option, try with Refresh module in the bottom of the left menu.

2) Creating the Logical Volumes

In Webmin the Logical Volume Management (LVM) is under Hardware/Logical Volume Management.

If you don't have this menu, go to the command line and enter:

sudo apt install lvm2

After this go back to Webmin and press Refresh Modules.

In LVM select Add a new volume group, set the name to VGTest, select the just created raid array, push Create.

The Volume Group is a pool of disks, from were you can allocate individual Logical Volumes, which appear as disks in the system.

Next step is to create a Logical Volume for the actual filesystem.

Go to Logical Volumes and press Create a logical volume in VGTest. For the name enter LVTest, and press create.

3) Creating filesystem and mounting it

On the same Logical volume tab, click on the newly created LVTest.

In the bottom of the screen select New Linux Native (ext4) and press Create Filesystem of Type. On the next screen just accept the default options and create the filesystem.

You can check if the filesystem is created with the following command:

lsblk -f /dev/mapper/VGTest-LVTest


For mounting we will still use webmin, on the Edit Logical Volume screen type /media/test in the field in from of Mount LV On and press the button. Leave the defaults as they are and press Create.

Now check if the disk is there by typing:

ls /media/test

or

df -h

To make is accessible for your user, we will create a directory and change its ownership to our actual user.

sudo mkdir /media/test/data
sudo chown laco:laco /media/test/data


4) Copying a file to the new disk and check it's hash

Get a bigger file (~4G) from somewhere and simply copy it to to /media/test/data.

cp testfile /media/test/data/

Now get the md5 checksum

md5sum /media/test/data/testfile

Note the result of the calculation.

With the df -h command you can check the disk usage and you can see that the disk is 90% full.

Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/VGTest-LVTest  4,8G  4,1G  465M  90% /media/test


5) Add the next partition to the RAID5 array

Go back to Webmin/Hardware/Linux RAID, select the earlier created array and click on its name.

On the raid device screen in front of the add partition, select the 3rd partition available for RAID and press Add partition.

You will be dropped back to raid device list, select again this array, and press Grow RAID.

You are dropped back to the raid device list, and you will see that the array is now in reshaping stage. In my machine it took 5 minutes to finish the 5 Gig disk, after that it will show again, that the raid is clean.

If you go in again to the array details, you will see, that the RAID size is already increased to 10 Gigabytes.

Just to be on the safe side, let's check the file again:

md5sum /media/test/data/testfile

And we can see that the file is still intact, as the summ matches the previous.

6) Add the extra capacity to the LVM Volume Group

In Webmin go to Hardware/Logical Volume Management and to the Physical Volumes tab. Click on the RAID device, and on the next screen press Resize To Match Device.

The device size will increase to 10 GB.

We can check again if the file is still ok, with:

md5sum /media/test/data/testfile

7) Increase the Logical Volume size and increase filesystem size

Before increasing the volume size, it is recommended to unmount the file system.

sudo umount /dev/mapper/VGTest-LVTest

Now in Webmin/Logical Volume Management go to the Logical Volume tab and select LVTest. On the upper right corner select Use all free VG space and click Save. As you can see the size of the volume increased to 10 Gigs.

Now enter the following command to resize the filesystem:

sudo resize2fs /dev/mapper/VGTest-LVTest

it asked to run this command before:

sudo e2fsck -f /dev/mapper/VGTest-LVTest

and the again the resize command, and we are almost done.

8) Mount the resized file system and check if the original file is kept, and if the additional capacity can be used

Mount back the file system:

sudo mount -t auto /dev/mapper/VGTest-LVTest /media/test

Check the available free space:

df -h

Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/VGTest-LVTest  9,7G  4,1G  5,2G  45% /media/test

Check if the file is intact:

md5sum /media/test/data/testfile

Copy another big file and check disk usage:

cp testfile /media/test/data/testfile1
df -h

Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/VGTest-LVTest  9,7G  8,2G  1,1G  89% /media/test

So we can see that the new file system is working ok, and the size has increased. By this we have completed this lab.

Comments

Popular posts from this blog

Setting ethernet interface speed in /etc/network/interfaces