Skip to content

Physical to Virtualisation for iMac

This guide can apply to basically any desktop, however there are some additional details I will be covering specifically for iMacs.

I used to own an old 2008 iMac. Roughly around 2014 I built my own computer, and ever since this poor iMac has been collecting dust in my garage. It’s about time I got rid of it.

There’s a lot of sentimental data on it, right at the start of my passion to f**k around with computers. So I thought it would be best image the entire disk before I erase it.

From that image, I am about to mount it and rummage through the files on my new computer without having to wait for the old 5k rpm 300GB ATA drive to spin it’s final turns. Though it kinda inspired me, what if I could bring the computer back to life, in a virtual machine!

Taking a Disk Image

First things first, you need 2 storage mediums;

  1. Some EMPTY simple/fast USB stick, 16GB or more in capacity
  2. An EMPTY external drive with a capacity greater than the total disk space of your Mac. My 2008 iMac is 320GB, so I grabbed a 1TB external drive.

We need to take an image of the entire disk, all partitions. To do this, I flashed a copy of Ubuntu onto a USB stick and booted into that on the iMac. There’s quite a few guides on how to do this online, but simply download Ubuntu’s latest LTS ISO, and some sort of software (Rufus for Windows, or DD for Linux) to copy the ISO to your USB stick. Whack that USB into your Mac and hold the Option key while you boot it.

Head’s up, we’re going to live boot Ubuntu from the USB. For gods sake do not install Ubuntu onto your iMac, because you will lose your data. When Ubuntu asks you, select “Try Ubuntu”, not install.

Once the desktop has loaded, plug your external drive in. We need to mount this so we can copy the image of the internal drive over. Open Terminal and do lsblk to list block devices. You should see something like the following.

[email protected]:~$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0   320G  0 disk 
├─sda1        8:1    0   2G    0 part 
├─sda2        8:1    0   300G  0 part 
└─sda3        8:9    0   18G   0 part 
sdb           8:16   0   1T    0 disk  
└─sdb1        8:25   0   1T    0 part

Here we can see two unmounted drives. Sometimes, Ubuntu likes to automount USB drives, so you might actually see our external HDD mounted somewhere in /media. In our case, I’m going to take a wild guess that /dev/sda is the iMac’s internal drive, and /dev/sdb is our attached external drive. We’ll take note of these. Let’s mount our external drive. Type the following

[email protected]:~$ sudo mount /dev/sdb1 /mnt

Cool, let’s just quickly test we can write to that disk. Should come back with no errors.

[email protected]:~$ sudo touch /mount/writetest

We’re ready to take a full disk image. Refering back to our previous lsblk, lets use dd to create an image of our disk, and save it to our hard drive.

[email protected]:~$ sudo dd if=/dev/sda of=/mnt/imac.image status=progress bs=4M
537919488 bytes (538 MB, 513 MiB) copied, 8 s, 67.2 MB/s

This is gonna take a very long time. But once you’re done, you can unmount the external drive and shut the computer down.

[email protected]:~$ sudo unmount /mnt
[email protected]:~$ sudo shutdown now

Mounting our Disk Image

Now that we’ve got our disk image saved, we can put the old iMac to the side and have a look at our disk image. Let’s mount it, if it’s not already mounted.

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sde           8:64   0 465.8G  0 disk 
└─sde1        8:65   0 465.8G  0 part

There’s the drive, /dev/sde1. We’ll mount that. I’m going to create a mount point for it first.

$ sudo mkdir /mnt/exthdd
$ sudo mount /dev/sde1 /mnt/exthdd

Let’s look for the disk image. It’s located at /mnt/exthdd/mac.image.

$ ls -l  /mnt/exthdd
mac.image writetest

Okay, now let’s have a look through that! First we need to install something called kpartx. It does a lot of the heavy lifting, looking through that file to find the partitions, and then creates them as loopback devices. Do sudo apt install kpartx -y to install it.

Once you’ve got that installed, let’s create the loopback devices, and then do lsblk.

$ sudo kpartx -av /mnt/exthdd/mac.image
GPT:Primary header thinks Alt. header is not at the end of the disk.
GPT:Alternate GPT header not at the end of the disk.
GPT: Use GNU Parted to correct GPT errors.
add map loop0p1 (253:0): 0 409600 linear 7:0 40
add map loop0p2 (253:1): 0 612106240 linear 7:0 409640
add map loop0p3 (253:2): 0 12364384 linear 7:0 612778024
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 298.1G  0 loop 
├─loop0p1   253:0    0   200M  0 part 
├─loop0p2   253:1    0 291.9G  0 part 
└─loop0p3   253:2    0   5.9G  0 part 

