Mounting external disks to the DNS-323 USB port for fun and profit
Published January 19th, 2009 in dns-323, hacks, unix
Hey kids. So in my first post I alluded to the fact that I was going to enable the USB port on the back of the NAS for other stuff. Shame on me for not actually having gotten around to it until now.
We’re going to load a USB driver in the 323’s linux kernel so you can plug things in the back. And do stuff. Fun stuff! like…
- Plug a 2gb usb thumb drive in the back, and run ffp, torrentwatchdog and cron scripts off it, to allow the Volume 1 and Volume 2 disks to stay spun down as much as possible.
- Plug a much bigger external USB drive in the back (like my old Lacie 500gb) and map it as a shared drive.
- Plug an entire USB hub full of crap into the 323!
For now, I’m going to post a rough outline of what I’ve got working so far. The intent of this post is to guide you to some basic functionality; I’ll leave it to you, my dear readers, to extend this further. Personally, what I’m working towards is running my entire ffp from a usb flash disk; this was always my original intent. I’d like the main disks to be spun down as much as possible.
Anyway, I digress. Here’s what we’re going to do:
- Obtain and load kernel driver
- Test flash disk
- “Install” (read: mount) flash disk to the 323
- Configure the flash disk to show up as a share, just like Volume_1 or Volume_2
- Automate the process to survive a reboot
- In a later article, offload the ffp install from Volume_1 to the usb flash disk.
What you need:
1. A DNS-323 (duh), modded and running fun_plug. (If you don’t know what that is, you probably shouldn’t be trying this one at home)
2. A usb flash disk, or an external harddrive. These should be formatted FAT32, ideally, but can also run NTFS.
3. The usb driver module, available here
4. Some good music, and maybe a (diet) coke. Real hackers drink coke. Or snort coke. I can never remember.
5. Required reading/reference - here - (see post #30. But don’t download usb-storage.ko from there).
Obtain and Load the Kernel Driver
Create a directory and place the usb kernel driver module in it. Then load the module with the ‘insmod’ command:
<telnet/ssh into box>
cd /mnt/HD_a2
mkdir .bookstrap
grab the usb-storage.ko module from here and copy it to the directory you just created (/mnt/HD_a2/.bootstrap), then run insmod:
insmod /mnt/HD_a2/.bootstrap/usb-storage.ko
count to ten, and…
Test Flash Disk
check your dmesg log by typing: dmesg
You should see something similar to the following:
Initializing USB Mass Storage driver…
scsi2 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 2
usb-storage: waiting for device to settle before scanning
usbcore: registered new driver usb-storage
USB Mass Storage support registered.
Vendor: Model: Patriot Memory Rev: PMAP
Type: Direct-Access ANSI SCSI revision: 00
SCSI device sdc: 4030464 512-byte hdwr sectors (2064 MB)
sdc: Write Protect is off
sdc: Mode Sense: 23 00 00 00
sdc: assuming drive cache: write through
SCSI device sdc: 4030464 512-byte hdwr sectors (2064 MB)
sdc: Write Protect is off
sdc: Mode Sense: 23 00 00 00
sdc: assuming drive cache: write through
sdc: sdc1
Attached scsi removable disk sdc at scsi2, channel 0, id 0, lun 0
Attached scsi generic sg2 at scsi2, channel 0, id 0, lun 0, type 0
usb-storage: device scan complete
Get some more information on the flash disk you have plugged in: cat /proc/scsi/usb-storage<hit tab>
For me, I’m working with a 2gb Patriot Xsporter XT thumb drive. The output is as follows (note the /usb-storage/2 came from the “device found at 2″ above):
root@blinky:/mnt/HD_a2/ffp# cat /proc/scsi/usb-storage/2
Host scsi2: usb-storage
Vendor:
Product: Patriot Memory
Serial Number: 078505AD0503
Protocol: Transparent SCSI
Transport: Bulk
And lastly, perhaps most importantly, double check what the usb disk filesystem is:
fdisk -l
Disk /dev/sdc: 2063 MB, 2063597568 bytes
16 heads, 32 sectors/track, 7872 cylinders
Units = cylinders of 512 * 512 = 262144 bytesDevice Boot Start End Blocks Id System
/dev/sdc1 1 7872 2015216 e Win95 FAT16 (LBA)
ok, so I lied. My flash drive is FAT16, not FAT32. But that’s why we check right?
One more thing. Because I only have one drive plugged into the back (I’m not using a USB hub), the thumbdrive shows up as device /dev/sdc1. If I had more than one device, that may change. Just something to keep in mind because it might affect how you mount the disk (below). I think, however, for 99% of you, the disk should mount as /dev/sdc1. Let me know in the comments if otherwise!
Mount the Disk (FAT16/FAT32)
Next, we are going to create a directory on /mnt/ to mount (virtually attach?) the USB device to.
IMPORTANT NOTE: I AM MOUNTING A FAT32 FILESYSTEM. DO NOT MOUNT AN NTFS FORMATTED DISK WITH THE FOLLOWING MOUNT COMMAND. Got it? Good.
Create a mount point: mkdir /mnt/usb
Mount the disk: mount -t vfat -o umask=0 /dev/sdc1 /mnt/usb
Verify disk mounted:
mount
rootfs on / type rootfs (rw)
/dev/root on / type ext2 (rw)
proc on /proc type proc (rw,nodiratime)
/dev/loop0 on /sys/crfs type squashfs (ro)
/dev/sda2 on /mnt/HD_a2 type ext2 (rw)
/dev/sdb2 on /mnt/HD_b2 type ext2 (rw)
/dev/sda4 on /mnt/HD_a4 type ext2 (rw)
/dev/sdb4 on /mnt/HD_b4 type ext2 (rw)
none on /proc/bus/usb type usbfs (rw)
devpts on /dev/pts type devpts (rw)
/dev/sdc1 on /mnt/usb type vfat (rw,nodiratime,fmask=0000,dmask=0000,codepage=cp850,iocharset=iso8859-1)
Sanity Check- write some data to a file and read it back:
ls -lF /mnt/usb
echo "hello!" > /mnt/usb/hello.txt
cat /mnt/usb/hello.txt
Mounting an NTFS-formatted Disk (…Not so much)
Okay, so I realize a bunch of you probably have big, 500gb, NTFS-formatted disks kicking around that you want to plug in the back of the 323 and share. You are not going to like what I have to say, but from what I can gather, the NTFS kernel driver is rather unstable and will likely cause you to lose your data if you try to use it.
Now, that being said, if anyone gets it to work (and its stable), hit me up in the comments … till then, maybe you want to try one of these connected directly to your PC instead. Sorry
Configure Samba Share
Okay, so we’ve got it reading from the drive plugged into the back of the NAS. Now we want to tweak the samba config so that /mnt/usb shows up as a share, just like Volume_1 and Volume_2 do.
Note: This is a quick hack just to show how its done; this method will not last a reboot. (See the next section on how to make it persistent).
Login to the 323. edit /etc/samba/smb.conf and add the following to the end of the file:
[ usb ]
comment =
path = /mnt/usb
valid users =
read only = no
guest ok = yes
oplocks = no
map archive = no
Save the file.
Stop and restart samba:
/usr/bin/smb stop; /usr/bin/smb start
Count to 10 and navigate to \\<NAS> in Windows Explorer or the Mac finder or whatever. Bask in the glory that is your newly shared USB drive:

Automate the Process (to survive a reboot)
I’ll post this real soon. I promise. (If not, you can yell at me in the comments).
14 Comments to “Mounting external disks to the DNS-323 USB port for fun and profit”
- 1 Pingback on Jul 20th, 2009 at 5:19 pm
Hi,
I found that if a user has only one Hd in the 323 then the usb drive /dev/sdc1 will be /dev/sdb1
Anyway the DNS 323 can mount an HFS USB Drive?
OK, I’m officially yelling at you in the comments.
@Jason,
Write a script, mountusb.sh, something like:
—
#!/bin/sh
insmod /mnt/HD_a2/.bootstrap/usb-storage.ko
sleep 10
mount -t vfat -o umask=0 /dev/sdc1 /mnt/usb
—
Place the script in /ffp/etc/profile.d/ and make it executable.
If you require the samba share to be persistent, you have two choices.
1) add the following to the end of the mountusb.sh script:
echo “[ usb ]” >> /etc/samba/smb.conf
echo “comment =” >> /etc/samba/smb.conf
and so on for each line that needs to be added to smb.conf.
The last line of the script should then do the following: /usr/bin/smb stop; /usr/bin/smb start
2) Safer option?
Copy /etc/samba/smb.conf to somewhere like /ffp/var/scripts/mysmb.conf
Edit mysmb.conf and add these lines:
[ usb ]
comment =
path = /mnt/usb
valid users =
read only = no
guest ok = yes
oplocks = no
map archive = no
Save the file.
Edit your mountusb.sh script to swap your custom smb.conf with the original, on boot files:
cp /etc/samba/smb.conf /ffp/var/scripts/smb.conf.orig
cp -y /ffp/var/scripts/smb.conf /etc/samba/
The last line of the mountusb.sh script should then restart samba using the new config file: /usr/bin/smb stop; /usr/bin/smb start
This will be run every time you reboot, since mountusb.sh sits in /ffp/etc/profile.d/
Let me know how you make out. I’ll post my scripts for this once I beat my 323 into submission (ffp is currently broken, and I haven’t had time to tinker with it lately).
admin hi
please write instruction step by step for mounting external usb drive
i true linux newbe) and very need your help
senx
sory my english, i’m from russia
on this page http://lsol.ru/mount_usb_drive.htm
is no bad script for mounting external usb storage
what you thinking about this?
Hi … Mike
I’ve made a translated version of your script in french at http://riduidel.posterous.com/comment-jai-installe-mon-ffp-s
But I’m wishing something a little more ambitious.
I’ve found various sources implying it could be possible to run fonz_fun_plug from an usb drive … for fun and profit (less disk spinning, and so on).
Unfortunatly, I found strictly no good documentation about the usage of ffp from the flash drive … Oh, well, OK, I found some doc, but it was of absolutely no help.
So … have you got some some good documentation about moving ffp to an external usb drive ?
Thanks
Hello all,
I like idea presented at the beginning of this article:”Plug a 2gb USB thumb drive in the back, and run ffp, torrentwatchdog and cron scripts off it, to allow the Volume 1 and Volume 2 disks to stay spun down as much as possible.”
I try to follow this article and I add UBS hub with 3 USB sticks each 2GB. I copy ffp on it mount it at /mnt/usb and for easy access also at /mnt/HD_a2/Temp/usb. Rest two USB sticks I joined to raid (linear) using mdadm. This drive I want to use for torrent downloading (with Volume1 and Volume2 in standby mode)
first time:
mdadm –create –verbose /dev/md0 –level=linear –raid-devices=2 /dev/sdd1 /dev/sde1
mke2fs /dev/md0
each start up:
mdadm –assemble /dev/md0 /dev/sdd1 /dev/sde1
mkdir /mnt/usb_raid
mount -t ext2 /dev/md0 /mnt/usb_raid/
and again for easy access also /mnt/HD_a2/Temp/usb_raid/
I also configure Transmission 1.50 to store data on /mnt/usb_raid/ see article http://www.horto.ca/?p=21 and others. And cron to update new torrent from directory /mnt/usb_raid1\BT\torrents_to_add\ each hour.
For easy to add new torrents i made link (symbolic) ln -s /mnt/usb_raid\BT\torrents_to_add\ /mnt/HD_a2\BT\
I thought that booth HDDs will be in standby almost all the time expects time when cron initialize to check new torrents or move (remove) downloaded files from USB_raid to Volume1 what should take few minutes. But reality is different. HDDs are waked more times per hour (and cron is setup to run ones an hour). I try to move also config files .transmission-daemon from Volume1 to USB with fft and I did link ln -s /mnt/usb/.transmission-daemon /mnt/HD_a2/. It didn’t help. I don’t know what else could wake HDDs up. If symlinks (/mnt/usb/.transmission-daemon or mnt/usb_raid1\BT\torrents_to_add\) activate the disk or DNS323 BitTorrent does it or something alse.
If you need any .sh files or any additional info about my configuration write to this discussion.
configuration:
DNS323, 2xHHD, Seagate Barracuda 1000GB, standard format (non-raid), FW 1.06, DNS323 BitTorrent installed, Transmission 1.50 installed, Fonz_fun plug full packege installed v0.5, USB hub 4 port Trust, USB stick 2 GB Intelligent I-stic (with ffp), 2x USB stick 2GB Pretec (RAID JBOB [linear]) for Torrent download (later 64GB USB stick)
FYI this probably works best with an EXT2 filesystem (note you mention the NTFS corruption issue) because the DNS-323 is running linux. (I’m running firmware 1.05 on the DNS-323 and dunno what revision of ffp, but it’s about a year old, I guess, and this mounted my 500GB external (formatted EXT2) with no troubles.)
Well written entry. I’m really liking the idea of running ffp off a usb flash drive, to leave the hdd’s spun down most of the time.
My question (and please bear with my newbie-ness)- is it conceivably possible to have lighttpd (with ffp) running off of the flash drive, in order to host a very small, simple static website 24/7, without needing to access the HDD’s? I’d like to make the flash drive serve on the public side, but limit the HDD access on the lan (private) side of things.
Possible?
Another question– possible to get the DNS-323 to mount as a USB (hard drive) device over the USB port?
Hey there!
Used to know Unix commands but this is far away, but your blog really helped me hacking this NAS and to mount an external HD.
Really great work!
Look forward for a stable mounting procedure for NTFS drives…
Cheers!
Roger L. from Montreal
I am seeing that I only get the USB mount to work when I login through SSH, not when i reboot. Once i ssh into my 323 only then will i see \\\USB in my windows directory. I tried your option #1 since I didn’t want my smb share updates that i may make through the web-based GUI to be blown away by some snapshot in time’s permissions.
How can i get my mountusb.sh script to run on powerup and not login? Perhaps it is running on powerup but the samba server is not getting restarted correctly? I have smb stop/start at the end of my mountsub.sh script so I’m not sure what i’m doing wrong.