Skip to content

Shrinking ext4 partition online.

Hello folks,

EXT4 file system cannot be shrunk online.This means you must either use live usb or dvd,or by another instance.

Another trick is to delete swapfile ,pacstrap Archlinux to it,update grub,boot from another instance.

These are the two methods to do, i knew until this day.Suddenly i got another idea.(I didn't put effort regarding this topic,maybe many use this method)

I did'nt try out,just asking if it is possible. Can't we add cfdisk or gdisk or gparted bianry to initramfs(mkinitcpio),so that we can edit live?

2 points7 comments
Open on Reddit
About this post
Posted
Archived
Score
2 · 100% up
Kind
Text
ID
aze7pp

Author

25
posts
102
comments
3
media
View profile

7 comments

I find it puzzling that EXT4, even on LVM, doesn't allow shrinking, while others like BTRFS does.

2 points

Can't we add cfdisk or gdisk bianry to initramfs

Yes. You can add any binary to initramfs, but the larger the program the slower the boot process as all of initramfs gets read to ram.

Can't we add gparted bianry to initramfs

You will need to pull in the whole xserver and likely a window manager and I am not sure how hard it is to launch a graphical display from initramfs. Although I don't know anything that would prevent it I have never seen or heard of someone doing it.

Another option is to use a efi application that can partition things, someone has converted fdisk to run as an efi application but it does not look like it will handle filesystems.

1 points

This must be generic option,must also applicable to non-uefi systems(legacy boot).So,fdisk efi may not be the perfect solution.

If we add cfdisk or gdisk to initramfs,can we able to shrink ext4 online?can we unmount the partitions(including root filesystem)?

1 points

Initramfs is a ram filesystem. It contains everything needed to mount the root filesystem so when you first enter it the disk is not mounted. If you hijack the normal process you will end up in a minimal system with a ram only root and can thus do whatever you want to the systems disks. This is very similar to what a live usb does.

You could also use grub to boot into an ISO image located in the efi or boot partition (or anywhere not on the filesystem you want to resize).

0 points

you could do a custom "shrink this filesystem"-initcpio-hook, sure

but in the time it takes to write that, you can also boot a livecd, shrink, and reboot into arch

or if it's a (v)server, boot into the rescue system, shrink, reboot into arch

that leaves a server without rescue system but then I'd rather think about implementing a rescue system anyway than just some specific hack for one thing

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.