Activating extroot on OpenWrt 12.09-rc1
Enabling extroot on OpenWrt 12.09-rc1 is bit tricky. Likely reason you're trying to enable extroot is lack of free space i.e. router with 4MB flash. Problem is that unless you're interested in creating custom firmware images there's no space left for tools to enable extroot using old procedure. Following has been tested with TP-Link MR3220 v1. It's ar71xx with 32MB RAM and 4MB flash being lowest end of currently supported OpenWrt compatible devices.
# Install packages to support extroot
# Since OpenWrt 12.09-rc1 included Luci it's tight fit on 4MB flash devices
# and we're forced to install required tools on-demand instead of all at once
opkg update
opkg install kmod-usb-storage fdisk
# Wipe old partition table from /dev/sda
# to wipe entire device which can take for a while drop "count=1" from end
dd if=/dev/zero of=/dev/sda bs=64k count=1
# Create new partitions, 64MB swap, 256MB root and rest as separate partition
cat <<'__EOF__' | fdisk /dev/sda
n
p
1
+64M
t
82
n
p
2
+256M
n
p
3
w
q
__EOF__
# Verify partitions, should look something like this
root@OpenWrt:/# fdisk -l /dev/sda
Disk /dev/sda: 1050 MB, 1050935296 bytes
33 heads, 61 sectors/track, 1019 cylinders, total 2052608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2785a891
Device Boot Start End Blocks Id System
/dev/sda1 2048 133119 65536 82 Linux swap / Solaris
/dev/sda2 133120 657407 262144 83 Linux
/dev/sda3 657408 2052607 697600 83 Linux
# Remove fdisk to make some space for e2fsprogs
opkg remove fdisk
opkg install e2fsprogs
# Create root and data filesystems
mkfs.ext3 /dev/sda2 -L openwrt-extroot
mkfs.ext3 /dev/sda3 -L openwrt-data
# Remove e2fsprogs and install mkswap
opkg --force-removal-of-essential-packages remove e2fsprogs libext2fs libcom_err libpthread
opkg install swap-utils
# Create swap
mkswap /dev/sda1 -L openwrt-swap
# Install blkid, block-mount and ext2/ext3/ext4 driver required for extroot support
opkg install blkid block-mount kmod-fs-ext4
# Check status with blkid
root@OpenWrt:/# blkid
/dev/mtdblock2: TYPE="squashfs"
/dev/sda1: LABEL="openwrt-swap" UUID="ef9f9054-7d12-4aa3-a3ee-9a56baae91b1" TYPE="swap"
/dev/sda2: LABEL="openwrt-extroot" UUID="c1ad543d-f24b-4363-b6a8-77639010a560" SEC_TYPE="ext2" TYPE="ext3"
/dev/sda3: LABEL="openwrt-data" UUID="c6472265-be07-49db-862f-bd75cff3956e" SEC_TYPE="ext2" TYPE="ext3"
# Cleanup default fstab configs as they don't work for us
/etc/init.d/fstab stop
uci delete fstab.@swap[0]
uci delete fstab.@mount[0]
uci commit fstab
# Enable swap on next boot
uci add fstab swap
uci set fstab.@swap[-1].uuid=`blkid -s UUID /dev/sda1 | cut -d\" -f2`
uci set fstab.@swap[-1].enabled=1
uci commit fstab
# Enable extroot on next boot
uci add fstab mount
uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda2 | cut -d\" -f2`
uci set fstab.@mount[-1].options=rw,sync,noatime
uci set fstab.@mount[-1].fstype=ext3
uci set fstab.@mount[-1].enabled_fsck=1
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/
# Enable data partition on next boot
mkdir -p /mnt/data
uci add fstab mount
uci set fstab.@mount[-1].uuid=`blkid -s UUID /dev/sda3 | cut -d\" -f2`
uci set fstab.@mount[-1].options=rw,sync,noatime
uci set fstab.@mount[-1].fstype=ext3
uci set fstab.@mount[-1].enabled_fsck=1
uci set fstab.@mount[-1].enabled=1
uci set fstab.@mount[-1].target=/mnt/data
uci commit fstab
# Disable anon mount feature
uci set fstab.automount.anon_mount=0
uci commit fstab
# Resulting /etc/config/fstab
root@OpenWrt:~# cat /etc/config/fstab
config global 'automount'
option from_fstab '1'
option anon_mount '0'
config global 'autoswap'
option from_fstab '1'
option anon_swap '0'
config swap
option uuid 'ef9f9054-7d12-4aa3-a3ee-9a56baae91b1'
option enabled '1'
config mount
option uuid 'c1ad543d-f24b-4363-b6a8-77639010a560'
option options 'rw,sync,noatime'
option fstype 'ext3'
option enabled_fsck '1'
option enabled '1'
option target '/'
config mount
option uuid 'c6472265-be07-49db-862f-bd75cff3956e'
option options 'rw,sync,noatime'
option fstype 'ext3'
option enabled_fsck '1'
option enabled '1'
option target '/mnt/data'
# Populate new root with copy of current root
mkdir -p /mnt/sda2 /tmp/cproot
mount --bind / /tmp/cproot
mount /dev/sda2 /mnt/sda2
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda2 -xf -
sync
umount /mnt/sda2
umount /tmp/cproot
# Activate extroot on next boot
/etc/init.d/fstab enable
/etc/init.d/fstab start
/etc/init.d/fstab whole_root_enable
# Reboot router
reboot
# Check mounts and swap after reboot
root@OpenWrt:/# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 246.0M 15.3M 217.9M 7% /
/dev/root 2.0M 2.0M 0 100% /rom
tmpfs 14.3M 76.0K 14.2M 1% /tmp
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda2 246.0M 15.3M 217.9M 7% /
/dev/sda3 671.3M 17.5M 619.7M 3% /mnt/data
root@OpenWrt:/# free
total used free shared buffers
Mem: 29220 20408 8812 0 2380
-/+ buffers: 18028 11192
Swap: 65532 0 65532
# We can now install bunch of useful tools since we have plenty of space
opkg update
opkg install fdisk e2fsprogs tcpdump screen mtr wget luci-app-samba
# Have fun!
good work!! Thanks a lot!!!!
ReplyDeleteDo you have any idea on how to revert extroot, I no longer wish to boot my router from the USB drive drive buy I have no idea what to do.
ReplyDeleteThanks for any reply.
thanks
ReplyDeleteThank you! Worked perfectly on Attitude Adjustment RC1 (r36422, custom build)
ReplyDelete