Moving Your Home Directory on Leopard
Since NetInfo Manager is going away under Leopard, we've got a gap in capability. How do you relocate your home directory without the GUI?
There are a few reasons you might want to move your home directory to another volume. For example, you might reinstall your OS frequently. Or, perhaps you just want to keep your data on a bigger disk than the one that came in the machine. In my case, both.
The venerable NetInfo is being replaced entirely with Directory Services. (Try "man 8 DirectoryServices" for more information.) There's a handy command-line tool you can use to interact with the DirectoryServices.
Let's start by opening up a Terminal window. (Applications > Utilities > Terminal) At first, you'll be logged in as yourself, not as root.
Last login: Wed Dec 31 18:00:00 on ttyp0 donk:~ mtnygard$
The first thing is to get out of your home directory, because we're going to delete it in about a minute and a half. Change to the root directory and make yourself into the root user with "sudo".
Last login: Wed Dec 31 18:00:00 on ttyp0 donk:~ mtnygard$ sudo su - Password: donk:~ root#
Next, fire up "dscl", the directory services command line. Without arguments, this gives you an interactive, shell-like environment to explore the directory. It also spews a bunch of help messages. If you give it "localhost", then it quietly assumes you wanted to interact with the directory.
You can list entries, cd around the directory hierarchy, and even create entries or change attributes.
User information is stored under /Local/Users, so we'll cd to that now.
donk:~ root# dscl localhost > cd /Local/Users /Local/Users >
Now, running "ls" will show you all the users that your machine knows. Try it now.
donk:~ root# dscl localhost > cd /Local/Users /Local/Users > ls _amavisd _appowner _appserver _ard _calendar _clamav _cvs _cyrus _eppc _installer _jabber _lp _mailman _mcxalr _mdnsresponder _mysql _pcastagent _pcastserver _postfix _qtss _securityagent _serialnumberd _spotlight _sshd _svn _teamsserver _tokend _unknown _update_sharing _uucp _windowserver _www _xgridagent _xgridcontroller daemon mtnygard nobody root /Local/Users >
Holy crap! Who the hell are all these people?
Well, of course, they aren't people. All the usernames starting with an underscore are application IDs. Root, nobody, and daemon are all part of the OS. Once you eliminate them, there should just be the people you've actually created accounts for. If you see any names you don't recognize at this point, this would be a good time to shut off your network connection.
At this point, you could "cd" directly into the entry for your user. It won't show you anything special; users do not have subnodes in the directory. It would set up your context for future commands, limiting them to just that user. In this case, however, we'll stay at /Local/Users and run "cat" on my username.
/Local/Users > cat mtnygard dsAttrTypeNative:_writers_hint: mtnygard dsAttrTypeNative:_writers_jpegphoto: mtnygard dsAttrTypeNative:_writers_passwd: mtnygard dsAttrTypeNative:_writers_picture: mtnygard dsAttrTypeNative:_writers_realname: mtnygard dsAttrTypeNative:authentication_authority: ;ShadowHash; dsAttrTypeNative:generateduid: 7F6A8EDE-63EC-4A34-9391-031A9C77806D dsAttrTypeNative:gid: 501 dsAttrTypeNative:hint: dsAttrTypeNative:home: /Users/mtnygard dsAttrTypeNative:jpegphoto: ffd8ffe0 00104a46 49460001 01000001 00010000 ffdb0043 00020202 ... 7fffd9 dsAttrTypeNative:name: mtnygard dsAttrTypeNative:passwd: ******** dsAttrTypeNative:picture: /Library/User Pictures/Sports/Tennis.tif dsAttrTypeNative:realname: Michael Nygard dsAttrTypeNative:shell: /bin/bash dsAttrTypeNative:uid: 501 AppleMetaNodeLocation: /Local/Default AuthenticationAuthority: ;ShadowHash; AuthenticationHint: GeneratedUID: 7F6A8EDE-63EC-4A34-9391-031A9C77806D JPEGPhoto: ffd8ffe0 00104a46 49460001 01000001 00010000 ffdb0043 00020202 ... 7fffd9 NFSHomeDirectory: /Users/mtnygard Password: ******** Picture: /Library/User Pictures/Sports/Tennis.tif PrimaryGroupID: 501 RealName: Michael Nygard RecordName: mtnygard RecordType: dsRecTypeStandard:Users UniqueID: 501 UserShell: /bin/bash /Local/Users >
Hmm. Seems like it must mean something. This is listing the values of all the attributes of my user profile. It's what I want, but there's a big pile of noise in the middle. That noise is a textual representation of my profile's JPEG. (I've edited it out of this transcript.) If you scroll up past that, you'll see the attribute of real interest.
The property dsAttrTypeNative:home tells the OS where to find my home directory.
I can change it with dscl's "change" command. The format of change is a little strange because it has to deal with multi-valued properties (as do all of the directory services commands.)
/Local/Users > change mtnygard dsAttrTypeNative:home /Users/mtnygard /Volumes/Data/mtnygard /Local/Users >
The first parameter is the object to change, the second parameter is the attribute to change. The third parameter is the old value that you want to replace (multi-valued list for each attribute, remember.) Finally, the fourth parameter is the new value you want to set.
Not quite done yet, though. I've given the OS a bogus home directory. There's no such directory as /Volumes/Data/mtnygard yet.
To get there, I have to move my directory from under /Users to the new location. I have to do this as root, but I don't want root to end up owning all my personal stuff. Fortunately, there's a "cp" option for that.
donk:~ # cp -Rp /Users/mtnygard /Volumes/Data/
Now, we're almost, almost done. Log off and log back on into your roomy new home directory.
- I don't know how to do this if you've got a shared directory tree set up. You might have that if you're on a Mac network at work, for example. You should definitely try this at home.
- The "cp" command I use will do really funky things if you've got hard links, symlinks, or especially circular symlinks in your home directory. Then again, if you've done that to yourself, you probably know enough Unix to work out your own parameters for "cp", "tar", "mv" or "cpio".
- One more thing: I'm not sure if this is from running a developer seed of Leopard, or if it's due to this home directory move technique, but I keep running into permissions problems. I couldn't automatically install dashboard widgets, for example. Adium complained that it couldn't create its "sounds" directory.