Goal
Set up a hard drive that is bootable to either OS X 10.6 or Ubuntu, but with a shared user partition so that user data is accessible regardless of which operating system is booted into.
Arrangement
I did this as an experiment, so I set up the dual boot on an external USB drive. I never modified my primary internal hard drive in this process. Afterwards, I could boot from the external USB drive, which was a bit slow but definitely useable.
I’m running a MacBook Pro with 10.5 as the local machine. The external USB is 400 GB (this could be far less).
I had a Snow Leopard .dmg for this, but not an install DVD. As part of this process, I create a partition on the external USB for the Snow Leopard install. I then use that partition to install the Snow Leopard OS on another partition, which will be my OS bootable partition. If you have a Snow Leopard DVD, the first partition I make below is not necessary.
Step 1 – Format the Drive
This step will completely erase the USB drive and any data on it.
- Open Application > Utilities > Disk Utility
- Select the USB drive
- Select “Partition” tab
- Select “Volume Scheme” > “4 partitions”
- Click “Options…” and make sure “GUID Partition Table” is selected
Step 2 – Setup the partitions
The first partition is going to hold the Snow Leopard install (this is not a bootable Snow Leopard OS):
- Click on Partition “Untitled 1”
- Rename to “Install” (you may use any name)
- Format: “Mac OS Extended (Journaled)”
- Size: 8 GB
The second partition is the bootable Snow Leopard OS:
- Click on Partition “Untitled 2”
- Rename to “OSX” (you may use any name)
- Format: “Mac OS Extended (Journaled)”
- Size: 80 GB (minimum is probably around 20 GB, you may want larger to accommodate /Applications)
The third partition is the shared data partition:
- Click on Partition “Untitled 3”
- Rename to “Data” (you may use any name)
- Format: “Mac OS Extended” (not journaled because Linux is going to be reading this)
- Size: 100 GB (all user/personal files will go here, so entirely up to you)
The fourth partition is a place holder that the Ubuntu install will format:
- Click on Partition “Untitled 4”
- Format: Free Space
- Click “Apply” and then “Partition” to format
Step 3 – Setup the Snow Leopard Install (optional if you have an install DVD)
- Obtain Snow Leopard Install DVD .dmg
- Double click on dmg to mount the drive
- Open Disk Utility
- Click on “Restore” and then “Restore” (I wish I had better notes on this because this doesn’t seem specific enough. What you need to do here is “Restore” the install dmg to the first “Install” partition you created above)
- This may require the admin password for the local machine even though it is not modifying it
- Wait time: 15 minutes
Step 4 – Install Snow Leopard
Restart the local machine with the USB plugged in and must hold down the OPTION key
Holding down the OPTION key during any restart throughout this process is a good practice. This way you always specify the boot drive and don’t waste time booting to the wrong drive by accident.
Continue with install:
- On the gray boot screen, select the “Install” USB option
- Follow all installation prompts
- When prompted to select a drive to install to, select your “OSX” partition
- Wait time during install: 25 minutes
- After installation, computer automatically restarts
- Continue following installation prompts
- You will be prompted if you want to transfer existing data. You may select any option and proceed accordingly, but I’m going to proceed with the “Do not transfer…” option.
- Create your user account. I use “user1” here (you can use any name)
OPTIONAL – Test/familiarize with mount and fstab
This section is for education/troubleshooting and can be skipped. It intentional does some incorrect actions below so you can note the error messages in case you encounter these while trying normal operations.
- Boot on the OSX partition and log in as user1
- Open Applications > Utilities > Terminal
- To see available disk drive hardware, enter
diskutil list
My output is:
user1s-MacBook-Pro:~ user1$ diskutil list /dev/disk0 #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *160.0 GB disk0 1: EFI 209.7 MB disk0s1 2: Apple_HFS Macintosh HD 159.7 GB disk0s2 /dev/disk1 #: TYPE NAME SIZE IDENTIFIER 0: GUID_partition_scheme *400.1 GB disk1 1: EFI 209.7 MB disk1s1 2: Apple_HFS Install 8.6 GB disk1s2 3: Apple_HFS OSX 85.9 GB disk1s3 4: Apple_HFS Data 107.4 GB disk1s4
/dev/disk0 is the local machine’s (MacBook Pro) internal hard drive.
/dev/disk1 is the external USB. Note the three partitions that we created: Install, OSX and Data. The Data partition corresponds to /dev/disk1s4. We’ll be repeatedly using this “disk1s4” reference; note if your Data partition is different and replace in the text below.
- To see which drives are mounted, enter:
df
My output is
Filesystem 512-blocks Used Available Capacity Mounted on /dev/disk1s3 167772160 19276312 147983848 12% / devfs 220 220 0 100% /dev /dev/disk0s2 311909984 308295856 3614128 99% /Volumes/Macintosh HD map -hosts 0 0 0 100% /net map auto_home 0 0 0 100% /home /dev/disk1s2 16777216 13018432 3758784 78% /Volumes/Install /dev/disk1s4 209715200 124152 209591048 1% /Volumes/Data
Our OSX partition (/dev/disk1s3 from the list diskutil output) is mounted as the root at /. Our Install and Data partition are mounted in the Volumes directory.
In the next section, we are going to make our Data partition mount in place of the standard /Users directory. Here, we are going to practice an intermediate step of mounting it to a new directory called /MyData.
- Put a temp file in the Data partition so we can check for it later
touch /Volumes/Data/this_is_data_partition.txt
- unmount the Data partition from it’s current location:
umount /dev/disk1s4
you should get an “operation not permitted” error. Note that this command requires root permission:
sudo umount /dev/disk1s4
you may get a “resource busy” error. Note that this can be overridden with the -f flag:
sudo umount -f /dev/disk1s4
if you try “df” again, the data partition is no longer mounted.
Note: there are analogous commands such as:
sudo umount -f /Volumes/Data diskutil umount /dev/disk1s4 diskutil unmount /Volumes/Data
The diskutil command is part of Mac OS X so it will not be on *nix systems. While diskutil may be preferred by some, I’m using the umount command that is part of *nix so we are familiar with it once we are in Ubuntu.
- create the directory where we will mount the partition:
cd / mkdir /MyData chmod 755 /MyData
- try to mount the Data partition
mount /dev/disk1s4 /MyDisk
- you should get a permission error, so use sudo
sudo mount /dev/disk1s4 /MyDisk
- you should get an “Incorrect super block” error. You need to tell it to use the Mac HFS partition type
sudo mount_hfs /dev/disk1s4 /MyDisk
Note: there are analogous commands such as
mount -t hfs /dev/disk1s4 /MyDisk diskutil mount -mountPoint /MyDisk /dev/disk1s4
Now we will use fstab to make /MyDisk the default mount point for the Data partition instead of /Volumes/Data. The fstab file does not exist under Mac OS X by default, so you may need to create it. (Note: you do not modify the fstab.hd file)
sudo touch /etc/fstab sudo nano /etc/fstab
- enter the following text through the nano editor:
/dev/disk1s4 /MyDisk hfs auto,rw 0 0
At any point, type control-O to save and hit ENTER to accept the file name. Type control-X to exit.
- Now unmount the partition:
sudo umount -f /dev/disk1s4
Now mount it using the defaults specified in fstab
mount -a
Confirm that our Data partition mounted automatically to /MyDisk:
df
The output should contain a line showing the partition is mounted at /MyDisk:
... /dev/disk1s4 209715200 124152 209591048 1% /MyDisk ...
Lastly, we should note that the label /dev/disk1s4 might change to disk0s4, disk2s4, diskNs4, etc… depending on what drives are present at boot. We can instead use the universal unique identifier (UUID), which will never change for a given drive.
Assuming disk1s4 is still mounted to /MyDisk, we find the UUID with:
diskutil info MyDisk
- To filter to the appropriate line:
diskutil info MyDisk | grep UUID
Copy the UUID and modify fstab to use *your* UUID, NOT the one shown below. The line in fstab should look something like:
UUID=1E837B07-01C9-3A9D-384E-6378993848DFF /MyDisk hfs auto,rw 0 0
- Confirm that our Data partition mounts automatically using the UUID in fstab
sudo umount -f /MyDisk mount -a df
Lastly, undo the actions we’ve done in this section, since it was only for instructional purposes. With the final nano command below, remove the MyDisk line from /etc/fstab.
rm -f /MyDisk/this_is_data_partition.txt sudo umount -f /dev/disk1s4 rm -rf /MyDisk sudo nano /etc/fstab
Step 5 – Make OSX use the Data partition for the /Users folder
- Boot to the OSX partition and log in as user1
- Put a temp file in the Data partition so we can check for it later
touch /Volumes/Data/this_is_data_partition.txt
- Edit fstab to include a line that references your Data partition by UUID and mounts it at /Users like this. Use your own UUID. (Unclear how to do this? See the optional section above):
UUID=1E837B07-01C9-3A9D-384E-6378993848DFF /Users hfs auto,rw 0 0
Create a preference file that tells the OS to automount the Data partition even before a user has logged in:
- Open a new document in TextEdit
- Select Menubar > Format > Make Plain Text
- Paste the following:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>AutomountDisksWithoutUserLogin</key> <true/> </dict> </plist>
- Save as /Library/Preferences/SystemConfiguration/autodiskmount.plist
Reboot to single user mode
- Apple menu > Restart…
- When gray screen appears, hold down “command-S”
- Mount the root partition:
/sbin/mount -uw /
- Move the original User directory out of the way
mv /Users /Users-old
- Create a new /Users directory for the mount location
mkdir /Users chmod 755 /Users
- Attempt to mount the Data partition to /Users using fstab settings
mount -a
- Confirm – You should see /dev/disk1s4 mounted to /Users:
df
- Move the original /Users content to the Data partition (Data partition should now be mounted at /Users)
ditto -v -rsrcFork /Users-old /Users
- Confirm that things are in order. You should both the “this_is_data_partition.txt” temp file and the user1 directory with the following command:
ls /Users
- Move the temp file into the user1 directory:
mv /Users/this_is_data_partition.txt /Users/user1
- Reboot
reboot
- Log in as User1
- Confirm – You should see the “this_is_data_partition.txt” in user1’s home directory
Step 6 – Install Ubuntu
- Obtain a Ubuntu desktop iso (this demo uses ubuntu-desktop-11.10.iso)
- Burn to a CD (There are options to burn to a USB but I never got those to work)
- Insert the CD, restart, hold down the OPTION key during restart, click the “Windows” CD (If you just inserted the CD, The “Windows” CD may take 10-20 seconds to appear)
- Wait for Ubuntu to boot (from CD, this take 2-3 minutes)
- Select the “Install Ubuntu” option
- Follow appropriate installation steps
Regarding installation location, you will need to manually set up new partitions:
- Select the install “Somewhere else” location at the appropriate install step
- Select the USB drive with the partitions that we set up (mine was /dev/sdb. The MacBook Pro internal drive was /dev/sda)
- In the main list, select the last “Free Space” entry for /dev/sdb
- Click “Add…”
- Size: 1500 MB (1.5 GB)
- Use as: “swap”
- Click “OK”
(For my setup, this created sdb5)
- Again, select the last “Free Space” entry for /dev/sdb
- Click “Add…”
- Size: 20000 MB (20 GB)
- Use as: “Ext4”
- Mount point: “/” (this is the root directory)
- Click “OK”
(For my setup, this created sdb6)
- Set the “Device for boot loader” option to: /dev/sdb6 (whatever was created four your ext4 partition above)
- Click “Install now” (Wait time: 10 minutes)
- After installation, restart, and eject CD
OPTIONAL – If Ubuntu install fails
If some part of the Ubuntu installation fails and you want to start over, you may have to delete the partitions created by the installation process.
- Boot into your local drive
Use the following to determine the device name of your USB drive, such as disk 1
diskutil list
List the partitions of that device
diskutil list disk1
Use the gpt command to list your partitions
gpt -r show disk1
To identify partitions, match the # column in the diskutil output to the index column of the gpt output. Erase the partitions created by the Ubunti installation process (there are probably 2-3). Before deleting a partiton with the the gpt command, you need to eject the volume with diskutil. Then substitute the partition’s index value after the -i in the gpt command. The following removes partitions 7, 6, and 5:
- diskutil eject disk1
- gpt remove -i 7 disk1
- diskutil eject disk1
- gpt remove -i 6 disk1
- diskutil eject disk1
- gpt remove -i 5 disk1
Step 7 – Make Ubuntu use the Data partition for /home
- Log in to user1 on Mac OS X and run:
id
My output was:
uid=501(user1) gid=20(staff) groups=20(staff),... [output truncated by author]
Note that user1’s uid=501 and gid=20(staff)
- Restart into Ubuntu, do not log in, go straight to terminal at login screen using: function-control-option-F3
- In terminal, log in as user1
- Setup a root password if you have not done so already:
sudo passwd root
- Logout as user1
exit
- Log in as root
- Remove all existing files from /home directory to make room for clean mount (Note: if you have done anything outside this tutorial to create files in your home directory, move those to a safe place before preceding with this command.)
rm -rf /home/*
- Make a backup of fstab:
cp /etc/fstab /etc/fstab.backup
- Determine the device name of the Data partition, which is likely mounted at /media/Data:
df
Mine was /dev/sdb4
- Get the UUID:
blkid /dev/sdb4
If the command above worked, append this to fstab so we can edit it (Note: if you mistype the command below and only use a single “>” (greater-than symbol), you will overwrite your fstab and have to start over. That’s why we made a backup)
blkid /dev/sdb4 >> /etc/fstab
- edit the fstab file with nano. Create a new line for the Data partition, using the UUID which has been brought in. Note: you need to remove the quotes around the UUID. The new line should read:
UUID=1E837B07-01C9-3A9D-384E-6378993848DFF /home hfsplus auto,user,nodev,rw 0 0
- Unmount from the old location:
umount /dev/sdb4
- Attempt to mount automatically using fstab
mount -a
- Confirm mount was successful at /home
df
Lastly, we want to change the user and group ID of our Ubuntu user1 account to match that of Mac OSX. You should have the Mac OS user and group id from the beginning of this section. In my case, userid=501 and gid=20(staff)
- Change the user and group ID:
usermod -u 501 -g 20 user1 groupdel user1 grouped -n staff dialout
Note: for my Ubuntu installation, gid=20 was for a group called “dialout”, while on Mac OSX gid=20 was for a group called “staff”. I’m opting to make the Ubuntu group 20 match Mac OSX’s “staff” group. I don’t have expertise to determine if this change to the “dialout” group will cause problems down the line, so use at your own risk.
Step 8 – Install rEFIt
- Download rEFIt dmg (download) and mount disk image
- Run “rEFIt.mpkg” to install
- Select “OSX” as install drive
- Enable rEFIt (admin password needed):
/efi/refit/enable.sh
Mac OS uses a GPT partition table, but Ubuntu typically needs an MBR partition table to boot. “gptsync” is a little tool that creates a MBR table from the GPT table. The MBR can only have 4 partitions, 1 of which is taken by default, so we need to fill the other 3 slots with the linux partitions.
rEFIt might work at this point if you were only dealing with an internal drive. In this case, the internal drive would be the “first” drive, and rEFIt might work on the first drive. But since we are installing on an external USB, which is usually the “second” drive, we need to run an additional command to get rEFIt working.
- Download gptsync archive (info, download)
- Run “gptsync-0.2.pkg” to install
- The “gptsync” command should now be in your path, so test with:
gptsync /dev/disk1
Here was my output:
Current GPT partition table: # Start LBA End LBA Type 1 40 409639 EFI System (FAT) 2 409640 17186855 Mac OS X HFS+ 3 17449000 185221159 Mac OS X HFS+ 4 185483304 395198503 Mac OS X HFS+ 5 395198504 398128191 Linux Swap 6 398128192 437190692 Basic Data Current MBR partition table: # A Start LBA End LBA Type 1 1 39 ee EFI Protective 2 40 409639 0b FAT32 (CHS) 3 * 409640 17186855 af Mac OS X HFS+ 4 17449000 185221159 af Mac OS X HFS+ Status: MBR table must be updated. Proposed new MBR partition table: # A Start LBA End LBA Type 1 1 409639 ee EFI Protective 2 409640 17186855 af Mac OS X HFS+ 3 17449000 185221159 af Mac OS X HFS+ 4 185483304 395198503 af Mac OS X HFS+ May I update the MBR as printed above? [y/N]
The first section above lists the actual GPT table, which reflects all partitions. The second section above lists the current MBR table, which can have a maximum of 4 partitions. The third section is what gptsync is proposing to update the MBR table to. Its proposal is incorrect, so
- respond with a “N” and ENTER.
The two partitions from the GPT (first section above) that Ubuntu will need in the MBR in order to boot are: “#5 Linux Swap” and “#6 Basic Data” (which has Ubuntu on it). We fill the fourth and last slot with #4, the Data partition.
- Run this command:
gptsync /dev/disk1 4 5 6
- Restart
- Hold down the OPTION key
- Select the rEFIt option
- Select the Linux option to boot.
Finish
You now have a hard drive that can boot to either OS X or Ubuntu, but both systems use the same shared data partition for user files.