Home
About
Projects
Articles
Resources
Music

Mobile Home

I do work for one of my clients both on site and off site. Since I'm participating in server software development, working on a laptop isn't really an option. I needed another way to take my workspace back and forther with me. Here's how I moved my home directory onto a usb drive:

The key was getting the machine to mount the correct partition at the right time in the right place. I discovered that SUSE has a daemon called suseplugger which auto-mounts removable media (like in windows!) but I quickly discovered that it runs in userland as part of a login session.

The simple solution I found was to use autofs to mount the drive when it's needed. I used two config files. The first file tells the automounter that mount-points under /mnt are described in the second file:

# file: /etc/auto.master
/mnt /etc/auto.home2

The second file tells the automounter which partition should be mounted at /mnt/home2 when it is accessed:

# file: /etc/auto.home2
home2 -fstype=ext3 :/dev/disk/by-label/home2

Note that I used the by-label links to make sure I get the right partition regardless of what device letter is assigned to my drive.

I used the KDE administrative interface to start autofs and set it to run on startup. Then I set my new home directory location in /etc/passwd:

sudo usermod -d /mnt/home2/altaurog altaurog

It worked!

The bigger challenge was unmounting the device after log-out. First I had to make sure there were no processing running keeping the device open. artsd for some reason doesn't seem to terminate properly under openSUSE 10.2/KDE, so I disabled it. I also noticed that when the SUSE login screen reappeared, the drive was re-mounted again for some reason. My simple workaround was to wait long enough for this to happen and then unmount the drive.

Since I'm using KDE, I created ~/.kde/shutdown/run-umount-usb.sh containing the following line:

nohup ~/bin/umount-usb.sh &

The nohup is important, since I want the script to continue executing after logout. Here's the script:

#!/bin/bash
# file: umount-usb.sh

# if we umount the drive too early, the system remounts it when logout is
# complete for some reason, so we have to wait until it's really finished.
sleep ${UMOUNT_SLEEP_SEC:-10}

# keep a log of our activities
exec >> /tmp/umount-log 2>&1

echo
date

# figure out which device it is
mydevice=`ls -l /dev/disk/by-label/home2 | perl -pe 's/.*\/([a-z]+)\d*/\1/i'`
echo device is $mydevice

# for diagnostic value, check processes
for device in `ls /dev/$mydevice[0-9]`
do
    fuser -mv $device
done

# now get mounted volumes and unmount them
df | grep "^/dev/$mydevice" | perl -alne 'print $F[-1]' |
{

    while read nextvol
    do
        echo attempting to unmount $nextvol
        sudo umount -l $nextvol
    done
}