User Folder on 2nd Partition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-01-2010 08:34 AM
Hey All
I plan on moving all of our end-user machines to a 2 partition model. The OS will be on the first partition and /Users will be on the second partition. Right now I'm connecting the OS with /Users through a symlink. ln -s /Volumes/UserData/Users /Volumes/MacHD/Users .
I havent had any problems in my test lab, but still unsure of the symlink idea. Has anyone else tried this? If you are using multiple partitions what did you use? I understand this can be done without symlinks via System Prefs > Accounts > Advanced Options but I havent found a way to replicate this through command line and I need this step to be part of a long automated bash script. An ideas would be grateful. ~Joseph
...
HUGE
Joseph Simon / IT Support Technician
718 233 4016 / F 718 625 5157
www.hugeinc.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-01-2010 11:14 AM
If you're running an OD, you could set this servers-side. If you want
a deployable script, you could do something like this:
#!/bin/sh
# Set the path to the new user directory here (no trailing slash).
PathToNewUserFolder=/Volumes/NameofExternal/Users
# Get list of UIDs above 499
for localuser in `dscl /Local/Default -list /Users UniqueID | awk '$2
499 { print $1; }'`; do
# Verify that they have a directory in /Users if [ -d /Users/${localuser} ]; then
# Change their NFSHomeDirectory attribute to the new location.
dscl . -change /Users/${localuser} NFSHomeDirectory
/Users/${localuser} ${PathToNewUserFolder}/${localuser}
# Move their home directory to the new location. mv /Users/${localuser} ${PathToNewUserFolder}
fi
done
FYI, I haven't tested this, this is just off the top of my head, so be careful.
Cheers,
Brandt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-01-2010 03:15 PM
We're just about to implement something similar for our teachers, but are using the fstab entry rather than symlink. I've got a script in Casper that runs after the imaging process and does the following:
1) Checks with an inventory server to see if it's a staff machine, based on MAC.
2) If a staff machine, checks the partition map.
a) If it only finds one partition, it grabs the size of the drives,
does some calculations and resizes the boot partition and adds
a User partition.
b) If it finds a second partition, does some testing to determine which is
the OS and which is the Users.
3) Gets the GUID of the Users partition, and uses that to configure fstab entry.
4) Adjusts permissions on the root of the boot partition so users can only write to it
if they authenticate.
It's in the testing stage so far and working quite well, it's about to be deployed later this week though so will be a fun ride I'm sure. The definite bonus is that if we need to reimage a machine we don't have to backup the user's data first - just run the image which wipes the boot drive, the script detects the Users partition, configures fstab, restarts. We bind back to AD and the user can log back into their original account.
Not really any reason why one couldn't change the fstab to the symlink method pretty easily as well.
I'm a bit crazy with deadlines right now but if you're interested I could probably send the script, minus the proprietary 'test against our inventory database' portion.
Jeff Dyck | Analyste de reseaux - Mac OS X
Conseil Scolaire Francophone de la Colombie-Britannique (SD 93)
3550 Wellington Street, Annexe B - Port Coquitlam, BC - V3B 3Y5
Tel: 778-284-0902 - Cell: 778-990-7960 - http://support.csf.bc.ca

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-01-2010 04:03 PM
So I've had a couple of off-list requests for the script, so will try to include it here...
BTW, might be a subject for a separate message, but I find it really annoying that whenever I just 'reply' to a message on this list it only goes to the user of the message I'm replying to, rather than to the list - I wonder how many messages and answers we miss because of this... Is there any way the listserve could be configured slightly differently to change that behaviour?
Anyway, on to the script, I've tried to comment it but probably missed something, so if you have any questions let me know and I'll do my best to explain what I was doing.
Oh, any feedback or better ways of doing things is always welcome.
Cheers
Jeff
----script begins here----------
#!/bin/bash
#########################################################################
# #
# Name: AutoPartition.sh #
# Date: May 21, 2010 #
# Author: Jeff Dyck (jeff_dyck at csf.bc.ca) #
# #
# Purpose: This script is designed to run as a post-imaging script for #
# Casper Imaging, to ensure there is a users partition on staff comps. #
# The script is designed to partition /dev/disk0 into two partitions, #
# Macintosh HD and Usagers. #
# #
# Thanks goes out to Thomas Larkin (tlarki at kckps.org) and #
# Steve Wood (swood at integer.com) for pieces of the script. #
# #
#########################################################################
# This script assumes that the primary drive in all computers is disk0
# Root check if [ `id -u` != 0 ] then echo "you are not root!" exit 1; fi
# Get HD Size and partition count...
let HDSize=diskutil info /dev/disk0 | awk '/Total Size/ { sub(/..*/, "", $3); print $3 }'
let Partitions=df | grep -c -i /Dev/disk0
################################################# # Find OS Partition, rename if required. # #################################################
# If we find a partition with our default name, then it's pretty obvious... if [ -d /Volumes/MacintoshHD ]; then OS=/Volumes/MacintoshHD
# Otherwise lets look for a partition on disk 0 that has a system folder
else
if [ $Partitions -eq 1 ]; then
partitionName=diskutil info disk0s2 | grep "Volume Name:" | sed -e 's|Volume Name:||g' -e 's/^ *//'
if [ -d "/Volumes/{$partitionName}/System" ]; then OS="/Volumes/${partitionName}" fi
elif [ $Partitions -gt 1 ]; then
#Add 2 because internal drive has 2 invisible partitions for HFS... let partitionTester=$[ $Partitions + 1 ]
for ((a=2; a <= $partitionTester; a++)); do
partitionName=diskutil info disk0s${a} | grep "Volume Name:" | sed -e 's|Volume Name:||g' -e 's/^ *//'
if [ -d "/Volumes/${partitionName}/System" ]; then
# Rename to MacintoshHD
diskutil rename disk0s${a} MacintoshHD
partitionName=diskutil info disk0s${a} | grep "Volume Name:" | sed -e 's|Volume Name:||g' -e 's/^ *//'
OS="/Volumes/${partitionName}"
fi
done
fi
fi
############################# # Partition if required # #############################
# Used = the amount of space USED on the OS partition
used=df -h "$OS" | awk '/dev/ { print $3 }' | sed -e 's/%//g' | sed -e 's/Gi//g'
# If there are already partitions, we don't want to delete them, exit. if [ $Partitions -gt 1 ]; then say "This is a staff computer that has already been partitioned"
# Otherwise, create partitions based on HD size... elif [ $Partitions = 1 ]; then say "This is a staff computer that has not been partitioned, adding a users partition"
if [ $HDSize -lt 80 ]; then say "The hard drive is less than 80GB, too small to partition." exit 0
elif [ $HDSize -ge 200 ]; then newhd=$[ $used * 3 ] say "Macintosh HD will be resized to $newhd gigabytes"
else newhd=$[ $used + 25 ] say "Macintosh HD will be resized to $newhd gigabytes"
fi
# Set User Partition Size newuser=$[ $HDSize - $newhd - 1 ] say "The users partition will be $newuser gigabytes"
# Enable Journaling On Partioned Drive diskutil enableJournal "$OS"
# RePartiton ! diskutil resizeVolume disk0s2 "$newhd"G JHFS+ Usagers "$newuser"G
# Move /User Account folders (mostly 'shared') to new partition mv "$OS"/Users/* /Volumes/Usagers/ fi
################################################ # Figure out name of the user's partition # ################################################
if [ -d /Volumes/Usagers ]; then usersVol="Usagers"
else #Add 2 because internal drive has 2 invisible partitions for HFS... let partitionTester=$[ $Partitions + 1 ]
for ((a=2; a <= $partitionTester; a++)); do
partitionName=diskutil info disk0s${a} | grep "Volume Name:" | sed -e 's|Volume Name:||g' -e 's/^ *//'
if [ -d /Volumes/${partitionName}/System ]; then #This is a system disk, move on to next partition... continue
else
folderList=ls /Volumes/${partitionName}/
for folder in $folderList; do
if [ $folder = "Shared" ] || [ -d /Volumes/${partitionName}/${folder}/Desktop ]; then
usersVol="${partitionName}"
break
fi
done
fi
done
fi
################################################ # Setup the FSTab for users partition # ################################################
say "Configuring f s tab to use $usersVol as user folder"
# Get the device name of the users folder, then use that to get the UUID for the partition
DEVNAME=diskutil list | grep ${usersVol} | awk '{print $6}'
UUID=diskutil info $DEVNAME | grep UUID | awk '{print $3}'
# Configure FSTab file echo "UUID=$UUID /Users hfs rw 0 0" > "${OS}/etc/fstab"
exit 0

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 07:55 AM
Another way to try and do this is to do portable home directories on thumb drives. I know it has it's own caveats, but it would allow any user to log into any computer on your domain as long as they plug in their thumb drive. Of course thumb drives get lost, washed in the laundry (I did that once...), stepped on and broken and so forth.
Just be careful with Apple updates and HD maintenance. I have had sym links break on me before in the past. Nice script. How does your /etc/fstab hold up? I have also had inconsistencies with editing that file myself in 10.5 and in 10.6. It worked better for me in 10.4 for some odd reason.
-Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 08:10 AM
I added the /etc/fstab segment to my script, tested and I think I'll be sticking with a symlink
Its pretty inconsistent.
After moving /Users to partition 2 and editing fstab. It work pretty well. BUT if you create a new user account, (mobile accounts for us) it recreates /Users on the OS partition and locks out any other user accounts that were moved to the 2nd partition.
I guess It would work if you add all the necessary users on the machine before editing the fstab file but for us that doesn't work.
Hey Jeff I see your script contains chunks of my AutoPartion.sh script I sent out about a week ago. Can I get some credit ? ;]
~Joseph

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 08:13 AM
Hi Jeff,
thanks for posting this script - it has spurred me onto moving forward with a two partition (OS and Users) setup for some of our images.
I have run into a problem with it though. On line 89 ( newhd=$[ $used 3 ] ) the script fails for me. It seems to be because bash cannot do the multiplication with a non-integer. In my case the result of line 74 ( used=df -h "$OS" | awk '/dev/ { print $3 }' | sed -e 's/%//g' | sed -e 's/Gi//g'
) gives me 6.3 and I get an error (when I run the script manually) that says " ./fstab_orig.sh: line 98: 6.3 3 : syntax error: invalid arithmetic operator (error token is ".3 * 3 ") "
Any ideas of how to get around this (I can understand bash quite well, but am not so good at writing it myself!!)
thanks
paul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 08:20 AM
Paul
You you can use this
Used =df -h / | awk '/dev/ { sub(/..*/, "", $3); print $3 }' | sed -e 's/%//g' | sed -e 's/Gi//g'
The original autopartion.sh script that I sent out last week had many bugs that I have since resolved. I will send out the totally working one shortly. ~Joseph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 09:01 AM
Updated autopartition script.
It is working with no problems. This is meant to be run after you imaged a machine. Works with both 10.5 and 10.6. ~Joseph
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 10:02 AM
Hmmmm,
The behaviour you are seeing is definitely not matching my experience... I'm definitely creating new users and they are definitely showing up on the second partition - my users are also mobile, managed users under an AD - OD golden triangle configuration.
Not sure if this might be the problem, but FSTAB requires there to be an existing folder to mount to, so if you've completely moved the /Users folder out of the way it probably doesn't have a folder to attach to and wouldn't work very well... Something to try anyway.
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 06-03-2010 10:04 AM
I've added your name to the credits section on my original - sorry about that... Gets hard to track when you're taking bits and pieces from here and there and modding them to suite ;).
Jeff

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Posted on 04-26-2012 08:34 AM
Think we needd that script promised by Oxford Uni at the user conf in London!
