Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Best way to resize root partition?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Marcih
Apprentice
Apprentice


Joined: 19 Feb 2018
Posts: 208

PostPosted: Wed Sep 16, 2020 7:40 am    Post subject: Best way to resize root partition? Reply with quote

I'm currently considering installing another operating system alongside my Gentoo install (trying out Hackintosh, to be specific) and my ext4 rootfs partition spans the entire disk:
Code:
Number  Start    End        Size       File system  Name  Flags
 1      1.00MiB  129MiB     128MiB     fat32        boot  boot, esp
 2      129MiB   114472MiB  114343MiB  ext4         OS
What would be the best way to shrink a partition? Although I may opt to just buy another SSD since this one is almost half full, I would still like to know how to correctly deal with something like this. If it were my /home, I would simply "cp -a" all the contents to another disk, delete all the partitions, redo them how I want and "cp -a" everything back (is there a better way for that too?), but rootfs is probably more complex than that.

Should I be creating a stage4? What about setting up LVM partitions, should I be doing that to simplify this process for myself in the future?
_________________
Bones McCracker wrote:
It wouldn't be so bad, if it didn't suck.

NeddySeagoon wrote:
The problem with leaving is that you can only do it once and it reduces your influence.
Back to top
View user's profile Send private message
alamahant
Guru
Guru


Joined: 23 Mar 2019
Posts: 551

PostPosted: Wed Sep 16, 2020 9:29 am    Post subject: Reply with quote

Hi,
You can use resize2fs
Boot to a livecd and run
Code:

e2fsck /dev/xxxx
resize2fs /dec/xxxx <new-size>

If it were on top of lvm you could do this online at some cases ie not needing unmounting or using livecd.
Please note that you can NOT shrink xfs filesystems.
Also for creating copies NEVER use "cp"
Use rsync instead.
Please have a look at
https://wiki.archlinux.org/index.php/Rsync#Full_system_backup

:D
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 16011

PostPosted: Wed Sep 16, 2020 4:17 pm    Post subject: Reply with quote

Strictly speaking, you can resize the root partition live, including shrinking it. Shrinking it like this will almost certainly destroy the filesystem. What you want is to resize the root filesystem, then resize the partition containing that filesystem. During the time that the filesystem is completely unmounted, you can have the partition be smaller than the filesystem, but the filesystem is not usable during this time (and will likely fail to mount). The only reason to do it is if you make a mistake, which you can correct if you catch it in time. Concretely, I would do as alamahant suggests (with some expansion):
  • Reboot to a livecd. To shrink a filesystem, it must not be mounted. The easiest way to unmount the root filesystem is to be running a livecd. This is noteworthy because for some less critical filesystems, you may be able to stop enough services that the filesystem can be unmounted while the system is running.
  • e2fsck the filesystem, as alamahant said.
  • Shrink the filesystem to the target size.
  • Shrink the partition to the target size. If in doubt, you may wish to shrink the filesystem too far, then regrow it later. For example, shrink the filesystem to 9.8G, shrink the partition to 10G, then grow the filesystem to fill the tail. This is not necessary for correct operation, but it is cheap, and may be easier than worrying about whether the tools exactly agree on the interpretation of the sizes you give.
  • Be sure that the kernel reloads the partition table. It may refuse if the device is busy. If you are using a livecd, the device should not be busy.
  • e2fsck the filesystem again. This should be clean. If it is not, panic.
  • If you chose to excessively shrink the filesystem, run resize2fs here to grow it back to fill the available space.
  • Run e2fsck again, just to be very cautious. This also should be clean.
  • Mount your filesystem from the livecd, just to verify that it mounts correctly.
  • Unmount and reboot back into your system
If you were using LVM, all the same principles would apply, but you would use LVM tools instead of partition editing tools for the step where you resize the block device.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum