RSS

Tag Archives: USB

TP-Link TL-WR1043ND – Openwrt – Ch05_USB_Storage

0) Briefing

    • What next
      • My USB thumb drive will be partition in 3 parts. I will be using ext4 for data storage. You may use FAT16/FAT32/NTFS, but you cannot have your drive as rootfs_data ( /overlay )
      • Install USB storage kernel module kmod-usb-storage ( 82 Byte in total )
        • Dependency : kmod-scsi-core
      • Install block-mount( 132 byte in total )
        • Dependency : libuuid libblkid blkid swap-utils
      • Install libext2fs( 168 Byte in total )
        • Dependency : libpathread libcom_err
      • install ext4 file system kernel module kmod-fs-ext4 ( 188 Byte in total )
        • Dependency : kmod-lib-crc16
      • (Optional) Install file system utilities e2fsprogs ( 312 Byte in size )
      • Setup a USB thumb drive to be part of the root memory

——————————————————————————–

1) Install USB storage softwares

  • Open up your favorite terminal and login into the router
    ssh root@192.168.1.1
  • These commands will update database:
    opkg update
  • Install all these softwares (580 Byte in size):
    opkg install kmod-usb-storage block-mount libext2fs kmod-fs-ext4
  • (Optional) If you want to format you USB thumb drive via OpenWRT, you should install:
    opkg install e2fsprogs

——————————————————————————–

2) Prepare your USB thumb drive

  • I am using a 8GB thumb drive, and will be chopped into 3 partitions:
    1. Root file system data ( /overlay )
    2. Personal data storage ( /mnt/shares )
    3. Swap

2.1) Partitioning

  • Plug in your external drive into your computer and see if it is present:
    dmesg  | tail -20
  • You should able to see something like USB storage in those lines, but you should be looking at:

    sd 0:0:0:0: [sda] 15124992 512-byte logical blocks: (7.74 GB/7.21 GiB)

    • Your drive is recognized as /dev/sda
    • if you have more than one drive, then it may be /dev/sdb
  • Use fdisk to partition your drive:
    fdisk /dev/sda
  • My partitions on my 8GB thumb drive:
    1. sda1 – 6.2GB – ext4 – Use for personal data ( /mnt/shares )
    2. sda2 – 504MB – ext4 – Root files system data ( /overlay )
    3. sda3 – The rest 300MB+ – Swap
  • Then you should format your drive:
     mkfs.ext4 -O ^has_journal,extent /dev/sda1
     mkfs.ext4 -O ^has_journal,extent /dev/sda2
     mkswap /dev/sda3

2.2) Mounting

  • Now plug in your USB external storage to the router
  • Create a location for you share folder and mount it
    mkdir /mnt/shares && mount /dev/sda1 /mnt/shares
  • To mount your swap partition:
    swapon /dev/sda3
  • To config your drives mount automatically at boot, first you have to find out the UUID of each partition. UUID is used is because Linux system cannot guaranty it will give the same sda or sdb or sdc to a drive. So when you write down the config file to mount sda1 it may not work because your drive may become sdb1 when next boot. Although it is very rare to be happened, now Linux system use UUID. UUID only change when you format your drive.To find out the UUID of your drive:
    blkid
  • Edit this file to tell the system what to mount:
    vi /etc/config/fstab
  • Here is my /etc/config/fstab

    config global automount
    option from_fstab 1
    option anon_mount 1

    config global autoswap
    option from_fstab 1
    option anon_swap 0

    config mount
    option target           /mnt/shares
    option uuid             “e2bbca31-8df9-447e-affd-70c927e59847”
    #option device          /dev/sda1
    option fstype           ext2
    option options          rw,sync
    option enabled          1
    option enabled_fsck     0

    config swap
    option uuid             “5fb9edfd-23f0-48c4-8a96-f2887b469329”
    #option device          /dev/sda2
    option enabled          1

  • When you are done, restart fstab
    /etc/init.d/fstab restart
  • Check are you drives properly mounted:
    df

——————————————————————————–

3) rootfs on external storage ( extroot )

In Linux file system, Root ( / ) is the mother of all folders and files. Every folder and file structure start building from there, just like C: drive in MS Windows.

Additionally, Linux link a USB external storage to a folder when it is plug in, so all other softwares in Linux will think it is just another normal folder rather than something special. They call this Mounting to a folder.

