Wednesday, September 30, 2015

Cloning Macs using Recovery Mode (or a USB Boot Drive) over a Network

Cloning Macs using Recovery Mode or a USB boot drive involves using Disk Utility to create an image of the drive. Where this gets complicated is when you need to do this over a network. Now let me stop here and say that in my testing, Clonezilla seems to be a faster option. However, you can do this with just the tools in OSX.

A prerequisite is that your file server must be configured to allow AFP or NFS protocols. You can't mount an SMB/Samba share in Recovery Mode because the Samba libraries aren't loaded. But AFP and NFS are core to OSX. A NAS is really great here because most NAS boxes allow you to enable many different file sharing protocols. Be aware that if you use NFS, your server might have a separate option to allow writing over NFS.

With that set up, boot to recovery mode or the USB boot drive, then go to the terminal. Enter the following command to set up a mount point:

mkdir /Volumes/Server

"Server" could be anything you want, it's just a name.

Now mount the network share:

For NFS:
mount -t nfs (ip address of the server):(share, such as /nfs/images or /images) /Volumes/Server
example: mount -t nfs 10.1.1.50:/nfs/images /Volumes/Server

For AFP:
mount -t afp afp://(username):(password)@(ip address of the server)(share, such as /images) /Volumes/Server
example: mount -t afp afp://username:password@10.1.1.50/images

Now quit Terminal and go into Disk Utility. Select the drive you want to create an image for, and click New Image. Find the down arrow next to the location drop down that gives you the Finder view. In some versions of OSX your Share will show here. Otherwise, drop down the "Look in" box and choose the computer. Then you will be able to select the share.

Friday, September 18, 2015

Hiding the Wi-Fi password on a Mac

You can only hide the Wi-Fi password from non-administrative users.

1. Login as the user you want to hide from and remove the password from Keychain Access.
2. Login as an administrator and connect to the Wi-Fi network in question.
3. Open Keychain Access and drag the Wi-Fi password to the System chain.

All users will authenticate to the Wi-Fi network using the password in the System chain. They will even be able to see the username, if applicable. What they will NOT be able to do is show the password without administrative credentials.

Two Commandments after Cloning a Mac

1. Set the startup disk in System Preferences so the firmware doesn't take forever to find your boot drive.
2. Do a safe mode boot and login so it can clear system caches.

Thursday, September 17, 2015

Make a Clonezilla Live USB Stick for Mac

1/7/16 update: The easier way is to rewrite the partition table as GPT. If you use the Apple Disk Utility, there is an option to write a "GUID Partition Table" which is what you want to do when you re-partition the drive. Then format the partition as MSDOS(FAT32). However if you create the drive this way you won't be able to read it under Windows. So if you are going to use it with PC and Mac then use the following method instead.

On the Windows side, go to a command prompt and do the following:
Type Diskpart, press Enter
Type List Disk , press Enter
Type Select Disk # (where # is the number your drive shows up as), press Enter
Type Clean, press Enter
Type Convert GPT, press Enter
Type Exit, press Enter.
Then go into Disk Management and format the drive with FAT32.

Once you've partitioned and formatted, download the Clonezilla alternative stable zip and unzip to the drive and you are done.

This way also allows you to modify the boot menu, which for an EFI boot is located at EFI\boot\grub.cfg.

EDIT 3/21/17: If you are interested in a custom Mac boot icon and label, see this post.

***Original post***

I spent days trying to make a bootable USB of Clonezilla to use with Macs in my organization. I tried a number of USB makers as well as trying to put it together myself. Finally, I found the solution.

1. Download the alternative-stable AMD64 Clonezilla ISO.
2. Follow the instructions at http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx, referencing your Clonezilla ISO instead.

I have reproduced the steps here.

1. Open the Terminal (in /Applications/Utilities/ or query Terminal in Spotlight).

2. Convert the .iso file to .img using the convert option of hdiutil e.g.,
hdiutil convert -format UDRW -o ~/path/to/isoname.img ~/path/to/isoname.iso
(Where "isoname" is the name of the downloaded Clonezilla ISO)
Note: OS X tends to put the .dmg ending on the output file automatically.

3. Run
diskutil list
to get the current list of devices.

4. Insert your flash media.

5. Run
diskutil list
again and determine the device node assigned to your flash media (e.g. /dev/disk2).

6. Run
diskutil unmountDisk /dev/diskN
(replace N with the disk number from the last command; in the previous example, N would be 2).

7. Execute
sudo dd if=/path/to/downloaded.img of=/dev/rdiskN bs=1m
(replace /path/to/downloaded.img with the path where the image file is located; for example, ./ubuntu.img or ./ubuntu.dmg).

If you see the error dd: Invalid number '1m', you are using GNU dd. Use the same command but replace bs=1m with bs=1M
If you see the error dd: /dev/diskN: Resource busy, make sure the disk is not in use. Start the 'Disk Utility.app' and unmount (don't eject) the drive

8. Run
diskutil eject /dev/diskN
and remove your flash media when the command completes.

9. Restart your Mac and press alt/option key while the Mac is restarting to choose the USB stick.

If your external USB drive does not show up in Clonezilla, instead of choosing the local dev option, choose shell. Enter the following command to list your drives:
sudo fdisk -l
Your drive will be /dev/sdx, and the partition will be /dev/sdxn, such as /dev/sdb1.
Mount the partition to partimag with the following command:
mount -t auto /dev/sdxn /home/partimag
Then the following command to get back to Clonezilla:
exit