TechInfoDepot:DD-WRT/Mounting USB drive without located onboard fs modules

From TechInfoDepot
Jump to navigationJump to search

Problem description

Fact is: not all dd-wrt images include well-known filesystems support (vfat, ext2, ext3, ntfs) because of lack of router's EEPROM memory to store them. If on Supported Devices page your board has 4MB of Flash or less, there is no modules for common filesystems support on it. Although in web-interface you see option to enable ext3/ext2 support - it doesn't really work because of absence of these kernel modules files. It's very sad if you were going to extend router by external USB drive and use router for running Optware or to use it as fileserver. But there is one trick to mount your drive on it!

Note: This is extention of gouryella's way (taken from [1] http://www.dd-wrt.com/phpBB2/viewtopic.php?p=454647#454647), also by calvin18 and others of the community. Gouryella wrote a smart script that downloads the ext3 driver and mounts the 1st partition to /opt during boot (after WAN is up). This method is described here, but I think, this is not good way because result of getting script from internet depends on a lot of things. The most convenient storage for this on USB-flash itself, and the absence of fs drivers isn't a problem!

Solution

Proper way is to enable USB Support under Services - first

Core USB Support
USB 2.0 Support
USB Storage Support
Automatic Drive Mount

, and on boot your USB-drive will become accessible via /dev filesystem

It's impossible to mount filesystem, but it's accessible as block device, and this is core idea to store modules on micro-sized dedicated partition linearly, without mounting it.

Building / finding suitable kernel modules

You should have your set of kernel modules as .ko files (for your architecture and kernel version). You can use precompiled ones [2], or build them on your own. I used precompiled, and this works fine for me (kernel 2.6.23.17, mips32r2).

Preparing USB stick/ USB HDD as modules storage

USB drive should be partitioned into 2 parts: huge partition for main storage space (to format to filesystem) and little one (just some megabytes, not for formatting) to place tar'ed modules archive linearly.

I've prepared flash stick on Linux PC. Just inserted flash has sdb identifier

[11500.435285] sd 6:0:0:0: [sdb] Attached SCSI removable disk

It's mounted automatically, you should unmount it to break into parts then

root@ubuntu:~# umount /dev/sdb

Run fdisk utility with USB flash device as argument

root@ubuntu:~# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Entering command "p" prints out partition table. You should delete all of them if you want to make partitions from scratch. But it isn't requirement. Anyway you should have at least two partitions: big for formatting and little one for system reasons

Command (m for help): p
Disk /dev/sdb: 15.1 GB, 15103688704 bytes
64 heads, 32 sectors/track, 14404 cylinders 
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes 
Disk identifier: 0x6f20736b

This doesn't look like a partition table Probably you selected the wrong device.

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   ?      379950      937327   570754815+  72  Unknown
Partition 1 does not end on cylinder boundary.
/dev/sdb2   ?       82368     1027695   968014120   65  Novell Netware 386
Partition 2 does not end on cylinder boundary.
/dev/sdb3   ?      913029     1858355   968014096   79  Unknown
Partition 3 does not end on cylinder boundary.
/dev/sdb4   ?     1409025     1409052       27749+   d  Unknown
Partition 4 does not end on cylinder boundary.

Partition table entries are not in disk order

I had some mess on flash and going to remove all partitions and create new ones. Deleting is "d" command

Command (m for help): d 
Partition number (1-4): 1
Command (m for help): d
Partition number (1-4): 2
Command (m for help): d
Partition number (1-4): 3
Command (m for help): d
Selected partition 4

I've got a clean flash (filesystem isn't written to disk yet until "w" entered)

Command (m for help): p
Disk /dev/sdb: 15.1 GB, 15103688704 bytes
64 heads, 32 sectors/track, 14404 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6f20736b

  Device Boot      Start         End      Blocks   Id  System

Command (m for help): u
Changing display/entry units to sectors

Creating pair of partitions - primary number 1 started from default sector and with end at sector DEFAULT(LAST) - some megabytes/512 bytes per sector:

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (32-29499391, default 32): 
Using default value 32
Last sector, +sectors or +size{K,M,G} (32-29499391, default 29499391): 29444000

And second partition with default start (just space after 1st partition) and ending at the end of the disk

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 2
First sector (29444001-29499391, default 29444001): 
Using default value 29444001
Last sector, +sectors or +size{K,M,G} (29444001-29499391, default 29499391): 
Using default value 29499391

Print result of repartitioning: p command

Command (m for help): p

Disk /dev/sdb: 15.1 GB, 15103688704 bytes
64 heads, 32 sectors/track, 14404 cylinders, total 29499392 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: 0x6f20736b

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              32    29444000    14721984+  83  Linux
/dev/sdb2        29444001    29499391       27695+  83  Linux

If all is ok - commit changes

Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

Format large partition to ext3

root@ubuntu:~# mkfs.ext3 /dev/sdb1
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
920272 inodes, 3680496 blocks
184024 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3770679296
113 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Filling second partition with binary zeros

