What Do I Need?
- A Dedicated or VPS Linux Server
- CentOS
- Putty
What is the Filesystem Extension?
Very early on in your career as a web server sysadmin, it’ll soon become necessary to use an awesome tool called LVM.
- Inputs
- Check the size of the filesystem by using the following command:
df -h
- Let’s take a look at the drives present and see how we’re going to increase them.
fdisk -l
- Increase Disk Size
- In this guide, we’re going to simulate increasing the size of the /dev/sda4 (Linux LVM) by a size of 10GB.
- Create Partition
- After increasing the size of the disk, you need to create a new partition:
fdisk /dev/sda
- Press ‘N’ to a new partition.
- Next press ‘P’ to indicate the type. We’ll select ‘Primary’.
- When asked to indicate a partition number, by default it’s the following with the number ‘3’.
- Next, the starting and ending sectors are indicated. Ensure you check that they match the values specified by a hyphen. In this example, we’ll use all of the unallocated space:
- Change the default type to Linux LVM. To do this, use the ‘T’ command, indicate the type of partition we want to change and number, and enter its code in the 8e hexadecimal system:
- Next press ‘P’:
- Now you’ve created /dev/sda3 partition. It remains only to save the changes with the ‘W’ command. After that the fdisk will automatically close:
- Extend LVM
- To use the created volume in LVM, initialize it with the pvcreate common:
pvcreate /dev/sda3
- Check the name of the volume group to which you want to add the partition. Let’s use vgdisplay for this. The default is cl:
- Add the new partition to this group:
vgextend cl /dev/sda3
- Using the lvdisplay let’s look at the name and path to the logical one that needs to be expanded, by default, this is root and /dev/cl/root:
lvdisplay
- Next, expand it. In order to facilitate this, lvextend will specify the path to the logical volume and the -l +100%FREE parameter, which indicates that we want to use all of the free space:
lvextend -l +100%FREE /dev/cl/root
- The last step left is to expand the filesystem. If you’re using xfs using the following command:
xfs_growfs /dev/mapper/cl-root
- If you’re using ext4, use the following command:
resize2fs -p /dev/mapper/cl-root
- Check the results and ensure that they match what you’re expecting:
df -h
Next Steps
Before starting on expanding and extending your filesystem, I recommend first getting a pen and pad and working out where you want the majority of your space allocated. It’s best to do this on a fresh server implementation before you start building up various sites and applications in-situ. It’s always a good idea to keep some hard disk space free just in case your client’s webspace expansion needs outstrip your own automated systems. To this end, plan ahead and implement before your web server layout with the following considerations in mind:
- Will the bulk of your users be e-commerce or business users?
- If so, prepare for large databases and lots of content.
- Will the bulk of your users be script-runners and app developers?
- If so, prepare again for large databases and lots of processor and memory cycles.
Conclusion
Always look out for those pesky log files and temporary caches getting a little too big. So get used to purging useless dumps periodically. To that end, try out some of the following commands when things start to get a little hectic:
cd /var/tmp rm -r *
** Huge thanks to Paul Joyce for correcting a typo on one of the commands!
- Do you need the best VPS? Read about our different offers.