There they are! Now we can mount them and browse through the files. loop0p2 is the one we’re most interested, the 300GB one. These loopback devices live in /dev/mapper.

$ ls /dev/mapper
control  loop0p1  loop0p2  loop0p3
$ sudo mkdir /mnt/img
$ sudo mount /dev/mapper/loop0p2 /mnt/img
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
loop0         7:0    0 298.1G  0 loop 
├─loop0p1   253:0    0   200M  0 part 
├─loop0p2   253:1    0 291.9G  0 part /mnt/img
└─loop0p3   253:2    0   5.9G  0 part 

And there it is, mounted! Let’s have a look at the files.

$ ls -l /mnt/img
total 167812
drwxrwxr-x 1 root      80        52 Jun 15  2017  Applications
drwxr-xr-x 1 root root           44 Jul 14  2012  bin
drwxrwxr-t 1 root      80         2 Feb 11  2010  cores
dr-xr-xr-x 1 root root            2 Feb 11  2010  dev
lrwxr-xr-x 1 root root           11 Dec 25  2010  etc -> private/etc
dr-xr-xr-x 1 root      80         2 Dec 25  2010  home
drwxrwxrwx 1 root      80        64 Jun 15  2017  Library
dr-xr-xr-x 1 root      80         2 Dec 25  2010  net
drwxr-xr-x 1 root root            2 Feb 11  2010  Network
drwxr-xr-x 1 root root            6 Dec 25  2010  private
drwxrwxrwx 1  501      80         3 Jun 15  2017  resources
drwxr-xr-x 1 root root           67 Jul 14  2012  sbin
drwxrwxrwx 1 root root            5 Jun 15  2017  System
lrwxr-xr-x 1 root root           11 Dec 25  2010  tmp -> private/tmp
drwxrwxrwx 1 root      80         7 Jul 25  2015  Users
drwxr-xr-x 1 root root           10 Dec 25  2010  usr
lrwxr-xr-x 1 root root           11 Dec 25  2010  var -> private/var
drwxrwxrwt 1 root      80         4 Nov 11 19:12  Volumes

Quite a few of those symbolic links wont resolve correctly, because we currently have a different root compared to when they were created on the iMac. But otherwise, everything should be there just as it was when you captured the image.

Preparing to Virtualise

First, install VirtualBox.

Once you’re done, we need to convert our raw disk image into a virtual disk format that VirtualBox accepts. To do this, open your terminal and type vboxmanage convertfromraw /mnt/exthdd/mac.image ~/Documents/mac.vdi. This again will take quite a while, as it needs to copy the disk to your local machine, and convert it to a VDI file.

Once you’ve gotten that squared away, you can unplug your external hard drive and put it to the side. Won’t be needing it again.

Let’s begin to create our Virtual Machine.

Virtualising the iMac

New VM

Open VirtualBox Manager, and select “New”. Give it a name, and set Type to “Mac OS X” and Version to whatever closely matches your actual computer. Snow Leopard 64-bit for me.

2048MB of memory is fine.

Do not add a virtual hard disk, we already have one created! Continue through the warning.

Configuring the VM

Click the new VM and then go to “Settings”.

Under System > Processor, increase the processor count to 2 or more vCPU’s.

Under Display > Screen, set Video Memory to Max, and enable 3D Acceleration.

Under Storage, remove the “Empty” disk, and then add a new hard disk. A new window will appear, click “Add”, then navigate to our mac.vdi file we created earlier.

Click OK

Fooling OS X

We’re almost there, though there is one last hurdle we need to jump. MacOS checks against the virtual machines “hardware” to determine if it’s running on Apple Hardware. Since clearly it’s not, we need to make it think it is.

Use the following commands, but substitute “mac” with the name of your VM, like “2008 iMac”.

 vboxmanage setextradata "mac" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac8,1"
 vboxmanage setextradata "mac" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
 vboxmanage setextradata "mac" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-AA95B1DDAB278B95"
 vboxmanage setextradata "mac" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
 vboxmanage setextradata "mac" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1

With luck, you should have successfully booted your old iMac in a Virtual Machine!

Leave a Reply

Your email address will not be published. Required fields are marked *