Wide Awake Developers

« What makes a POJO so great, anyway? | Main | Coach and Team From Same Firm »

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.

Whew.

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.

Caveats:

  1. 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.
  2. 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".
  3. 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.

Comments

you can also edit your homedirectory information in Leopard using System Preference "Account". If you "right-click/control-click" on any account listed in the account panel you will get an "advanced" editor sheet that lets you directly edit several aspects of your account (including home directories). Remember to reboot after changing this sort of information or make sure to run dscacheutil -flushcache.

NOTE: the contextual menu may not show up until you've actually "unlocked" the accounts panel.

This is great. I was looking for niutil in Leopard and found out it was not going to be there. The process works ok. The caveats mentioned in 2. may be resolved by using "ditto -rsrcFork" instead of "cp".

Any idea how to make all new accounts automatically be created on a specific volume?

I would like to create a multi-user system with all local accounts that are created reside on a seperate partition.

Dave,

That sounds a lot easier! It was fun for me to explore the internals of Mac OS X's directory, though. I'm a long-time UNIX user, so I started with "/etc/passwd" and had to find my way from there.

On Tiger, the GUI was my crutch. Lacking that I had to go looking for another way. Typical of a UNIX user to head straight for the command line, isn't it?

Michael,

Have you tried:

rsync -a cp -Rp /Users/mtnygard/ /Volumes/Data/mtnygard/

instead of 'cp'? 'rsync' can handle hard links and special files properly. Tiger's 'rsync' is broken for resource forks (and 'cp' probably is too), but I haven't tested it on Leopard yet.

PS-Why won't this site honor ` or formatting?

Hmm, pretty annoying to have a Windows-style "right-click only" options pane, though. Hopefully we'll get a contextual gear or the like in 10.5 final.

Anyway, dscl is pretty neat.

/Local/Users has changed to /Local/Default/Users under the first release of Leopard.

Prototypo,

Thanks. That's one of several updates I need to make. I'll add that in the next revision. (With attribution, of course!)

Looks to be the only solution since googbye Netinfo...

But have somebody tried on Leopard official release without problems ?
I tried, it works but sometines I get bugs, I'm not sure that's due to this but need some feebacks pls.

Thks !

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)