How to shrink a partition without using GParted?
Solution 1
If you really want to use the gui, and you have extra space (or perhaps can provision it on demand, or even temporarily purchase a new VPS briefly), then you could:
- Boot in rescue mode
- unmount /home, and dd (copy) the raw partition to a new partition (another device for convenience); we will refer to it as 'home2'.
- You could now boot into 'full' system with gui if you prefer.
- Verify your copy: fsck, mount, check that home2 is okay, then umount home2.
- You can now run gparted on home2, verify that it is okay, figure out the exact partition size / blocks required
- Boot in rescue mode again
- Do the resize with confidence, or just delete that partition and create it again with required size (back up the partition table first though).
- Use dd to copy the filesystem image back from home2 to the resized home partition.
- Reboot!
Realize that any filesystem changes to /home between steps 2 and 6 will be lost.
Disadvantage: that's an extra step or two, and requires extra disk space.
Advantage: you do have a backup copy of your partition.
For anyone not fluent with dd, fsck, fdisk, parted, mount, and partition tables, experiment with a virtual server and a virtual disk; it's free. Also, try experimenting with LVM, as it allows you to resize dynamically (no reboot or downtime required).
Solution 2
...answering as best as possibile to my own question:
If for any reason you cannot use GParted, you will have to do it manually using some of these command line tools:
parted
resize2fs
(c)fdisk
The steps can be different according to the filesystem contained in the partition. For example I found that parted
cannot resize partitions which contains filesystem like ext4, so I had to destroy and recreate the partition with fdisk, making some calculations about the correct size. Also most of the commands can only used when the partition is not mounted.
Before using fdisk you may want to backup the partition table, i used dd for that task.
Also if you drive is setup with LVM you may use the tools provided.
Some useful links I found:
I will try to improve my answer as I gain more experience.
Solution 3
Gparted works fine, but, as with any partition manager, you can not resize mounted partitions. And you can not un-mount your root partition while running your OS.
So the trick is: Use a Live CD / USB boot!
Then you can resize any hdd partition, since none will be mounted.
Just be aware that the system must have been properly shut down, as hibernated partitions should not be resized.
Also use fsck
prior to resize, just to make sure there are not corrupted structures.
Solution 4
I used fdisk to create a small partition before the boot partition then created a new boot partition and deleted small partition, rebooted, then ghosted back the c: drive.
Using the desktop version of gparted I was able to see I was close to the recommended 1024 alignment (1025) which gave me a five fold increase in 4kb read speed on crystal bench mark.
When I was able to get the cd boot version of gparted and do a proper alignment by making a 2 mb space before then creating a 1 mb space, as recommended as the way to get the optimum 1024 figure in gparted, I didn't see any improvement in the crystal bench mark scores. So just going the fdisk way, and using crystal bench sees to me to give just as good results.
Related videos on Youtube
castigli
Updated on September 18, 2022Comments
-
castigli over 1 year
Unfortunately all the answers I found involve GParted. I thought I could be using parted, but apparently the "parted resize" command has some limitations with respect to GParted when working on a partition which has already a filesystem in it ( gives a warning and also can't work on filesystem with some special features like journal, etc... )
I was being able to shrink the filesystem ( ext4 ) by using resize2fs command, but now I don't know how to shrink the partition in order to create a new one.
I also compiled parted 3.0, but in this new version the resize command has been removed altogether...
Should I just use fdisk ? In the man I don't see a resize command there, they say to use parted...
Thanks
-
Admin about 12 yearsQuestion: why don't you want to use gparted? It is far safer than other tools (though there is always an element of risk, so be prepared for data loss).
-
Admin about 12 yearsHis
server
tag seems to indicate he's working with Ubuntu Server, which is command-line only.. -
Admin about 12 years@SirCharlo:
gparted
is just a front-end to the command-lineparted
tool, which the OP already said it didn't work... -
Admin about 12 yearsThat's just it; he used the command-line program, which is hard to use and unintuitive to one accustomed to using GUIs.
-
Admin about 12 yearsI have nothing aginst GParted :), I have used it on the desktop, but my server is a cheap VPS and as far as I know I cannot boot from a live CD. I can boot from a "rescue system" but also there I have no GUI program, only parted v.2.2 and other utils...
-
Admin almost 12 yearsDoes your "cheap VPS" provide a control panel of some sort? You can find options to resize disk image there. Alternatively, have a look at this answer by @Gilles: askubuntu.com/a/109224/14564 - it uses a combination of
fdisk
andresize2fs
to resize a "live" partition. Make sure you've got backups :)
-
-
castigli about 12 yearsThanks, but AFAIK I am unable to boot from a LiveCD, my server is a cheap VPS, and I can boot only from a rescue system which has only CLI.
-
castigli about 12 yearsThanks, but I can have the partition unomunted, since I can boot from the "rescue system". The problem is that I cannot use GParted, and parted seems not only less user friendly, but more limited in features. Now I am missing only the last step, to resize the partition. I fear I could destroy my data using fdisk...
-
MestreLion about 12 yearsI said
fsck
, notfdisk
. And yes, you should have a backup prior to any partition resize. If you can't afford to lose your data if things go wrong, don't resize.