When OpenWrt is flashed to storage such as a microSD card or USB drive on a Raspberry Pi, NanoPi, or Orange Pi, it may initially use only a small part of the available capacity.
Even if the card or drive is 32 GB or 64 GB, OpenWrt may use only a few hundred megabytes. This prevents installing larger packages or applications such as Docker and PassWall.
This guide explains how to expand OpenWrt's root filesystem to use more of the available SD-card or USB capacity.
There are two approaches.
Method 1 uses the OpenWrt expansion script and supports EXT4 and SquashFS.
Method 2 performs the EXT4 steps manually for cases where the script fails or every step needs to be visible.
The manual example is based on work by
jeremienguyen
on VOZ.VN, using a NanoPi R2S, a 32 GB SD card, and EXT4.
Use PuTTY or another SSH client to log in to OpenWrt.
Connect the router to the Internet before starting.
The basic difference between EXT4 and SquashFS
SquashFS is read-only, while EXT4 supports read and write operations.
With SquashFS, the root filesystem is normally mounted through OverlayFS. Changes are stored in the writable upper layer; resetting the device removes that layer and returns to the read-only base.
With EXT4, the system writes directly to the filesystem. Changes remain after a reset unless the complete system is flashed again.
SquashFS and OverlayFS can add some boot time, but they are useful for systems with small or slower storage such as NAND and SPI flash.
root@OpenWrt:~# parted
GNU Parted 3.4
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD LX32G (sd/mmc)Disk /dev/mmcblk0: 31.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 33.6MB 50.3MB 16.8MB primary ext2 boot
2 67.1MB 176MB 109MB primary ext2
(parted) resizepart 2 100%
Warning: Shrinking a partition can cause data loss, are you sure you want to continue? Yes/No? yes
(parted) print
Model: SD LX32G (sd/mmc)Disk /dev/mmcblk0: 31.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 133.6MB 50.3MB 16.8MB primary ext2 boot
2 67.1MB 30.0GB 29.9GB primary ext2
(parted) quit
Information: You may need to update /etc/fstab.
root@OpenWrt:~#
If resizepart 2 100% reports that /dev/mmcblk0p2 is in use, answer n, quit Parted, run umount /dev/mmcblk0p2, and repeat the operation.
After Parted finishes:
mount -o remount,ro /
tune2fs -O^resize_inode /dev/mmcblk0p2
fsck.ext4 /dev/mmcblk0p2
reboot
After the router reboots, run:
resize2fs /dev/mmcblk0p2
Check the result:
1
2
3
4
5
root@OpenWrt:~# df -h
Filesystem Size Used Available Use% Mounted on
/dev/root 7.3G 14.5M 27.5G 0% /
tmpfs 495.8M 68.0K 495.7M 0% /tmp
tmpfs 512.0K 0 512.0K 0% /dev
Góp Ý / Bình Luận / Đánh giá