Shrinking a disk partition.
Mar. 27th, 2023 12:59 pmFor a while now I have wanted to try out crux, an old source based linux distro. But I have been afraid of shrinking my home partition to make some room for it, reason being that all my precious data lives mostly on that one partition, plus I only have a single hdd. This would not be much of a concern if I could use gparted to do all that dangerous stuff but I got bad luck on my side this time, my touchpad had an unfortunate death almost 2 months back and trying to use the gparted resize gui using a keyboard is close to impossible(seriously). I have been using xdotool to simulate mouse controls but even that won't save you in this case.
Sooo today I decided to try shrinking a virtual disk partion in one of my void VM's. I had looked around the net in the past for ways to do it using fdisk but with little success but today I got real lucky, I stumbled upon the man page of resize2fs which helped me to figure it all out.
To resize an ext4 disk partition one should first use resize2fs to specify the new size of the partition then use fdisk or cfdisk to do the actual resizing.
Let's assume that we have a disk /dev/sda with a single 10G ext4 partition /dev/sda1. We would like to shrink it to size 5G.
The last step is to use either fdisk or cfdisk to resize the partition /dev/sda1. 'To resize' simply means to delete the partition then recreate it with the desired size(in this case 5G). I recommend to use cfdisk since it has a 'Resize' menu option that can do all this for you. You just have to enter the new size 5G and all done.
I plan on going through with this on my actual machine next week or so, right after my exams. It's always fun when you learn new things. (─‿─)
Sooo today I decided to try shrinking a virtual disk partion in one of my void VM's. I had looked around the net in the past for ways to do it using fdisk but with little success but today I got real lucky, I stumbled upon the man page of resize2fs which helped me to figure it all out.
To resize an ext4 disk partition one should first use resize2fs to specify the new size of the partition then use fdisk or cfdisk to do the actual resizing.
Let's assume that we have a disk /dev/sda with a single 10G ext4 partition /dev/sda1. We would like to shrink it to size 5G.
# check the file system first
> e2fsck -f /dev/sda1
# resize to 5G
> resize2fs /dev/sda1 5G
The last step is to use either fdisk or cfdisk to resize the partition /dev/sda1. 'To resize' simply means to delete the partition then recreate it with the desired size(in this case 5G). I recommend to use cfdisk since it has a 'Resize' menu option that can do all this for you. You just have to enter the new size 5G and all done.
I plan on going through with this on my actual machine next week or so, right after my exams. It's always fun when you learn new things. (─‿─)