Resize2fs: Invalid argument when Resize Partition on x86 ext4

Hi, I have an x86 box with OpenWrt 18.06.5 r7897

I want to resize the root partition:

I already delete and recreated the partition on the same start sector using fdisk but when I try to resize the filesystem it shows:

root@OpenWrt:~# resize2fs /dev/sda2
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/sda2 to 262272 (4k) blocks.
resize2fs: Invalid argument While trying to add group #3

I already tryed: running fsck -f, making the partition smaller than 2gb, and running resizefs after umount / shows:

root@OpenWrt:~# resize2fs /dev/sda2
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
resize2fs: Read-only file system While checking for on-line resizing support

I wanted this to be able to sysupgrade later and preserve the partition size, but will not work:

root@OpenWrt:~# sysupgrade
Usage: /sbin/sysupgrade [<upgrade-option>...] <image file or URL>
       /sbin/sysupgrade [-q] [-i] <backup-command> <file>

upgrade-option:
        -f <config>  restore configuration from .tar.gz (file or url)
        -i           interactive mode
        -c           attempt to preserve all changed files in /etc/
        -n           do not save configuration over reflash
        -p           do not attempt to restore the partition table after flash.
        -T | --test
                     Verify image and config .tar.gz but do not actually flash.
        -F | --force
                     Flash image even if image checks fail, this is dangerous!
        -q           less verbose
        -v           more verbose
        -h | --help  display this help

backup-command:
        -b | --create-backup <file>
                     create .tar.gz of files specified in sysupgrade.conf
                     then exit. Does not flash an image. If file is '-',
                     i.e. stdout, verbosity is set to 0 (i.e. quiet).
        -r | --restore-backup <file>
                     restore a .tar.gz created with sysupgrade -b
                     then exit. Does not flash an image. If file is '-',
                     the archive is read from stdin.
        -l | --list-backup
                     list the files that would be backed up when calling
                     sysupgrade -b. Does not create a backup file.

Even with sysupgrade listing -p do not attempt to restore the partition table after flash.

When I ran the sysupgrade command with -p flag it just ignore it:

root@OpenWrt:~# sysupgrade -v -p /tmp/openwrt-*-x86-generic-combined-ext4.img.gz
Image metadata not found
Reading partition table from bootdisk...
Reading partition table from image...
Partition layout has changed. Full image will be written.
(...)

and the after the sysupgrade reboot the partition layout comes back to initial state:


root@OpenWrt:~# fdisk -l /dev/sda
Disk /dev/sda: 7.5 GiB, 8004304896 bytes, 15633408 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd534cb06

Device     Boot Start    End Sectors  Size Id Type
/dev/sda1  *      512  33279   32768   16M 83 Linux
/dev/sda2       33792 558079  524288  256M 83 Linux

note that /dev/sda2 was 1G before and not 256M

  • I've never successfully resized an online EXT4 partition on any running Linux
  • I personally use a Linux LiveCD and GParted

https://gparted.org/livecd.php

Thanks, I already know how to do it using gparted, but wanted to do it on the box itself... There must be a way to do it.

from what I can tell ... you'd need to hook into the lib/upgrade routine... because it slaps a part-table over the disk...

it's pretty easy to tuck an initramfs on /boot and a grub entry for disk-ops out-of-band.

some experimental methods here... not ideal... but might give you some ideas... ( wrtflashalt.sh uses a "repacked" upgrade.bin to upgrade an alternative partition without touching partition tables )

I was thinking about and I decided that I will stay with the standard behaviour and just drop a /etc/install.sh with the opkg update and the list of opkg install [package] to get packages installed when I sysupgrade, and if I need to use more space of the drive with some data or something just create a third partition and mount it using fstab I think that I can even Install big packages like python and similar there if I need too using opkg install --dest thirdpart [package] after I edit /etc/opkg.conf and add a new dest /mnt/thirdpart line.
It sound like a much better aproach to me, that way I will not need to deal with build my own package with CONFIG_TARGET_ROOTFS_PARTSIZE or keep remembering to boot with parted to resize the partition and things like that.
I already did something like that on a NAS and no problems so far.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.