[HOWTO] TL WR703N extroot for the greenhorn

After several tries and a lot of serial console usage I finally got extroot working. I am new to digging in the guts of linux and started my journey about extroot in the openwrt wiki. As this is very technical I got confused and…long story short here is a howto for beginners on how to setup your openwrt box to boot from an external USB stick.

I assume you have a fresh openwrt setup (Attitude Adjustment) without any installed packages. You have set up your network of course (vi /etc/config/network) to match your home network ip/dns/gateway. Your ‘internet is up’ and furthermore you have a USB stick (obviously).
I have an 8 gb verbartim mini stick.

Once the system is booted up type the following

1)
[code]
opkg update
opkg install kmod-usb-storage kmod-usb2 kmod-fs-ext4 fdisk e2fsprogs hotplug2 block-mount
[/code]

The first line updates the available packages from the openwrt trunk.
The second line installs all necessary packages.
There should be no errors.

2)
Plug in your USB stick and type (if not printed automatically)
[code]dmesg | grep sd[/code]
This should show the USB stick like :
[code]
[ 9.830000] sd 0:0:0:0: [sda] 15646720 512-byte logical blocks: (8.01 GB/7.46 GiB)
[ 9.830000] sd 0:0:0:0: [sda] Write Protect is off
[ 9.840000] sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
[ 9.840000] sd 0:0:0:0: [sda] No Caching mode page present
[ 9.850000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 12.070000] sd 0:0:0:0: [sda] No Caching mode page present
[ 12.070000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 12.080000] sda: sda1
[ 12.090000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 12.100000] sd 0:0:0:0: [sda] Attached SCSI removable disk
[/code]

3) Partitioning of the USB stick
Your USB stick should be on /dev/sda1 or whatever address the above code shows.
Start fdisk on your usb device with
[code]
fdisk /dev/sda[/code]
If your are familiar with fdisk, creating three primary partitions shouldn’t be a hassle.
In my example the first partition is 7GB. The second around 500MB and the third gets the rest of it.
[code]
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-245, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-245, default 245): +7000M

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (158-245, default 158):
Using default value 158
Last cylinder or +size or +sizeM or +sizeK (158-245, default 245): +500M

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (190-245, default 190):
Using default value 190
Last cylinder or +size or +sizeM or +sizeK (190-245, default 245):
Using default value 245

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82
Changed system type of partition 3 to 82 (Linux swap / Solaris)[/code]

In short type:
[code]
n
p
1
+7000M

n
p
2
+500M

n
p
3
[enter]

t
3
82
[/code]

n = create new partition
p = create primary partition
(number) = actuall partition number
+xxxxM = size in MB

[code]p[/code] should print something like this
[code]
Command (m for help): p

Disk /dev/sda: 8011 MB, 8011120640 bytes
247 heads, 62 sectors/track, 1021 cylinders, total 15646720 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: 0x003d97c2

Device Boot Start End Blocks Id System
/dev/sda1 2048 14338047 7168000 83 Linux
/dev/sda2 14338048 15386623 524288 83 Linux
/dev/sda3 15386624 15646719 130048 82 Linux swap / Solaris
[/code]

Write ‘w’ and the changes will be written to the usb stick.

4) Creating file systems

Type
[code]
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
mkswap /dev/sda3
[/code]
Followed by ‘Enter’. This creates ext4 fs on sda1/2 and a swap on sda3

5) Configure Fstab
[code]

uci set fstab.automount=global
uci set fstab.automount.from_fstab=1
uci set fstab.automount.anon_mount=0
uci set fstab.autoswap=global
uci set fstab.autoswap.from_fstab=1
uci set fstab.autoswap.anon_swap=0
uci set fstab.@mount[0]=mount
uci set fstab.@mount[0].device=/dev/sda1
uci set fstab.@mount[0].enabled_fsck=0
uci set fstab.@mount[0].fstype=ext4
uci set fstab.@mount[0].options=rw,relatime,barrier=1,data=ordered
uci set fstab.@mount[0].enabled=1
uci set fstab.@mount[0].is_rootfs=1
uci add fstab mount
uci set fstab.@mount[1].device=/dev/sda2
uci set fstab.@mount[1].enabled_fsck=0
uci set fstab.@mount[1].target=/opt
uci set fstab.@mount[1].fstype=ext4
uci set fstab.@mount[1].options=rw,relatime,barrier=1,data=ordered
uci set fstab.@mount[1].enabled=1
uci set fstab.@swap[0]=swap
uci set fstab.@swap[0].device=/dev/sda3
uci set fstab.@swap[0].enabled=1
uci commit fstab
[/code]

6) Copy the root fs
[code]

mount /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind / /tmp/root
cp -a /tmp/root/* /mnt
umount /tmp/root
umount /mnt
[/code]

That’s it. If all went well after plan a reboot should boot the system from the USB stick.

[code]root@OpenWrt:/# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 6.7G 153.8M 6.2G 2% /
/dev/root 1.5M 1.5M 0 100% /rom
tmpfs 14.2M 396.0K 13.8M 3% /tmp
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda1 6.7G 153.8M 6.2G 2% /overlay
overlayfs:/overlay 6.7G 153.8M 6.2G 2% /
/dev/sda2 503.9M 16.4M 462.0M 3% /opt
root@OpenWrt:/#
[/code]

This howto is based upon [url]https://aseith.com/pages/viewpage.action?pageId=4161740[/url]. He wrote a great tutorial in german for Backfire but with a small change in the opkg instructions above this works for AA, too. Would even work without it :). He also has some other nice howto’s for OpenWrt which helped me alot as they are dead simple and not as confusing as the wiki. Unfortunately it took me a bit to long to find his page.

Leave a Reply

Your email address will not be published. Required fields are marked *