This hint is for you if you want to put your home folder on a USB flash drive to take between Macs, or maybe you are just interested in the novelty of being able to carry all of your 'stuff' around. Please note, this hint is not for the faint of heart.
The following instructions make it so you can take your home folder with you wherever you go. All you need is an admin password on each machine you want to use it on and, of corse, a flash drive. The roomier the flash drive the better, but I got this to work on a 128 megabyte flash drive. I won't be able to store much music or many pictures in this home folder (because of the size), but it would be great for getting to my documents and settings anywhere. I have a friend who has a 1-gigabyte flash drive. He would be able to use this for music, pictures, and maybe even small video files.
To see how my hint relates to this earlier hint on moving your home folder to an external hard disk, see the information at the bottom of this hint.
Behavior:
When you login to your computer with your flash drive connected, your user environment will be loaded from it. When you login to your computer without your flash drive connected, your user environment will be what it has always been.
Warning:
With these modifications, it is possible to mess up your ability to login to your user account. While I don't think you can lose your data this way, you can certainly lose your ability to log on to the right place (when I was first figuring this out I had some moments of panic, myself). I recommend creating a new user to try this on first, before trying it on your normal user. Also, when your flash drive is connected, it will look as if all your data and settings are gone. Don't Panic, you can still access them at /Users/short_username on your hard disk (where short_username is your Mac OS X short user name). Or simply logout and remove your flash drive (you will probably have to shut down, because it could be dangerous for the data on your flash drive to remove it, if it should happen to be mounted). Once you get this working and are happy with it, then you can simply copy across whatever you want from your normal user to your flash drive's user.
Also, I don't know how this modification would behave if your Mac OS X short user name and passwords on the different machines don't match. Also-also, I don't know how the different filesystems behave, should you use something other than the DOS filesystem that comes with most flash drives. This is open for experimentation. There is also the slight potential for an error to develop among the workings of this hint. I did put a fail-safe mechanism in the script (it will try to remove empty folders), but this mechanism is untested. If the flash drive is removed after it is detected (during boot) and before you login, the Mac OS will think that you want it to create a new home folder inside the invisible Volumes folder. The solution to this is to remove the directories it creates inside the Volumes folder if the script, for some reason, does not. I have NOT tested this hint with FileVault, and it will probably cause problems if you try it with FileVault on!
Here is what you do:
First of all, all of my samples are for my system, so Justin is my short user name and ATTACHE is the name of my flash drive.
#! /bin/bash
# This script checks to see if your flash drive is connected. If it is it will
# change your home folder reference to the flash drive. If your flash
# drive is not connected it will change the reference back to your
# usual home folder.
# Change 'Justin' to your Mac OS X short user name. (7 occurrences)
# Change 'ATTACHE' to the name of your flash drive. (5 occurrences)
# You can find the flash drive's name by typing 'df' in the terminal, but
# this should be the same name you see in the Finder.
# Remove empty directories that will confuse this script (this will not work
# if the directories are not empty):
rmdir /Volumes/ATTACHE/Users/Justin
rmdir /Volumes/ATTACHE/Users
rmdir /Volumes/ATTACHE
# Check to see if your flash drive is connected (if there is a folder for
# it in Volumes):
if [ -s /Volumes/ATTACHE ]
then
niutil -destroyprop . /users/Justin home
niutil -createprop . /users/Justin home /Volumes/ATTACHE/Users/Justin
else
niutil -destroyprop . /users/Justin home
niutil -createprop . /users/Justin home /Users/Justin
fi
sudo mv /Library/Hooks/FlashDriveHome.txt /Library/Hooks/FlashDriveHome
sudo chmod +x /Library/Hooks/FlashDriveHome
sudo /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow LoginHook /Library/Hooks/FlashDriveHome
sudo defaults write /Library/Preferences/SystemConfiguration/autodiskmount AutomountDisksWithoutUserLogin -bool true
mkdir /Volumes/ATTACHE/Users/
Some explanations:
sudo cp -r /Users/usertemplate /Volumes/ATTACHE/Users/Justin
sudo chown -R Justin /Volumes/ATTACHE/Users/Justin
Some explanations:
Mac OS X Hints
http://hints.macworld.com/article.php?story=20050423203849332