root@ubuntu:~# dd if=/dev/zero of=/dev/sdb2
dd: writing to `/dev/sdb2': No space left on device
55392+0 records in
55391+0 records out
28360192 bytes (28 MB) copied, 6.49572 s, 4.4 MB/s
root@ubuntu:~# 

After that get archive and copy it block-by-block over little partition

root@ubuntu:~# wget http://home.karneval.cz/10102207/fs.gz
--2011-08-18 18:24:46--  http://home.karneval.cz/10102207/fs.gz
Resolving home.karneval.cz... 80.109.240.73
Connecting to home.karneval.cz|80.109.240.73|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 166663 (163K) [application/x-gzip]
Saving to: `fs.gz'

100%[=================================>] 166,663      422K/s   in 0.4s    

2011-08-18 18:24:47 (422 KB/s) - `fs.gz' saved [166663/166663]

root@ubuntu:~# dd if=fs.gz of=/dev/sdb2
325+1 records in
325+1 records out
166663 bytes (167 kB) copied, 0.0163577 s, 10.2 MB/s

Try to get files directly from disk - it works pretty well.

root@ubuntu:~# cd /tmp
root@ubuntu:/tmp# tar -zvxf /dev/sdb2
ext3
ext3.ko
fat
fat.ko
fuse.ko
jbd.ko
mbcache.ko
nls_cp437.ko
nls_iso8859-1.ko
nls_iso8859-2.ko
nls_utf8.ko
vfat.ko
root@ubuntu:/tmp# 

Now eject USB drive from PC - it's ready for mounting on dd-wrt board.

Startup script on box for mounting

After plugging USB device into box, new drive should appear in dmesg listing

root@dir-620:~# dmesg
...
<6>usb 1-1: new high speed USB device using dwc_otg and address 2
<6>usb 1-1: configuration #1 chosen from 1 choice
<6>scsi0 : SCSI emulation for USB Mass Storage devices
<7>usb-storage: device found at 2
<7>usb-storage: waiting for device to settle before scanning
<5>scsi 0:0:0:0: Direct-Access     Generic  Flash Disk       8.07 PQ: 0 ANSI: 2
<5>sd 0:0:0:0: [sda] 7995392 512-byte hardware sectors (4094 MB)
<5>sd 0:0:0:0: [sda] Write Protect is off
<7>sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
<3>sd 0:0:0:0: [sda] Assuming drive cache: write through
<5>sd 0:0:0:0: [sda] 7995392 512-byte hardware sectors (4094 MB)
<5>sd 0:0:0:0: [sda] Write Protect is off
<7>sd 0:0:0:0: [sda] Mode Sense: 03 00 00 00
<3>sd 0:0:0:0: [sda] Assuming drive cache: write through
<6> /dev/scsi/host0/bus0/target0/lun0: p1 p2
<5>sd 0:0:0:0: [sda] Attached SCSI removable disk
<5>sd 0:0:0:0: Attached scsi generic sg0 type 0
<7>usb-storage: device scan complete

If they don't appear check if USB support enabled in Services-USB, otherwise enable save config and reload box. Highlited string is address of your USB-drive, it may differ. By the fact, it's a directory containing block partitions part1 and part2:

root@dir-620:~# ls /dev/scsi/host0/bus0/target0/lun0/
disc   part1  part2

Then make a simple script, to uncompress part2 somewhere into rw filesystem: /tmp or /var, load needed modules, and finally mount part1 to /opt mount point. In my case it looks like

root@dir-620:~# nvram set rc_startup="
sleep 15
mkdir /var/lib/fs
cd /var/lib/fs
tar -zxvf /dev/scsi/host0/bus0/target0/lun0/part2
insmod jbd.ko
insmod mbcache.ko
insmod ext3.ko
sleep 10
mount -t ext3 -o noatime /dev/scsi/host0/bus0/target0/lun0/part1 /opt"

This script works after executing manually, also works on restart:

root@dir-620:~# lsmod
Module                  Size  Used by
ext3                  106496  1
mbcache                 8192  1 ext3
jbd                    57344  1 ext3
nf_nat_pptp             4096  0
nf_conntrack_pptp       4096  1 nf_nat_pptp
nf_nat_proto_gre        4096  1 nf_nat_pptp
nf_conntrack_proto_gre     4096  1 nf_conntrack_pptp
etherip                 8192  0
n_hdlc                  8192  0
rt2860v2_ap           479232  1
usblp                   8192  0
scsi_wait_scan           480  0
root@dir-620:~# mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro)
none on /dev type devfs (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
ramfs on /tmp type ramfs (rw)
devpts on /dev/pts type devpts (rw)
devpts on /proc/bus/usb type usbfs (rw)
/dev/scsi/host0/bus0/target0/lun0/part1 on /opt type ext3 (rw,noatime,data=ordered)
root@dir-620:~#

Enjoy :-) Kirill Varlamov, Russia