In OpenWRT, there are two main folders. One is /rom, which hold all pre-installed softwares. The other is /overlay, which hold every other data and settings, which included softwares that you manually installed.

What are we going to do now is to ask the system to mount our external drive to /overlay at boot. Imagine the original /overlay like a bin, you put things in it. Then what are we doing next is to put a plastic bag over the bin, which the bag represent the external drive. People still think they put thing into the bin, but actually the bag store everything, and when the bag is remove, it will expose the original stuffs inside the bin.

3.1) Partitioning and formating

  • If you have not partition and format your USB external storage, just follow the Step 2.1 above

3.2) Config to mount your external storage at boot

  • We need to visit the /etc/config/fstab file again:
    vi /etc/config/fstab
  • Add the following data:

    config mount
    option target            /overlay
    option uuid             “a60731b0-c056-4771-993e-c8f8338cc21f”
    #option device          /dev/sda2
    option fstype            ext4
    option options            rw,sync
    option enabled            1
    option enabled_fsck            0

3.3) Copy original /overlay data to external storage

  • As my Bin and Bag explanation above, if you put your new bag inside the bin, people will think it is a empty bin, however, the original stuffs inside the bin is needed. So we need to duplicate them to our bag.
  • First if your drive is not mount, mount it, in my case is sda2:
    mkdir /mnt/sda2 && mount /dev/sda2 /mnt/sda2
  • Then copy the original data to the external storage:
    tar -C /overlay -cvf - . | tar -C /mnt/sda2 -xf -
  • Unmount the external drive then reboot:
    umount /mnt/sda2 && rm -rf /mnt/sda2

——————————————————————————–

4) Quick tips

  • If you do not want to edit /etc/config/fstab, you can edit /etc/fstab:

    /dev/sda2    /overlay    ext3    rw,sync    0    0
    /dev/sda1    /mnt/shares    ext2    rw,sync    0    0
    /dev/sda3    none    swap    sw    0    0

——————————————————————————–

Appendix : References

 
5 Comments

Posted by on May 8, 2013 in Networking, Router

 

Tags: , , , , , , , , , , , , ,

TP-Link TL-WR1043ND – Openwrt – Ch00_Introduction

Today, routers are very powerful electronics equipments, they are not just only routing data packages, giving out IPs or blocking unwanted connections anymore. Now they also can act as File Server or Printer server as well.

Of course, manufactures will not put every single function into one router, otherwise, how can they earn some big cash from you. That’s why there are third-party firmwares. These third-party firmwares are base on Linux, which able to provide endless choice of software for you to use. Dropbear for SSH. FTP, SFTP, Samba or NFS for file server. CUPS for print server. SANE for scanner. Asterisk for VoIP. And sound server, webcam server….. The only limitation is on the hardware itself.

There are 3 large camp on third-party firmwares: DD-WRT, OpenWRT and Tomato. Personally, I have never use Tomato, so I could not make any comment on that.

My experience with DD-WRT is with my TP-Link TL-WR741ND. Which I have one in Hong Kong as my pptp VPN server. 741ND + DD-WRT is a bullet prove combination. I use it many hours everyday with huge data flow for 2 years now.

However, there are limitations. 1) 741ND don’t have USB port, which I can’t use it for file and printer/scanner server. 2) 741ND only have 4MB ROM memory, which left no space for anyone to install extra softwares. 3) The difficulty of setting up a DD-WRT.

Performance wise, I would not say DD-WRT will have to much different compare to OpenWRT, since they are both just Linux base, the different would not be huge. However, the simplicity of setup procedure with OpenWRT, definitely makes it a winner.

As I said before, 741ND lack a USB port, which is not going to be my next new toy. However, if you don’t need to use USB. I would say 741ND is the only choice you should have. And it is dirt cheap as well, less than USD$20 in Hong Kong.

My new toy would be TP-Link TL-WR1043ND. It cost just over USD$55, which cost much more than 741ND. But it come with big guns: Giga-byte LAN ports, 3 antennae, a much faster processor and a USB port.

My new setup, will be a PPTP+OpenVPN VPN servers, printer server, scanner server and a Samba file server.

 
Leave a comment

Posted by on April 11, 2013 in Networking, Router

 

Tags: , , , , , , , , , , , , , ,

 
%d bloggers like this: