Running out of an entire partition

I'm not sure if anyone else does this way, but I prefer to run the entire root filesystem out of an USB stick partition without any use of overlayfs. (Assume that the disk has been partitioned already):

opkg update
# Needed for block mount:
opkg install kmod-usb-storage block-mount kmod-fs-ext4 kmod-scsi-core e2fsprogs

mkfs.ext4 -F -L usb1 /dev/sda1
mount /dev/sda1 /mnt
mkdir -p /tmp/chroot
mount --bind / /tmp/chroot
tar -C /tmp/chroot -cvf - . | tar -C /mnt -xf -
umount /tmp/chroot

block detect > /etc/config/fstab
cat >> /etc/config/fstab <<EOF
config 'mount'
        option target /
        option device /dev/sda1
        option fstype ext4
        option options rw,sync
        option enabled 1
        option enabled_fsck 1
sync ; reboot

This is the well known extroot configuration which has long been a standard way to work around small internal flash.

If lots of writing to the USB is expected, formatting it f2fs may reduce flash wear compared to ext4. But USB sticks are not good for frequent writing in any case.


Just for completeness:


True, yeah, but this is only written to once for the copy of ROM -> FS

Logs etc exist in memory only.

I think my commands are way simpler than that web page method