Skip to content

Instantly share code, notes, and snippets.

@p2made
Last active November 12, 2024 23:31
Show Gist options
  • Save p2made/4f38be302043d51fe2e08aa601a8d2e3 to your computer and use it in GitHub Desktop.
Save p2made/4f38be302043d51fe2e08aa601a8d2e3 to your computer and use it in GitHub Desktop.

ExtRoot & Swap on OpenWrt

Following Quick Start for Adding a USB drive but installing some packages that will be needed right after. Also see Using storage devices.

  • SSH into the router.
  • Install required packages...
opkg update
opkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb-ohci kmod-usb-storage kmod-usb-uhci kmod-usb2 kmod-usb3 usbutils nano
  • Enter ls -al /dev/sd* to show the [Unix] names of all attached USB devices...
root@OpwnWrt:~# ls -al /dev/sd*
brw-------    1 root     root        8,   0 Apr 23 19:30 /dev/sda
brw-------    1 root     root        8,   1 Apr 23 19:30 /dev/sda1
brw-------    1 root     root        8,   2 Apr 23 19:30 /dev/sda2
brw-------    1 root     root        8,   2 Apr 23 19:30 /dev/sda3
partition name / description size
sda1 ExtRoot / overlay 256 MB
sda2 swap 192 MB
sda3 There will be spare capacity that you can use.

If you're not using a swap volume, sda2 will be the remaining space, & you won't have sda3.

  • Create the fstab config file based on all the block devices found...
block detect | uci import fstab
  • Update the fstab config file to mount all drives at startup. More...
uci set fstab.@mount[0].enabled='1'
uci set fstab.@global[0].anon_mount='1'
uci commit fstab
  • Mount the devices...
/etc/init.d/fstab boot

Ignore any error on /dev/sda3 for now.

Run the ExtRoot magic...

mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt

block detect > /etc/config/fstab; \
   sed -i s/option$'\t'enabled$'\t'\'0\'/option$'\t'enabled$'\t'\'1\'/ /etc/config/fstab; \
   sed -i s#/mnt/sda1#/overlay# /etc/config/fstab; \
cat /etc/config/fstab;

Output...

config 'global'
	option anon_swap '0'
	option anon_mount '0'
	option auto_swap '1'
	option auto_mount '1'
	option delay_root '5'
	option check_fs '0'

config 'mount'
	option target '/overlay'
	option uuid '9b150345-5a3e-4164-b494-3e91dccfde8d'
	option enabled '1'

config 'swap'
	option uuid '0c01be5c-efb0-4032-9dba-87aada184546'
	option enabled '1'

config 'mount'
	option target '/mnt/sda3'
	option uuid '1536-CA6E'
	option enabled '0'

If swap is not enabled...

nano /etc/config/fstab

Change option enabled to 1.

reboot
grep -e /overlay /etc/mtab

Should give output like...

root@OpwnWrt:~# grep -e /overlay /etc/mtab
/dev/sda1 /overlay ext4 rw,relatime,data=ordered 0 0
overlayfs:/overlay / overlay rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work 0 0
df /overlay /

Should give output like...

root@OpwnWrt:~# df /overlay /
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1               116912      5004    103168   5% /overlay
overlayfs:/overlay      116912      5004    103168   5% /
sed -i -e "/^lists_dir\s/s:/var/opkg-lists$:/usr/lib/opkg/lists:" /etc/opkg.conf
opkg update

Upgrade all installed packages..

opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment