Update the package list and install the necessary modules to support USB drives and the ext4 file system:
root@OpenWrt:~# opkg update root@OpenWrt:~# opkg install block-mount kmod-usb-core kmod-usb2 kmod-usb-ohci kmod-usb-storage kmod-fs-ext4
Ignore the error message that appears during the installation of the kmod-usb-storage package (Barrier Breaker 14.07). In fact, the module is installed successfully.
kmod: failed to insert /lib/modules/3.10.49/sd_mod.ko
Reboot the router:
root@OpenWrt:~# reboot
Connect the USB drive and observe how the system reacts (it should detect it). In my case, the dmesg command showed the following:
root@OpenWrt:~# dmesg ... [ 18.800000] usb-storage 1-1.4:1.0: USB Mass Storage device detected [ 18.810000] scsi0 : usb-storage 1-1.4:1.0 [ 18.810000] usbcore: registered new interface driver usb-storage [ 19.810000] scsi 0:0:0:0: Direct-Access SanDisk Cruzer Fit 1.27 PQ: 0 ANSI: 6 [ 19.820000] sd 0:0:0:0: [sda] 62530624 512-byte logical blocks: (32.0 GB/29.8 GiB) [ 19.830000] sd 0:0:0:0: [sda] Write Protect is off [ 19.830000] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00 [ 19.830000] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 19.850000] sda: sda1 sda2 sda3 [ 19.860000] sd 0:0:0:0: [sda] Attached SCSI removable disk ...
If the system detected the drive and all its partitions, edit the /etc/config/fstab file to specify the mount points.
Instead of partition names like «sdxx» in the fstab file, use «uuid» identifiers, as they are unique. If you connect another (or even several) drives, there is no guarantee that the router will assign the correct name to the USB drive. Therefore, instead of the «device» partition name, specify the unique «uuid» identifier.
You can find the partition identifiers by running the block detect command, and then make the corresponding changes to fstab. If you are performing a fresh installation, it is better to generate fstab automatically:
root@OpenWrt:~# block detect >> /etc/config/fstab
Check the result:
root@OpenWrt:~# cat /etc/config/fstab config 'global' option anon_swap '0' option anon_mount '0' option auto_swap '1' option auto_mount '1' option delay_root '5' option check_fs '0' config 'swap' option uuid 'b91e3bff-9e15-4fd0-82e7-25d75d889ce6' option enabled '0' config 'mount' option target '/mnt/sda2' option uuid '7ee9d192-239f-4401-b749-3fb60b4f8eaa' option enabled '0' config 'mount' option target '/mnt/sda3' option uuid 'ad0381c6-31b8-4eda-ac21-a87bbd09eef2' option enabled '0
Edit the /etc/config/fstab file. Comment out or remove the parameters for the sda3 partition, which was created for NAS (we will configure NAS later):
root@OpenWrt:~# vi /etc/config/fstab config 'global' option anon_swap '0' option anon_mount '1' option auto_swap '1' option auto_mount '1' option delay_root '5' option check_fs '0' option from_fstab '1' config 'swap' option uuid 'b91e3bff-9e15-4fd0-82e7-25d75d889ce6' option enabled '1' config 'mount' option target '/overlay' option uuid '7ee9d192-239f-4401-b749-3fb60b4f8eaa' option fstype 'ext4' option options 'rw,sync' option enabled '1'
If the mount point parameters are obvious, let's take a closer look at the global section parameters:
option anon_swap '0' # монтировать своп-раздел, даже если он не описан в fstab option anon_mount '1' # монтировать раздел с данными, даже если он не описан в fstab option auto_swap '1' # автоматически монтировать своп-раздел при его обнаружении option auto_mount '1' # автоматически монтировать раздел с данными при его обнаружении option delay_root '5' # задержка X секунд до попытки монтирования корневого раздела option check_fs '0' # проверять файловую систему при монтировании option from_fstab '1' # читать данные fstab в случае "горячего" подключения устройства
Create a temporary directory /mnt/sda2 (for transferring the system located in the router's internal memory) and mount the USB drive partition to it.
root@OpenWrt:~# mkdir /mnt/sda2 root@OpenWrt:~# mount /dev/sda2 /mnt/sda2
Copy the /overlay partition from the router's internal memory to the partition on the USB drive. The copy operation is performed while preserving all permissions.
root@OpenWrt:~# tar -C /overlay -cf - . | tar -C /mnt/sda2 -xf -
Now you can unmount the partition and delete the temporary directory:
root@OpenWrt:~# umount /mnt/sda2 root@OpenWrt:~# rm -rf /mnt/sda2
Reboot the router:
root@OpenWrt:~# reboot
If everything is done correctly, the router should boot from the USB drive. If the router does not boot: disconnect the USB drive, boot with the internal /overlay, connect the USB drive, mount the partitions, and check fstab (sometimes you may need to do this several times … it helps :)) Tested on myself!
