After re-imaging one of our servers, due to our image sites, I instantly needed more than the standard 4GB allocated to the var logical volume. Unfortunatley the 1and1 FAQ was not as useful as it has been previously due to the version of CentOS installed on the server leaving me with errors at step 9. Fortunately Google search and translate came to the rescue, so here’s the step by step guide with an expanded step 9 to help others.
- First, log into the server via SSH.
- Once logged in, type df – h at the command prompt and hit ENTER. The partition and logical volume sizes will be listed including the used disk space. In the image below, the var logical volume is 4GB. Assume that ~9GB of web content will be uploaded to the /var folder. The disk space needs to be increased before there is enough space to upload the content.
df This is the disk free space command which will display disk usage information.
-h This option forces the output to be in human readable format. This will display sizes in KB, MB or GB.
- Next, type fdisk -l to view the total hard disk(s) size and partitions on the disk. It can also be noticed here that the physical partition /dev/sda3 is using Linux LVM.
- Type the pvs command and press Enter.Further Explanation:
pvsPhysical Volume Show command.
PVPhysical Volume path
VFVolume Group name.
Fmt LVM Format
Attr Physical volume attributes. The a attribute means that the physical volume is allocatable and not read-only.
PSizePhysical Size of the physical volume.
PFreePhysical Freespace left on the physical volume.
- As stated above, our scenario requires roughly 9GB of data to be uploaded to the /var folder. Since the logical volume assigned to /var is only 4GB, we will increase this to 10GB using the lvextend command. The command below is to be used as reference only as the parameters will be different depending on your scenario.The format for the lvextend command is as follows:lvextend -L +1G /dev/mapper/vg00-varFurther Explaination:lvextend This is the logical volume extend command used to make a logical volume larger.
-L +6G It is specified using the Logical volume size option, how much larger to make the volume. In this scenario, 6 gigabytes is added to the current 4 gigabyte volume to result in a 10 gigabyte volume.
/dev/mapper/vg00-var The path to the logical volume is specified last. The path to the volume to be extended was taken from the output from the second step in this guide.
- Type df -h to display the disk free space once again. The lvextend operation finished successfully in the last step however the /dev/mapper/vg00-var size is still only showing 4.0G. This is because while the logical volume was increased successfully, the file system needs to be extended to take advantage of the full space of the logical volume.
- Type lvs to show the logical volume information once again. Here, we can confirm that the logical volume has successfully been extended to 10 gigabytes. In the next steps, we will increase the file system to match the logical volume size.
- Type mount and press ENTER to display the mounted file systems. From the output, we find that the /dev/mapper/vg00-var logical volume is using xfs (with the introduction of CentOS 6, the default filesystem is ext4).
- To increase the file system to match that of the logical volume, we will use the xfs_growfs command if the filesystem uses xfs or resize2fsif the filesystem is ext4. Typing xfs_growfs /var (ubuntu) or resize2fs /dev/mapper/vg00-var(depending on which filesystem is used on your system) will extend the file system to the 10 gigabyte limit of the logical volume.If you get the error
resize2fs: Filesystem has unsupported feature (s) while trying to open / dev / local / home
Could not find valid filesystem superblock.
This is because in CentOS 5.5+ two versions of resize fs are included:
- resize2fs: 1.39
- resize4fs: 1.41.9
Therefore, to extend ext4 file systems we use utility resize4fs: resize4fs /dev/mapper/vg00-var
- Type df -h to display the disk free space to confirm that the file system has been extended.