Mounting an ext4 Partition over NFS on Mac OS X Snow Leopard

The title says it all.  I want to use a USB drive formatted with ext4 on Snow Leopard.  I mostly use the drive with Linux but sometimes I wish to mount it on my iMac at work to transfer a large amount of data (the wired network is just much faster there…).

My first attempt to mount an ext4 filesystem on Snow Leopard was to use MacFUSE and ext4fuse, but I quickly found this solution was inflexible (largely the ext4 support is very preliminary).

My solution is to install Debian Squeeze on the iMac using VirtualBox, mount the ext4 formatted USB drive on the guest Linux, and export the partition over NSF to the host iMac.  I had shied away from any virtualization up until this point, but it was actually quit trivial to set it up, so no installation note here.  Just download and install VirtualBox on iMac, install an OS by popping in an install media, following the standard Debian install procedure, and that was it.  The Debian installer has gotten easier to use so this should be very trivial.

Configure VirtualBox for Detect a USB Drive

Here I follow this article.

On VirtualBox, select the Debian I just installed.  Go to Settings -> Ports -> USB.  Check “Enable USB Controller” and “Enable USB 3.0 (EHCI) Controller.”  Add a new USB filter with all fields initially set to empty strings.  This is important so that the ext4 formatted USB drive gets detected before OS X does.  (When OS X detects such a device, it thinks the device is unreadable and gives me an option to either initialize (omg), ignore, or eject.  When this happens, make sure to choose “ignore.”)

Configure Network between Host and Guest

Here I follow this article.

On VirtualBox, select the Debian I just installed.  Go to Settings -> Network -> Adapter 2.  Check “Enable Network Adapter.”  For “Attached to,” choose “Host-only Adapter” and “vboxnet0″ for its name.  I may leave the default advanced settings.

On iMac host, find out the IP address of vboxnet0:

host$ sudo ifconfig
...
vboxnet0: ...
    ...
    inet 192.168.56.1 netmask 0xffffff00 broadcast 192.168.56.255

So the host machine is at 192.168.56.1.

Now, login to Debian guest as a regular user.  I configure the second network adapter that I created as follows.  Edit /etc/network/interfaces to have the following lines:

auto eth1
iface eth1 inet static
    address 192.168.56.10
    netmask 255.255.255.0

so that the guest machine is at 192.168.56.10.  Do

guest$ sudo ifup eth1

and try to login to guest from host:

host$ ssh 192.168.56.10

Make sure everything works fine through this point.

Mount the USB Drive in Debian

I just follow a standard procedure for mounting a USB drive, but here goes.  Start the guest Linux system.  Once logged in as a regular user, plug in the USB drive to iMac.  Find out which node the device has been attached:

guest$ dmesg | tail
...
scsi 3:0:0:1: Attached scsi generic sg3 type 13
...
 sdb: sdb1
...

This is how it looks like on my system.  Create a mount point and mount it:

guest$ mkdir ~/usb
guest$ sudo mount /dev/sdb1 /home/username/usb
guest$ ls /home/username/usb
... should see the content of the usb drive ...

If this works, the next step is to set up the NFS.

Setting up NFS on Debian Guest

On iMac host, find out the uid and gid of myself as a regular user:

host$ id
uid=501(username) gid=20(staff) ...

Take a note of these numbers.

On Debian, install some packages:

guest$ sudo aptitude install nfs-kernel-server nfs-common portmap

In /etc/exports, have the following line:

/home/username/usb 192.168.56.1(rw,sync,all_squash,no_subtree_check,anonuid=0,anongid=0)

[NOTE: THIS ACTUALLY DOESN'T WORK AS I THOUGHT.] Here, use the uid and gid of my regular user on iMac for anonuid and anongid; this is important so that the NFS mounted filesystem can be used as a regular user on iMac host.  Then execute:

guest$ sudo exportfs -a

Now /home/username/usb should be mountable on iMac.

Mounting the NFS Partition on iMac Host

host$ mkdir usb
host$ sudo mount_nfs -P 192.168.56.10:/home/username/usb usb
host$ ls usb
... should see the content of the usb drive ...

That’s it.

This entry was posted in Uncategorized and tagged , , , , , , , , . Bookmark the permalink.

5 Responses to Mounting an ext4 Partition over NFS on Mac OS X Snow Leopard

  1. conor says:

    thanks, helped me with setting up an NFS file server using virtualbox and connecting to it with the host machine!

  2. gerard says:

    By ext4fuse having preliminary support you mean that it lacks write support? Or something else? Just curious :). Oh, and if you feel like it, you might want to have a look at this => http://libguestfs.org/, I haven’t tried, but maybe you can compile it on OSX.

    • Taro says:

      gerard — I used the word preliminary just because the README implies that it’s a work in progress. Not surprising given that ext4 hasn’t been adopted as widely yet I believe. I remember that I couldn’t mount an ext4 partition on my USB drive at all; mount just locked up. I didn’t know how to make it spew out log messages, so I kinda just gave up.

      • gerard says:

        Well, by preliminary I guess it means that is not fully tested. Anyhow, since it doesn’t write to the partition, it should be safe to use. If you steel feel like giving it a try, and it locks, you can get the logs by adding a third parameter when you mount the partition. It would help if you could have a look and report a bug if it’s appropriate.

        BR,
        Gerard.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>