19 September 2010

Mount and Automount Ext3 USB Drives on Western Digital My Book World 2ND Edition (White Light)

It seems somewhat silly that the WD My Book World 2ND Edition (MBWE II)supports USB drives that have NTFS and FAT filesystems but doesn't support the Linux EXT3 considering it runs Linux.

These instructions will let you mount and use USB drives with EXT3 partitions and I expect drives with other supported filesystems.

Firstly be careful! As with every tutorial I post only do this if you know what you are doing I take no responsibility you do it all at your own risk.

I actually expect that this will work for other filesystems that the NAS knows about but I don't have any drives with these formats to test it with, if you do try please post your results for others.


Manual Mount
Firstly you will need to SSH into the drive (you may need to turn it on using the admin web interface). There are lots of other sites that will tell you how to do this if you aren't familiar with this process.

If you aren't familiar using SSH you don't want to type the # it just indicates it is a command to enter, and everything is case sensitive. If you needed this help then you really need to be careful.

If you just want to mount the EXT3 drive as a one off it's easiest to do it manually, I've been doing this for some time now.

To mount the drive we need to find the device file associated with the drive, we can do this by running fdisk.
# fdisk -l
...
Disk /dev/sdb: 1024 MB, 1024966656 bytes
32 heads, 62 sectors/track, 1009 cylinders
Units = cylinders of 1984 * 512 = 1015808 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1               1         159      157697    b  Win95 FAT32
/dev/sdb2   *         160        1009      843200   83  Linux

The first set of entries (/dev/sda*) which I have omitted here are the WD's internal drive (if you have a dual drive version I'm assuming you will have a second drive listed here as well).

You should have a set of entries for your EXT3 drive. The above example is for a 1GB drive with two partitions, the first is a ~160MB fat drive and the second is a ~840MB EXT3 partition. So what I'm interested in is /dev/sdb2.

Next we create a folder to mount to, this can be anything but I've found the following nice because you can log into the copy manager on the web interface of the drive and use it to copy files between the drives (if you don't care about the copy manager /DataVolume/usb is probably a better place to make it).

# mkdir /shares/usb1-1share1

Then we mount the drive (replacing /dev/sdb2 with whatever device file fdisk showed your EXT3 partition to be listed as):

# mount -n -t ext3 /dev/sdb2 /shares/usb1-1share1

for other filesystems try:

# mount -n /dev/sdb2 /shares/usb1-1share1

You can then copy files to the mounted drive either using the web interface copy manager or from the console using either of the following commands:

# cp /DataVolume/sharename/file /shares/usb1-1share1/
# cp -r /DataVolume/sharename/folder /shares/usb1-1share1/



Note however that this method does not share the mounted filesystem though the standard mechanisms like CIFS. While it is possible to do this with this method it is just easier to automount the drive so if you want this read on.

Automount

The above worked fine for me for some time but I really wanted the drive to automount, and when I did a search around the web to find out how to do it, it seemed like I wasn't the only one to want the feature:
http://mybookworld.wikidot.com/forum/t-24171/
http://mybookworld.wikidot.com/forum/t-166644/need-help-sharing-ext3-usb-drive
http://mybookworld.wikidot.com/forum/t-247589
http://community.wdc.com/t5/My-Book-World-Edition/usb-ext3-drive-not-mounting/td-p/19414
http://community.wdc.com/t5/My-Book-World-Edition/MBWE-II-ext3-formatted-USB-storage/td-p/18643

I am currently not a member of all of these communities, and haven't bothered to list this on all these old threads, but if you have come here from one of these communities or another post about this it might be helpful if you would link this post.

This code patch is for Firmware Version 01.02.04 (currently the most recent firmware version) and should work with (Firmware Version 01.01.16).

First things first lets backup the file incase we make a mistake:
# cp /sbin/usb_auto_share_add.php /sbin/usb_auto_share_add.php.bkp

Should you need it you can restore the file using:
# cp /sbin/usb_auto_share_add.php.bkp /sbin/usb_auto_share_add.php

The only text editor on the NAS is currently vi, I like to recommend nano or pico to inexperienced users but unfortunately they aren't installed on this system. So I have developed an alternative for those who aren't familiar with vi.

Copy the file to a share you have, open the file over the network, edit it and then copy the file back. Here's how to do that, if your happy with vi just skip on a bit.

Find the share you want to copy to:
# ls /DataVolume/

Copy the file to the share using (substituting sharename with the case sesitive name you found using ls):
# cp /sbin/usb_auto_share_add.php /DataVolume/sharename/

Now open the file over the network using the method you normally would, make the edits outlined below and then save the file.

Once you've made the changes copy the file back to the folder using
# cp /DataVolume/sharename/usb_auto_share_add.php /sbin/

Here are the changes to make to the file. If your going to post this elsewhere a little credit that you found it here first might be nice :)

Open the file in vi:
# vi /sbin/usb_auto_share_add.php

Sorry for the layout of the following, I suggest that you copy it into something nicer before you read it (like notepad with Word Wrap turned off).

| lines from the original used for alignment.
o optional lines
+ lines to add.
- lines to remove


