OpenWRT - Installation

Installing OpenWRT on an ARM SBC like the NanoPi R4S is cost effective as it cosumes little power compared to x86 counter parts.

It is very good to run as your “do it all” router running multiple apps through docker (Yes docker can also be installed, and it is nice when you lack some hardware and want to run pihole, unbound, nginx manager for network purposes).

Prerequisites


  1. An SBC (for our case a NanoPi R4S)
    Note: As of this writing, only works with the sdcard version, the emmc version still has some bugs.
  2. SDCard (NanoPi R4S needs one)
  3. Latest OpenWRT firmware
  4. Balena Etcher

EXT4 vs SquashFS


You may have noticed when downloading the OpenWRT firmware you were given 2 options namely EXT4 and SquashFS.


The main difference between the two is that EXT4 is a mutable file system so you can update it with no option to return, while SquashFS is a readonly file system, the biggest advantage over EXT4 is that you can reformat your OpenWRT installation and go back to the beginning.


Yes, we can also reformat EXT4 via sysupgrade -f but it needs the help of a firmware img while SquashFS does not and can return to its former self all on its own.


Installation


In my case I will go with EXT4 cause I need to expand the filesystem and unfortunately I don't know yet how to expand squashfs haha.


Now open balena etcher and use the recently downloaded system image and flash it unto your sdcard.


Then voilà, after flashing we should now be able to boot it up and start using OpenWRT.


Software Requirements


Install:
  • parted
  • resize2fs
  • mount-utils
  • tune2fs
  • lsblk

We can install the above via LuCI or Command Line.


# downloads the repository package list
opkg update

# install the needed packages / software
opkg install parted resize2fs mount-utils tune2fs lsblk

Expanding the Partition


First run parted and you should be in a parted CLI.


root@OpenWrt:~# parted
GNU Parted 3.6
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Then print all to list all the available devices.


(parted) print all

Model: SD SC16G (sd/mmc)
Disk /dev/mmcblk1: 15.9GB # disk device and maximum size
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  176.1MB  109MB  primary  ext4   # partition to expand

We can then now determine the storage device and what partition to expand and the maximum size.


In my case it is /dev/mmcblk1 and partition (number) 2.


We can then now run the command below to select the storage device.


select /dev/mmcblk1

Once selected we can then run resizepart just like below to expand the partition to its maximum capacity.


resizepart 2 15.9GB

We can then run print again and we should be able to see that the partition is already expanded.


(parted) print
Model: SD SC16G (sd/mmc)
Disk /dev/mmcblk1: 15.9GB
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  15.9GB  15.8GB  primary  ext4

We can then exit by entering q from the parted CLI and run the crucial commands below to finally be able to use the additional storage space.


Also Note that I am using /dev/mmcblk1p2 since I expanded partition 2.


You can run lsblk and the device under your primary device with the corresponding number should be your parition just like below.


root@OpenWrt:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda           8:0    1 14.7G  0 disk
└─sda1        8:1    1 14.7G  0 part /btrfs
mmcblk1     179:0    0 14.8G  0 disk
├─mmcblk1p1 179:1    0   16M  0 part
└─mmcblk1p2 179:2    0  109M  0 part / # this is my partition 2 pre storage expansion.

Now lets continue with running the commands below.


mount -o remount,ro /

tune2fs -O^resize_inode /dev/mmcblk1p2

fsck.ext4 /dev/mmcblk1p2

After running the above we then need to reboot the device and after rebooting we should immediately ssh back and run the command below to finally expand the partition.


resize2fs /dev/mmcblk1p2

Congratulations you should now have an expanded storage for your OpenWRT. See more of my posts on how to install Docker and using a BTRFS file system to run docker.