Hey bloggers and readers π
This post will help you to extend your Partition on a Linux System. (Thanks to koxbox)
Here I will be demonstrating how to extend / parition by shrinking the /home partition and using some of it’s space (WARNING: You may lose files if not CAREFUL!)
— HINT: Backup everything before doing this π
NOTE : The filesystem is ext4 and the container logical volume.
jackson@foss:~$ sudo init 1
This will take you into runlevel 1 (‘runlevel’ refers to the mode of operation in the OS). init 1 or in technical terms ‘runlevel 1’ mode is used to carry out administrative tasks such as resizing the partitions,etc.
It will ask for your su (root) password and then you can make administrative changes to your system.
Now run the following command and I’ll explain each command below it. Here I am shrinking my 40GB ‘/home’ to 35GB and adding 2GB of the free space created to ‘/’ partition
root@jackson:~$ cd / root@jackson:~$ umount /home root@jackson:~$ e2fsck -f /dev/debian/home root@jackson:~$ resize2fs /dev/debian/home 35G root@jackson:~$ lvresize -L 35G /dev/debian/home root@jackson:~$ mount -a root@jackson:~$ vgs root@jackson:~$ lvs root@jackson:~$ df -h root@jackson:~$ lvextend -L +2G /dev/debian/root root@jackson:~$ resize2fs /dev/debian/root root@jackson:~$ df -h root@jackson:~$ init 5
(replace /home with whatever partition you need to shrink)
cd / :change directory to the root
umount /home : unmount the home partition, in order to make changes to the home partition.
e2fsck -f /dev/debian/home : used to disk check the file system of type ext3/ext4,etc for bad sectors and I/O errors related to HDD
We need to resize the partition in physical volume first then in logical volume.
resize2fs /dev/debian/home 35G : Resize the ext3/ext4 file system to 35GB
lvresize -L 35G /dev/debian/home : Resize the logical volume to 35GB
It will popup a message saying : ‘WARNING you may lose the files on the file system’
type yes (‘y’) and enter (make sure that there is free space available on the partition to be shrunk or it might corrupt if the free space margin is too low)
mount -a : It will mount all the partitions.
vgs ; lvs ; df -h : Run this to check if the file system are okay or not.
lvextend -L +2G /dev/debian/root : Extend logical volume by 2GB
NOTE : Remember the + sign before 2G as it will add that much space to the existing space or else it will resize it to the specified amount only without the sign.
resize2fs /dev/debian/rootΒ : This will resize the root partition to the total space specified before.
df -h : Run this command to check the size of all the partitions after the resize.
init 5 : This command will take you back to the runlevel 5 (ie. start the system normally + display manager like Gnome or KDE etc).
Hope this tutorial helps you π
Questions: (Why resize partition?)
Q. What did you do that you need to resize?
– I was trying to do ‘apt-get dist-upgrade’ and got stuck due to low space on ‘/’ (root) partition.
– Also sometimes /usr or /var goes low on space, one will need to resize the partition but it can be avoided by moving some files to /home,etc.
– While installing maybe some partition was initiated with smaller size and you need more space.
Let the Windows be open, and feel the Freedom.
Hi Pal , that’s a post that’ll come in handy to many . Great Work . Keep it up π
LikeLike