Sometimes adding a volume to a system is a requirement. Sometimes an existing logical volume under linux needs to be expanded. What ever the reason may be, getting to the GUI is not always a guarantee, so the underlying command line functions cannot be forgotten.
Step 1: Create the “physical volume”
After adding the drive to the system, a partition needs to be identified on the drive. You can optionally choose to not partition the drive and simply point to the full device (/dev/sdb vs /dev/sdb1), but it isn’t recommended specifically for the reason that it will likely cause pain at another time (mounting the volume on another system when you are trying to rescue it, etc.. basically, things you think you will never have a need for, but when it does happen, you don’t want to have already shot down your chances).
With the partition created, create the “physical volume” identifier on the partition:
Step 2: Create/Extend the volume Group
If this is a new volume group, create it via:
vgcreate NewVolumeGroupName /dev/sdb1
If this added space will be used to extend an existing volume group, do this via:
vgextend VolumeGroupName /dev/sdb1
We now have the volume group “VolumeGroupName” which contains this new physical volume.
Step 3: Create/Extend the logical volume
If this is a new logical volume, create it via:
lvcreate -l 100%FREE -n NewLogicalVolume VolumeGroupName
If this added space will be used to extend an existing logical volume, do this via:
lvextend -l +100%FREE -n LogicalVolumeName
We now have the logical volume “LogicalVolumeName” with all of the new space allocated to it.
Step 4: Create/Extend the filesystem
This is specific to ext3/ext4 which does not translate to other filesystems well.
If this is a new filesystem, simply run:
mkfs -t ext4 -m 0 -j /dev/mapper/VolumeGroupName-LogicalVolumeName
And it will run for a few minutes as it sets up the file system. Once complete, mount it to where ever you so desire.
If this is to extend an existing filesystem, this can be done seamlessly and on the fly via:
Best practice says to do this with the volume unmounted and followed by “fsck -y /dev/mapper/VolumeGroupName-LogicalVolumeName”, but ext3/ext4 filesystems extend very cleanly.
Step 5: Turn off boot time file system checks
Ext3/Ext4 are journaled file systems. Large file systems can take a LONG time to fsck, which could translate to a long time before the machine boots. It may not be best practice to turn these off, but, IMHO, a controlled fsck is better than a surprise one 4 months from now when a system is rebooted without a maintenance window large enough to compensate for a 40 minute fsck.
tune2fs -i 0 -c 0 /dev/mapper/VolumeGroupName-LogicalVolumeName
The above command means that it will never automatically check the file system again. It is recommended that you plan for a scheduled file system check on your terms by running “touch /forcefsck” prior to a reboot of your system.