OpenWrt Forum Archive

Topic: [HOWTO] TL WR703N extroot for the greenhorn

The content of this topic has been archived on 13 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello

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)

opkg update
opkg install kmod-usb-storage kmod-usb2 kmod-fs-ext4 fdisk e2fsprogs hotplug2 block-mount

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)

dmesg | grep sd

This should show the USB stick like :

[    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

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

fdisk /dev/sda

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.

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)

In short type:

n
p
1
+7000M

n
p
2
+500M

n
p
3
[enter]

t
3
82

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

p

should print something like this

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

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

4) Creating file systems

Type

mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
mkswap /dev/sda3

Followed by 'Enter'. This creates ext4 fs on sda1/2 and a swap on sda3

5) Configure Fstab

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

6) Copy the root fs

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

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

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:/#

This howto is based upon https://aseith.com/pages/viewpage.action?pageId=4161740. 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 smile. 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.

(Last edited by ianmcmill on 11 Feb 2013, 10:48)

Great man big_smile please admins update WIKI

hmm i have some errors to after making extroot with this tutorial above :

i cant in luci set any network settings (is that normal after extrooting)

http://www.deviantpics.com/images/2013/02/12/aaaa.png

hmm i think it is wrong formated file but which one ?

XML Parsing Error: not well-formed
Location: http://192.168.1.2/cgi-bin/luci/;stok=4 … n/network/
Line Number 142, Column 57:    /usr/lib/lua/luci/dispatcher.lua:195: in function </usr/lib/lua/luci/dispatcher.lua:194></pre>
---------------------------------------------------------------^

(Last edited by fpopic on 12 Feb 2013, 22:40)

Hello,
I was trying this on the AA RC1, and kept getting out-of-room errors.
This is the steps i took to get mine working:
1. install the plain image squashfs

2. login via telnet and set password and update /etc/config/network to connect it to my lan
3. reboot
4. connect via SSH
5. run:
opkg remove ppp* uhttpd luci* kmod-ppp* --force-removal-of-dependent-packages
opkg update
opkg install kmod-fs-ext4 kmod-usb-storage
opkg install block-mount

6.
Partitioned the USB as partition 1 = 3.5GB Ext4
partition 2 = 512MB Swap
7. Plugged usb into the 703N
8. ran :
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 set fstab.@swap[0]=swap
uci set fstab.@swap[0].device=/dev/sda2
uci set fstab.@swap[0].enabled=1
uci commit fstab

