OpenWrt Forum Archive

Topic: Expanding rootfs on RPI3

The content of this topic has been archived on 22 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

The image I'm using for the RPI3 doesn't utilize all of the SD card its space.

I'm trying to expand the partition to utilize the full 16GB on the SD card but it doesn't seem to work:

root@openwrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root               478.5M     37.1M    431.8M   8% /
tmpfs                   464.9M    292.0K    464.6M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
root@openwrt:~# umount -f /
root@openwrt:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.28).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 14.5 GiB, 15523119104 bytes, 30318592 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: 0x5452574f

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1 *      8192  417791  409600  200M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      425984 1409023  983040  480M 83 Linux

Command (m for help): d
Partition number (1,2, default 2):

Partition 2 has been deleted.

Command (m for help): p
Disk /dev/mmcblk0: 14.5 GiB, 15523119104 bytes, 30318592 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: 0x5452574f

Device         Boot Start    End Sectors  Size Id Type
/dev/mmcblk0p1 *     8192 417791  409600  200M  c W95 FAT32 (LBA)

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (2-4, default 2):
First sector (2048-30318591, default 2048): 425984
Last sector, +sectors or +size{K,M,G,T,P} (425984-30318591, default 30318591):

Created a new partition 2 of type 'Linux' and of size 14.3 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
root@openwrt:~# reboot
root@openwrt:~# resize2fs /dev/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
resize2fs: Invalid argument While checking for on-line resizing support
root@openwrt:~# resize2fs /dev/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/root to 3736576 (4k) blocks.
resize2fs: Operation not permitted While trying to add group #5

When I check Kernel log:

[   61.283001] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)
[   94.396389] EXT4-fs (mmcblk0p2): re-mounted. Opts: block_validity,delalloc,barrier,user_xattr,acl
[   95.711277] EXT4-fs (mmcblk0p2): resizing filesystem from 122880 to 3736576 blocks
[   95.780817] EXT4-fs warning (device mmcblk0p2): reserve_backup_gdb:968: reserved block 32 not at offset 31
[   95.799098] EXT4-fs (mmcblk0p2): resized filesystem to 3736576
[   95.810053] EXT4-fs warning (device mmcblk0p2): ext4_group_extend:1730: can't shrink FS - resize aborted
[  106.246223] EXT4-fs (mmcblk0p2): resizing filesystem from 163840 to 3736576 blocks
[  106.268424] EXT4-fs warning (device mmcblk0p2): reserve_backup_gdb:968: reserved block 32 not at offset 31
[  106.286995] EXT4-fs (mmcblk0p2): resized filesystem to 3736576
[  106.307088] EXT4-fs warning (device mmcblk0p2): ext4_group_add:1605: No reserved GDT blocks, can't resize

Does anyone know how to fix this?

Do you build your own Image or use a downloaded one ??

elektroman wrote:

Do you build your own Image or use a downloaded one ??

I built my own. Does the precompiled image have a feature to expand the root filesystem automatically?

You first need to convert the filesystem to a non journaled filesystem

tune2fs -O ^has_journal /dev/mmcblk0p2

Then you run fdisk, delete the partition and recreate it. Then you run resize2fs /dev/mmcblk0p2. Then you fsck the partition.

Then you recreate the journal

tune2fs -O dir_index,has_journal,uninit_bg /dev/mmcblk0p2

You will need to boot off a USB memory stick containing some live image to do this, since it is the root filesystem

After I do the fdisk and restart the rpi, the openwrt does not boot. What could be wrong?

The discussion might have continued from here.