Playing with LVM on Debian Weehzy.
Resizing or deleting partitions, gaining space and then redistribute it across the partition you need to resize.
Basically the logical operations are pretty simple and straightforward if taken into a ‘logical’ vie. Of course you have to shrink the partition first and then the volume, while, at the opposite if you want to grow a partition you have to resize the volume in order to be able to contain the bigger partition.
But you can’t do this on a running system. You have to restart into recovery mode. So you will be able to umount partitions as you will be using just the memory.
Particularly this applies to the machine from a dutch provider called Transip who sells these convenient VPS and more, these have huge a disk space amount (the basic VPS has 50 gigs).
They offer a very nice Control Panel, although in dutch, is very easy to use and it offers advanced features like the chance to set the reverse dns by yourself, or or creating a private network with your virtual machine in order to carry on internal operation such as for example backups, or build your load balancing, your mysql cluster and so. Very very nice, their interface is built by themselves, very smart company.
Anyway, back to my problem, they have this console you can use to install the operating system from scratch and Icouldn’t manage to get into a partition manager that allowed me to decide how many and how large partition to use. So i had to use one of the predefined setup (“Use entire disk and setup LVM” then “Use separate partition like /usr, / home, /var etc”). This is a picture of the starting situation:
But I don’t really enjoy that kind of partitions and their size. So I’ll let the installation finish and then I’ll start modifying my lvm.
This machine will be used to keep some backups from mysql and some web folders under /var/www, from another machine. For this reason I will install and configure Bareos.
With “df -h” i can identify the following partitions, the ones I’m interested in. I want to get some free space from shrinking /home and merging /usr into the root partition (/):
/home 36 Gb / 322 Mb /tmp 368Mb /usr 8.3Gb /var 2.8 Gb /blah
First, I want to get rid of /usr and merge it with / (the root partition).
For this reason I will:
cp -pr /usr /home/usr umount /dev/machine-name/usr lvremove /dev/machine-name/usr
I’ll be able to check the actual free disk space gained. You should see at the end of the output a line starting by (look at the picture below):
Free PE / Size.
That is the measure you can increase another partition of, or of the redistributable space. Here I’m going to make backups so I’m going to create a new partition called “/backups” where I will store my backups. This is supposed to be a very big partition, so i’ll start merging and shrinking partitions in order to leave the most of the space available for backups.
So now for example I’ll reduce the filesystem first and then teh volume size for the partition /home.
umount /dev/machine-name/home e2fsck -f /dev/machine-name/home -p 2G lvreduce -L 2G /dev/machine-name/home
Then this is what I have after all these operations:
At this point I have still to merge /usr into / (the root partition), but i have to make it bigger first. So I’ll give more space to the logical volume first and then I’ll extend the file system as well.
lvextend -L 3G /dev/machine-name/root resize2fs -p /dev/machine-name/root 3G rm -fr /usr mv /home/usr /
At this point we want to remove the /usr entry from /etc/fstab otherwise we will get errors because that partition doesn’t exist any more on our system. (little advice: since we are going to create a new partition and a new mount point at this point you could consider instead of deleting the entry, to modify it for the new mount point so there will be no need to come back on this file again, but it’s up to you).
Then create a new partition , but first the logical volume
lvcreate -L 39G -n backups vg-name
Create then a file system
mkfs .ext4 /dev/machine-name/backups
Let’s create a mount point
and let’s add the partition to /etc/fstab (just copy the line for /var taling care of renaming where needed)
If it’s all ok now we can reboot in a normal way and check whether the new partition mounts correctly etc.
So, reboot and connect with ssh. Then with “df -h” i’ll verify all.
root@eventhorizon:~# df -h Filesystem Size Used Avail Use% Mounted on rootfs 3.0G 308M 2.5G 11% / udev 10M 0 10M 0% /dev tmpfs 101M 232K 101M 1% /run /dev/mapper/eventhorizon-root 3.0G 308M 2.5G 11% / tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 201M 0 201M 0% /run/shm /dev/vda1 228M 18M 199M 9% /boot /dev/mapper/eventhorizon-home 2.0G 153M 1.8G 8% /home /dev/mapper/eventhorizon-tmp 368M 11M 339M 3% /tmp /dev/mapper/eventhorizon-backups 39G 176M 37G 1% /backups /dev/mapper/eventhorizon-var 2.8G 181M 2.5G 7% /var
Great! all is as expected.
Now i can install and configure Bareos, so follow my next posts!!