9.
Ran :
mount /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind / /tmp/root
cp -a /tmp/root/* /mnt
umount /tmp/root
umount /mnt
reboot

10. reconnected and success big_smile

This is based off ianmcmill's work. Hopefully this helps someone big_smile

--edit--
Here is my new df -h:

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    3.5G    124.0M      3.2G   4% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    14.3M      1.8M     12.5M  13% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 3.5G    124.0M      3.2G   4% /overlay
overlayfs:/overlay        3.5G    124.0M      3.2G   4% /

(Last edited by ralim on 19 Feb 2013, 09:04)

and when you  go to network in luci everythings fine or ?

Opkg remove is useless with squashfs images...

The opkg remove did free up enough space on the unit for everything to install nicely for me. But i dont understand the whole system perfectly, i just went with what worked...

Luci seems to be working perfectly?

LuCi Home
LuCi Network
LuCi Software

Tell me if you want screen shots of anything else..
I also have wifi set up to act as an ap as i didnt normally on a different firmware with Luci... smile

Thanks,
Ralim

nice, i will redo extroot with your tutorial big_smile

Thank you ianmcmill for putting this together. I Managed to install extroot following your instructions and got arround the lack of space by installing some package in ram ( i have modded my router with 64MB of ram , but it should work on a stock 32Mb unit  as the packages aren't really big ). This is my tutorial based on your original instructions :




opkg update
opkg install kmod-usb-storage kmod-usb2 kmod-fs-ext4 hotplug2 block-mount ldconfig

There's not enough room in internal Flash to store all the packages with standard rom, but since we only need some temporary we just go for a ram install

opkg install fdisk e2fsprogs -d ram


But we need to update current PATH in order to find the stuff in ram and update ldconfig

PATH=$PATH:/mnt/usb/usr/bin:/mnt/usb/usr/sbin:/mnt/usb/sbin:/tmp/usr/bin:/tmp/usr/sbin:/tmp/sbin:/tmp/usr/lib
echo "/tmp/lib/" > /etc/ld.so.conf
echo "/tmp/usr/lib/" >> /etc/ld.so.conf
ldconfig

plug your usb storage to the router
and check if it is detected properly

dmesg | grep sd    

This should show the USB stick like :

 
root@OpenWrt:/tmp# dmesg | grep sd
[    9.720000] sd 0:0:0:0: [sda] 3915776 512-byte logical blocks: (2.00 GB/1.86 GiB)
[    9.730000] sd 0:0:0:0: [sda] Write Protect is off
[    9.730000] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[    9.730000] sd 0:0:0:0: [sda] No Caching mode page present
[    9.740000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.750000] sd 0:0:0:0: [sda] No Caching mode page present
[    9.750000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.760000]  sda:
[    9.760000] sd 0:0:0:0: [sda] No Caching mode page present
[    9.760000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[    9.770000] sd 0:0:0:0: [sda] Attached SCSI disk

let's partition the usb storage

fdisk /dev/sda

If your are familiar with fdisk, creating 3 primary partitions shouldn't be a hassle.
In my example the first partition is 2GB. The second around 500MB and the third gets the rest of it.

**we now assume the device has no partition , to check this use "p" to print current partition table , delete any if the table is not empty


root@OpenWrt:/tmp# fdisk /dev/sda
Welcome to fdisk (util-linux 2.21.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3915775, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3915775, default 3915775): +1200M
Partition 1 of type Linux and of size 1.2 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 2
First sector (2459648-3915775, default 2459648):
Using default value 2459648
Last sector, +sectors or +size{K,M,G} (2459648-3915775, default 3915775): +500M
Partition 2 of type Linux and of size 500 MiB is set

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (1-4, default 3): 3
First sector (3483648-3915775, default 3483648):
Using default value 3483648
Last sector, +sectors or +size{K,M,G} (3483648-3915775, default 3915775):
Using default value 3915775
Partition 3 of type Linux and of size 211 MiB is set

In short type

n
p
1
default
+1200M

n
p
2
default
+500M

n
p
3
default
[enter]          // will use the rest of the available space


t
3
82

w        // finish with writing new partion table

now we need to format those :

mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/sda2
mkswap /dev/sda3

then we have to update fstab to mount all the partitions

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

Copy the root fs

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


now we need to clean all the unneeded stuff

opkg remove ldconfig --force-removal-of-essential-packages
rm /etc/ld.so.conf
opkg remove fdisk e2fsprogs

we are now clean , reboot the router and check that all went ok

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.2G     58.4M      1.1G   5% /
/dev/root                 2.0M      2.0M         0 100% /rom
tmpfs                    30.2M     88.0K     30.1M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 1.2G     58.4M      1.1G   5% /overlay
overlayfs:/overlay        1.2G     58.4M      1.1G   5% /

All done , Enjoy

(Last edited by nimu68 on 6 Mar 2013, 21:15)

Hi Nimu68,

I followed your steps and successfully done, now, since my USB is 8G, I got something like this:

Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.1G      9.7M      1.1G   1% /
/dev/root                 1.8M      1.8M         0 100% /rom
tmpfs                    14.1M     68.0K     14.1M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sda1                 1.1G      9.7M      1.1G   1% /overlay
overlayfs:/overlay        1.1G      9.7M      1.1G   1% /
/dev/sda2               476.2M      2.3M    449.0M   1% /opt

It looks like the big part of my disk goes to swap area, I'd like to use that for a samba share later, how to redo this process? Thanks,

Angelo

nimu68 wrote:

Thank you ianmcmill for putting this together. I Managed to install extroot following your instructions and got arround the lack of space by installing some package in ram ( i have modded my router with 64MB of ram , but it should work on a stock 32Mb unit  as the packages aren't really big ). This is my tutorial based on your original instructions :


All done , Enjoy

If you boot up without the stick inserted it will fall back to pre-extroot setup. You can then insert the stick and reformat it correctly.

I have experienced some erratic behaviour after following the instructions in the first post (extroot worked but after a reboot many internet were down. Strange, I need to investigate that.

But meanwhile, I would like to ask for some clarifications of instructions:

a) Both the first post (by ianmcmill) as well as the one by Nimu68 use 3 partitions on the USB drive. My understanding is SDA1 = dataspace for user (eg server data), SDA2 for extroot / rom, SDA3 = swap. Is that correct?

b) If a is correct, shouldn't in step6 (when copying the rootfs) SDA2 or /opt appear somewhere?

c) Is the fallback to pre-extroot setup when booting without USB-stick (mentioned by robthebrew) only temporary? Meaning if I reboot again _with_ the USB stick present will then the extroot configuration load again?

d) The fstab file should be located in /etc/config, correct?

Thank you for explanations.

The discussion might have continued from here.