Virtual Hard Disk Expansion
- Last Updated: 07/26/2021
Introduction to RAID¶
RAID (Redundant Array of Independent Disks) is a data storage virtualization technology where multiple disks are logically put together and function as a single array. Some reasons why RAID arrays are used are to prevent data loss if a disk fails (redundancy), quicken data transfers, and increase storage space.
There are different types of RAID levels.
- Raid 0 (striping): In a RAID 0 system, data is evenly split between multiple disks. Although RAID 0 performs really well, it is not fault tolerant. That means if one drive fails, then the rest of the array fails.
- Raid 1 (mirroring): In a RAID 1 system, two or more disks store the same copy of data. Therefore, if one drive fails, then the array will continue to operate as long as at least one drive functions properly.
- Raid 5 (striping with parity): In a RAID 5 system, at least three disks are needed, and each block of data is stored in three different places. Two of these three places simply store the block of the data, and the third one stores a checksum, which can be used along with the other data block to rebuild a lost data block. One advantage of RAID 5 is that you still have access to the all the data in the event that one drive fails or while the failed drive is being replaced.
- Raid 10 (striping and mirroring): A RAID 10 system is a combination of a RAID 0 and a RAID 1 system. Therefore, data is evenly split across multiple disks, and multiple disks are used to store copies of data. Therefore, if one disk fails in a RAID 10 system, the rebuild time is relatively fast because the data from the surviving mirror just needs to be copied to a new drive.
In this tutorial, we'll be using Raid 1.
Steps to Expand Hard Disk Space¶
Displays current partitions
View information regarding specific virtual disk drives
/usr/sbin/megacli -LDInfo -Lall -aAll | more
Get enclosure and slot ids of the physical drives:
megacli -PDlist -aall
Show foreign config on inserted drives
megacli -CfgForeign -Scan -aALL
Clear foreign config on drive
megacli -CfgForeign -Clear -aALL
Get list of disks with only Enclosure and Slot #
megacli -PDlist -aall | grep -e '^Enclosure Device ID:' -e '^Slot Number:'
Create RAID drive (where -cfgldadd stands for "configure logic device -add," r# represents what RAID level is being used, [E:S] represents the enclosure id and slot number, and -a# stands for "adapter" (adapter 0 represents the first LSI RAID card in your system and is generally used if you don't have multiple
RAID cards in your system))
megacli -CfgLdAdd -rN [E:S, E:S, ...] -aN
Example of Creating a RAID 1 drive:
megacli -CfgLdAdd -r1 [32:0, 32:1] -a0
Use the fdisk command-line utility to delete partitions on /dev/sda
Command (m for help): p
Disk /dev/sda1: 18.6 GiB, 19999490048 bytes, 39061504 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
Disklabel type: dos
Disk identifier: 0xec56af3a
IF THE PARTITION HAS AN EXT4 SIGNATURE DO NOT DELETE IT. The disk will be ruined.
Command (m for help): d
deletes partitions one at a time
Command (m for help): w
Command (m for help): p
prints the partition table (use to confirm that changes were saved)
Command (m for help): n
adds a new partition
Command (m for help): m
lists all the commands you can use (prints the menu)
Ctl+C to exit fdisk utility
Run df to see new extended space
***IMPORTANT NOTE: A partition can only be mounted to an empty directory. So, you might want to create a new directory to mount your disk if your current directory is not empty.
Make a new directory
Creates an ext4 filesystem
Mounts disk to your new directory
mount /dev/sda /newdirectoryname
How to Automount a File System in Linux and Restore Files After Restarting the Server¶
Mount your disk to your directory using the following command:
mount /dev/sda /directoryname
Take note of the UUID of the appropriate disk (the command below lists all the UUIDs of the disks on your machine)
Go into /etc/fstab and add the line below to that file.
**MAKE SURE THAT YOUR UUID MATCHES THE ONE OF YOUR DISK!!!**
**MAKE SURE THAT ALL OF THE INFORMATION IN THE /ETC/FSTAB FILE IS CORRECT. OTHERWISE, YOUR MACHINE WON'T BOOT PROPERLY!!!**
UUID=insert-uuid-here /directoryname ext4 noatime,errors=remount-ro 0 1
After you add the line above, save your file, and reboot your machine to see if the changes took place.