/sbin/usb_auto_share_add.php
|    // mount USB share for NTFS/HFS+ filesystem using ufsd
|    @system('/bin/mount -n -t ufsd -o gid=1000,umask=002,iocharset=utf8,force /dev/' . $USBDevInfo['devname'] . ' ' . $mountPoint, $retval);
|    if($retval != 0) {
|      // mount USB share with UTF8 option for FAT filesystem
|      @system('/bin/mount -n -o gid=1000,umask=002,iocharset=utf8 /dev/' . $USBDevInfo['devname'] . ' ' . $mountPoint, $retval);
|      $filesystem = 'fat';
|    }
+  
+    if($retval != 0) {
+      // Try mounting  USB share as ext3.
+      @system('/bin/mount -n -t ext3 /dev/' . $USBDevInfo['devname'] . ' ' . $mountPoint, $retval);
+      if($retval == 0) {
+        $filesystem = 'ext3';
+      }
+    }
+  
+    if($retval != 0) {
+      // Try mounting  USB share as any other file system known to the system.
+      @system('/bin/mount -n /dev/' . $USBDevInfo['devname'] . ' ' . $mountPoint, $retval);
+      if($retval == 0) {
+        $filesystem = ''; // or could use [= 'unknown';] // Note: Could find file system type with [mount] but see no reason to at this stage.
+      }
+    }
O  
O    // Debug Log
O    @system("/usr/bin/logger \"Mounted File System: $filesystem\" ");
O  
|    // mount USB share without UTF8 option for HFS+ filesystem
|    //if($retval != 0)
|    //  @system('/bin/mount -n -o gid=1000,umask=002 /dev/' . $USBDevInfo['devname'] . ' ' . $mountPoint, $retval);

=-=-=-=-=


|      // mount USB share for NTFS/HFS+ filesystem using ufsd
|      @system('/bin/mount -n -t ufsd -o gid=1000,umask=002,iocharset=utf8,force /dev/' . $USBDevInfo['partition'][$i] . ' ' . $mountPoint, $retval);
|      if($retval != 0) {
|        // mount USB share with UTF8 option for FAT filesystem
|        @system('/bin/mount -n -o gid=1000,umask=002,iocharset=utf8 /dev/' . $USBDevInfo['partition'][$i] . ' ' . $mountPoint, $retval);
|        $filesystem = 'fat';
|      }
+     
+      if($retval != 0) {
+        // Try mounting  USB share as ext3.
+        @system('/bin/mount -n -t ext3 /dev/' . $USBDevInfo['partition'][$i] . ' ' . $mountPoint, $retval);
+        if($retval == 0) {
+          $filesystem = 'ext3';
+        }
+      }
+     
+      if($retval != 0) {
+      // Try mounting  USB share as any other file system known to the system.
+        @system('/bin/mount -n /dev/' . $USBDevInfo['partition'][$i] . ' ' . $mountPoint, $retval);
+        if($retval == 0) {
+          $filesystem = ''; // or could use [= 'unknown';] // Note: Could find file system type with [mount] but see no reason to at this stage.
+        }
+      }
+     
O      // Debug Log
O      @system("/usr/bin/logger \"Mounted File System: $filesystem\" ");
O     
|      // mount USB share without UTF8 option for HFS+ filesystem
|      //if($retval != 0)
|      //  @system('/bin/mount -n -o gid=1000,umask=002 /dev/' . $USBDevInfo['partition'][$i] . ' ' . $mountPoint, $retval);
=====

Now you should be able to automount EXT3 drives and get them to show up as a shares like other filesystems on USB drives (according to your USB permsssions, see below):


It would have been nicer to get the filesystem type from mount but I haven't got around to that yet.
Now I didn't spend to long on this patch, and I havn't tested it with other file systems, but I believe it will also work with others supported by the NAS. I believe mount will try the filesystems listed in order in the following file:
# cat /etc/filesystems

You may be able to add more file systems to the list and even build and compile modules for file systems that aren't supported yet but that is well beond the scope of this article. I might add another post in future if I have the need, ext4 anyone???

I have identified a number of potential issues using EXT3, some which I have experienced and some that I hypothesised will create problems, if you find any more let me know and I'll list them here.
  • To access the share using normal methods you need to set the USB share permssions apropriately using the admin web interface (Advanced Mode->Users->USB Share Permissions).
  • Because EXT3 is a native Linux file system supporting permssions, the permissions of the files may cause problems. This will particularly be a problem if you have created the files (or permssions) on another Linux system and then connected the drive to the NAS or are doing the reverse. You should be able to fix this using commands like:
    # chmod 775 /shares/usb1-1share1/
    # chown root /shares/usb1-1share1/
    # chgrp jewab /shares/usb1-1share1/

I will try to get in contact with the developers and see if they will include this patch into the next firmware update. If I get any worthwhile feedback I'll let you know.

Update: I've tried to contact the developers (listed in the file) and the email address appears to be dead. If you know of a firmware developer that works on the MBWE II or want to contact support to have this included in future firmware updates please feel free I'm sure it will help out many others.

7 comments:

  1. Very useful! Thanks a lot

    ReplyDelete
  2. Awesome! Thanks a thousand times! I wish i found this before spending 3 days to backup on a NTFS drive and another 3 days fixing my optware after a restore (update of firmware) and realising that i lost all the symbolic links.

    I took the time to try if it works with ext4, and i didn't had any luck.

    I have the impression that Western Digital doesn't let us mount ext* by mean.

    ReplyDelete
  3. Great - saved my day. WD is really crap running on Linux but not supporting Ext3 - unbelievable.

    ReplyDelete
  4. Thanks - really was a help getting my new drive attached.

    ReplyDelete
  5. any idea why i would get this?

    ~ # fdisk -l /dev/sdc

    Disk /dev/sdc: 250.0 GB, 250059350016 bytes
    255 heads, 63 sectors/track, 30401 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdc1 1 30401 244196001 83 Linux
    ~ # ls /shares/usb
    ~ # mount -n -t ext3 /dev/sdc1 /shares/usb
    mount: Mounting /dev/sdc1 on /shares/usb failed: Invalid argument

    ReplyDelete
  6. Sorry to bump an old post. You mentioned that it is possible to mount the drive as a normal share manually, but its easier to use the auto mount method. Could you share how to do it the hard way?

    ReplyDelete