Skip to content

This guide walks through resizing the root partition of OpenWrt on Raspberry Pi and compatible boards. It covers downloading the Ext4 version, expanding the root partition, setting up an Ubuntu VM with USB passthrough, using fdisk to resize partitions, and verifying changes, with troubleshooting tips.

License

Notifications You must be signed in to change notification settings

HexKernel/Expanding-the-Root-Partition-for-OpenWrt-on-Raspberry-Pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 

Repository files navigation

Expanding the Root Partition for OpenWrt on Raspberry Pi

For those attempting to run the OpenWrt OS for the first time on their Raspberry Pi or other boards, having sufficient storage volume attached may not resolve an issue with the limitation of root partition sizes of OpenWrt OS images that are shipped with less than 100 MB in size. This limitation can become troublesome after installing some packages and starting the OS. Therefore, in this guide, we will go through the steps to increase the size of the root directory to a desired size, allowing you to install as many software applications and packages as necessary.

1. Prerequisites

To accomplish this, please prepare the following items in advance:

  1. OpenWrt OS (Ext4 format): Download the Ext4 format version of the OpenWrt OS that corresponds to your board (in my case, using the Raspberry Pi 4 with processor model BCM 2711 was necessary the download link is: https://downloads.openwrt.org/releases/23.05.5/targets/bcm27xx/bcm2711/ ). Note that sometimes on the OpenWrt website, they promote the SquashFS format version, which is slightly faster than Ext4; however, due to being read-only, it cannot be used for partitioning. The trade-off here is worth using the Ext4 format since the difference is negligible.

  2. Raspberry Pi (or other board): Raspberry Pi board (or any other board you are using to boot up your OpenWrt OS).

  3. Backup your data: Backup /root directory in openwrt before partitioning (Just in case)

  4. A microSD card reader (for Raspberry Pi) or an external drive connected via USB to a secondary system (your laptop/computer running a Linux system).

If you do not have a laptop/computer running a Linux system as the host, you can use virtualization software such as VMware/VirtualBox/Hyper-V/etc. to install a Linux-based OS, such as Ubuntu. In this guide, I downloaded and used the first and smallest version of Ubuntu, which was Ubuntu 16, on VirtualBox running on my macOS laptop with USB passthrough enabled. Since the USB microSD card reader is connected to my host macOS laptop using the USB port, it was necessary to first install: The VirtualBox extension package, which can be downloaded from: https://www.virtualbox.org/wiki/Downloads, and then once the guest OS (Ubuntu 16 in this case) is configured and installed, use the commands below on the Ubuntu as the root user:

4.1. VirtualBox Extension Package Installation on Ubuntu

apt update
apt install virtualbox-ext-pack virtualbox-guest-utils virtualbox-guest-x11 virtualbox-guest-dkms

4.2. Add your user to the vboxusers group to enable USB passthrough

usermod -aG vboxusers root

and then reboot for the changes to take effect.

Note that you should install an extension package that corresponds to the version of VirtualBox that you have on your system; otherwise, it won’t work. Also, during this process, all running VMs must be turned off.

2. Accessing the SD Card in Ubuntu VM

Once everything is done, right-click on the Ubuntu VM and hover over the USB setting where you check the Enable USB controller. and then select the version that corresponds to yours (it is usually USB 2 and above, but again, check with your version). Then, from the USB filter list, add your device using the plus sign and run the VM.

Once you turn on the VM, from the menu bar of the Ubuntu VM (displayed below), click on the USB icon and select the USB that you added in the previous step. Once this is done, you should be able to see it attached using the command lsblk.

Example output:

root@Ubuntu:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0    5G  0 disk 
|-sda1   8:1    0    4G  0 part /
|-sda2   8:2    0    1K  0 part 
`-sda5   8:5    0  975M  0 part [SWAP]
sdb      8:16   1   59G  0 disk 
|-sdb1   8:17   1   64M  0 part 
`-sdb2   8:18   1  104M  0 part 
sr0     11:0    1 1024M  0 rom

To summarize:
/dev/sdb → full SD card (59 GB)
/dev/sdb1 → boot partition (64 MB)
and /dev/sdb2 → root partition (104 MB; this is what we’ll expand).

3. Partitioning:

fdisk /dev/sdb

Inside fdisk, do this carefully:

  • Type p → to show current partitions (note the start sector of /dev/sdb2, which is currently created and included with the image).
  • Type d → delete partition.
  • Choose partition 2.
  • Type n → create new partition.
  • Type p → primary partition.
  • Type 2 (same partition number).
  • Use the same start sector.
  • Accept the default ending (full size of disk or specify, explained below).

Here, an important thing to consider is the starting and ending sectors for the partition of sdb2 that you will be deleting. When you attempt to create a new one, it should have the same starting sector to avoid overlapping with the boot partition. However, the ending sector could either be the default value, which is usually the entire remaining space on the storage, or if you want this root partition to be set to a specific amount rather than taking the entire storage, you can specify the ending sector. For me, since I had a 64GB SD card, I only wanted 10GB for the root and leave the rest for other use cases such as NAS, File Sharing, etc. This is how you can calculate the ending sector for the amount of 10GB, assuming you start from the starting sector of 147456, which was my case:

  • Start sector is 147456 (you noted this earlier). 10 GB in sectors:
  • 1 GB = 2,000,000 sectors (since each sector is 512 bytes). Therefore, 10 GB = 10 × 2,000,000 = 20,000,000 sectors. End sector for the 10 GB partition:
  • End sector = Start sector + 20,000,000 - 1.
  • End sector = 147456 + 20,000,000 - 1 = 20147455
  • When prompted about removing the signature: say N for no (if you are asked).
  • Type w → write changes and exit.

Now, re-check and resize the filesystem:

e2fsck -f /dev/sdb2
resize2fs /dev/sdb2

By recreating /dev/sdb2 with the exact same start sector and an end sector beyond your existing data, you only update the partition table—no formatting occurs, and all original data remains intact and accessible when you remount it.

To verify, you can use:

sudo lsblk

Example output:

root@Ubuntu:~# sudo lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0    5G  0 disk 
|-sda1   8:1    0    4G  0 part /
|-sda2   8:2    0    1K  0 part 
`-sda5   8:5    0  975M  0 part [SWAP]
sdb      8:16   1   59G  0 disk 
|-sdb1   8:17   1   64M  0 part 
`-sdb2   8:18   1 58.9G  0 part
sr0     11:0    1 1024M  0 rom

Lastly, if you want to create an additional partition for other applications like what I did, you can repeat the same partitioning, but make sure that the additional partitions have some gaps in between them for safety, to avoid overlap. For example, since the ending sector for sdb2 was 20147455, you can have the starting sector for sdb3 be 20147455 + 1000 (which is 20148455).

In case you get an error similar to the following after finishing the formatting via fdisk:

Example output:

root@Ubuntu:~# e2fsck -f /dev/sdb3
e2fsck 1.42.13 (17-May-2015)
ext2fs_open2: Bad magic number in super-block
e2fsck: Superblock invalid, trying backup blocks...
e2fsck: Bad magic number in super-block while trying to open /dev/sdb3

The superblock could not be read or does not describe a valid ext2/ext3/ext4
filesystem.  If the device is valid and it really contains an ext2/ext3/ext4
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
    e2fsck -b 8193 <device>
 or
    e2fsck -b 32768 <device>

Then, please make sure to check the partition type via the command: sudo file -s /dev/sdb3 If you get “data” or something not ext*, then it’s not formatted or is a different FS.

If it’s unformatted, run sudo mkfs.ext4 /dev/sdb3 and you should be good to go.

4. Mounting third, fourth, and further partitions on OpenWrt

Since OpenWrt only automatically mounts the boot and root partitions created during OS installation, any additional partitions created on a secondary Linux OS (Ubuntu in this case) will not be mounted or shown in OpenWrt. They must be mounted manually using the following commands and steps.

  1. List all partitions and identify mmcblk0p3 as the target (≈49.3 GiB) using the cat /proc/partitions command:
root@OpenWrt:~# cat /proc/partitions
major minor  #blocks  name

   1        0       4096 ram0
   1        1       4096 ram1
   1        2       4096 ram2
   1        3       4096 ram3
   1        4       4096 ram4
   1        5       4096 ram5
   1        6       4096 ram6
   1        7       4096 ram7
   1        8       4096 ram8
   1        9       4096 ram9
   1       10       4096 ram10
   1       11       4096 ram11
   1       12       4096 ram12
   1       13       4096 ram13
   1       14       4096 ram14
   1       15       4096 ram15
 179        0   61798400 mmcblk0
 179        1      65536 mmcblk0p1
 179        2   10000000 mmcblk0p2
 179        3   51724172 mmcblk0p3
  1. Check if the MMC/SD kernel module is installed:
opkg update
opkg list | grep kmod-mmc
  1. If not present, install the required packages
opkg update
opkg install kmod-mmc kmod-fs-ext4 block-mount
  1. Install the file utility to detect the filesystem
opkg update
opkg install file
  1. Inspect the filesystem on the partition file -s /dev/mmcblk0p3

If unformatted or you wish to reformat: mkfs.ext4 /dev/mmcblk0p3

Example output:

root@OpenWrt:~# file -s /dev/mmcblk0p3
/dev/mmcblk0p3: Linux rev 1.0 ext4 filesystem data, UUID=d9c427d3-f325-4064-919f-b96afcc5cd56 (needs journal recovery) (extents) (large files) (huge files)
  1. Create a mount point and mount the partition
mkdir -p /mnt/data
mount -t ext4 /dev/mmcblk0p3 /mnt/data
  1. Confirm with disk free output: df -h:

Example output:

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 9.4G     26.1M      9.4G   0% /
tmpfs                   928.4M     76.0K    928.3M   0% /tmp
/dev/mmcblk0p1           63.9M     17.8M     46.1M  28% /boot
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/mmcblk0p3           48.4G     24.0K     45.9G   0% /mnt/data
  1. Enable auto‑mount at boot by editing /etc/config/fstab:

Add the following block:

cat << 'EOF' >> /etc/config/fstab
config mount
    option target   '/mnt/data'
    option device   '/dev/mmcblk0p3'
    option fstype   'ext4'
    option options  'rw,sync'
    option enabled  '1'
EOF
  1. Enable and start fstab service
/etc/init.d/fstab start
  1. Reboot to confirm persistence and after reboot, verify:
mount | grep /mnt/data
df -h /mnt/data

Example output:

root@OpenWrt:~# mount | grep /mnt/data
/dev/mmcblk0p3 on /mnt/data type ext4 (rw,sync,relatime)
root@OpenWrt:~# df -h /mnt/data
Filesystem                Size      Used Available Use% Mounted on
/dev/mmcblk0p3           48.4G     24.0K     45.9G   0% /mnt/data

Disclaimer

Please be advised that while the steps outlined in this guide have been carefully reviewed and tested, the author cannot be held responsible for any damage, data loss, or other unintended consequences that may arise from following these instructions. It is strongly recommended to back up all important data before proceeding with any changes to your system. By following this guide, you acknowledge that you do so at your own risk.

About

This guide walks through resizing the root partition of OpenWrt on Raspberry Pi and compatible boards. It covers downloading the Ext4 version, expanding the root partition, setting up an Ubuntu VM with USB passthrough, using fdisk to resize partitions, and verifying changes, with troubleshooting tips.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published