Linux Disk Administration

This page contains some of the tricks and experiences that I have came into with dealing with disks in Linux.

Expand Disks in Linux

Create a New LVM Volume

The example below will create a new logical volume based on an existing volume group with free space available. Use vgdisplay -v to display the available volume groups. If you need to expand the volume group refer to the Expand Volume Group section. In the example below, datavg is returned. Use lvcreate -n lvname -L size [MB|GB] datavg. If you want to use all the free space in the volume group use -l +100%FREE instead of the -L size parameter. After you create the logical volume you’ll need to create the file system using mkfs.ext3, mkfs.ext4, mkfs.xfs or whatever you want.

1. vgdisplay -v
2a. lvcreate -n lvname -L 10GB datavg 
  OR
2b. lvcreate -n lvname -l +100%FREE datavg
3. mkfs.ext4 /dev/datavg/lvname
Add the new lvname to the fstab if desired 
4. mount -a
5. mount # verify new mount is there

Expand LVM Volume

The example below will expand a logical volume based on an existing volume group with free space available. Use vgdisplay -v to display the available volume groups. If you need to expand the volume group refer to the Expand Volume Group section. In the example below, datavg is returned. Use lvextend -r -L size [MB|GB]
lvname. If you want to use all the free space in the volume group use -l +100%FREE instead of the -L size parameter. The -r command does online resizing. If this option fails you may have to unmount the file system and run the resize2fs on the unmounted device to expand it. Then remount when the resize2fs completes.

1. vgdisplay -v
2. Find the VG that LV is part of (If you need to expand the VG, refer to the Expand Volume Group Section
3. lvextend -r -L +10G /dev/datavg/lvname
4. df -h # to verify the new size

Add a New Drive to a LVM Volume Group

The example below will add a new drive to a LVM Volume Group. The first thing you need to do is scan for the new drive(s), if it’s a new VMWare, Hyper-V or SAN volume. The results of the scan can be found at the tail of dmesg output. The output should look something like /dev/sd? where ? is a new drive character. Using this drive character you can create the physical volume and then add it to the volume group. You can specify the letter that ? will be directly or you can use the ? wildcard which will add all new /dev/sd? found.

1. cd /sys/class/scsi_host
2. for i in *; do echo '- - -' > $i/scan; done
3. dmesg | tail  # to find the new drive letter
4. pvcreate /dev/sd?
5. vgextend /dev/datavg /dev/sd?