Author Topic: Use Linux to install OSX from a DMG extracted to a partition - without a Mac DVD  (Read 79228 times)

0 Members and 1 Guest are viewing this topic.

Online Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17126
  • Karma: 434
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
I used Ubuntu 10.04 (Lucid), on which all the needed apps where available in the repos... also (FYI) I used a Mac OSX 10.5 (Leopard) .dmg, but I can see no reason this shouldn't work with a 10.6 (Snow Leopard) .dmg, 10.04 (Tiger) .dmg, or for that matter... any other OSX .dmg image.

[EDIT]

Anyone using this tutorial to install OS X 10.7 Lion may want to take a look at the info in this posting:
http://ubuntuforums.org/showthread.php?p=11924128#post11924128
or the last but one posting here:
http://ubuntuforums.org/archive/index.php/t-1969841.html

[END EDIT]

To install OSX from a .dmg image from within Linux, and without access to a 'working' Mac or a 'Mac OS X Installation DVD'... First you are going to need to install gparted, hfsplus, hfsutils, hfsprogs, and dmg2img...

Code: [Select]
sudo apt-get install gparted hfsplus hfsutils hfsprogs dmg2img

Next fire up gparted, and create 2 HFS+ PRIMARY partitions, one has to be a minimum of 8gb (or larger) and the other needs to be a minimum 30gb (or larger).

IMPORTANT - You MUST create 2 (or more) primary HFS+ partitions (see bottom).

(From here on I'm going to assume you have a .dmg file in your home directory called image.dmg)

Now you need to convert the .dmg to an .img:
Code: [Select]
dmg2img image.dmg image.img

You now have a mountable image, BUT it is a hybrid disk image... If you mount it now, all you will have access to is the first partition which does not have the installation files... They are in a hidden HFS+ partition within this image... an HFS+ partition starts with 1024 reserved bytes (for boot code), followed by the volume header... we're going to search for that header then subtract 1024 bytes to find the beginning of the partition.
The first 4 bytes of the volume header are a signature and a version number... "H+" followed by version 4 (or "HX" followed by 5 for HFSX). So we need to look for the following hex sequence in the image - "48 2b 00 04" for HFS+ (or "48 58 00 05" for HFSX)... the storage blocks here will probably be at a block boundary and have an address that ends with "0x00"

So in a terminal:
Code: [Select]
hexdump -C image.img | grep "48 2b 00 04"
now wait... this search may take a while.

I got:
0001d600  48 2b 00 04 00 00 01 00  48 2b 4c 78 00 00 00 00  |H+......H+Lx....|

My block number is "0001d600", and it ends with "00" so it's my volume header block (you need to use the number you get). However the partition starts 1024 bytes before that address, so you'll need to use an online hex converter:

http://www.statman.info/conversions/hexadecimal.html

(I'm going to convert the hex address 'I' got...  YOU need to use the hex address you got)
convert 0001d600 from hex to decimal = 120320
now subtract 1024
120320 - 1024 = 119296

Now use losetup to setup the .img as a block device starting with an offset of 119296:
Code: [Select]
sudo losetup -o 119296 /dev/loop0 image.img
(be sure to use YOUR offset, not mine)
Now that the loop device is setup, all you need to do is mount it:
Code: [Select]
sudo mkdir /mnt/tmp
sudo mount -t hfsplus /dev/loop0 /mnt/tmp/

You should now have access to all the Installation files inside the image (in the /mnt/tmp directory)... Copy EVERYTHING (as root) to the 8gb HFS+ partiton you created earlier.

Now you need to find out where on the hard drive this 8gb partition is located... fire up gparted again, and  count the active partitions from left to right... mine was on the First Physical Drive, 3rd active partition. (remember this)

You will need to edit (as root) the
/Library/Preferences/SystemConfiguration/com.apple.Boot.plist
file (on the 8gb partition), and set a kernel flag to point to this partition... i used gedit, but any text editor will do.

Look for the lines:
<key>Kernel Flags</key>
<string></string>


I changed them to:
<key>Kernel Flags</key>
<string>rdisk0s3</string>

but you will need to change rdisk0s3 to wherever YOUR 8gb partition is located.

rdisk0s3 = First Physical Hard Drive, 3rd partition (so another example would be rdisk1s2 = second HDD, 2nd partition)

Where:- rdisk0 = First HDD, rdisk1 = Second HDD etc.
and s1 = First partition, s2 = Second partition etc.


save the file.

Reboot, and after the 'Start' sound, hold down the 'Option' key (aka - Alt) and select one of the EFI partitions... if you selected the correct one... Voila... the OSX installer will start.
If you selected the wrong one, you will get a 'No Entry' logo displayed, just reboot, and select the other EFI partition.

Now you can either install OSX, or use the Mac OSX Disk Utility and your .dmg file, to create a bootable installation DVD, USB pendrive, USB Hard Drive etc.

Have fun :)

If you wondered why you needed the second 30gb partition... probably because the installer NEEDS to see another HFS+ partition... deleting the Linux partition with a gparted LiveCD and creating an HFS+ one in its place would probably work (but the rdiskXsY string would need adjusting)... but if you don't create one you WILL get a mach_kernel panic when you boot to the 8gb partition... you CAN install to this partition though, or install over the Linux partition.

I can't condone the use of this 'How To' for installing OSX on a hackintosh. ;)

.
« Last Edit: December 30, 2012, 02:16:06 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline koef

  • Jr. Member
  • **
  • Posts: 1
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
Reboot, and after the 'Start' sound, hold down the 'Option' key (aka - Alt) and select one of the EFI partitions... if you selected the correct one... Voila... the OSX installer will start.

So, you did this on Apple hardware running Ubuntu Linux?

Quote
I can't condone the use of this 'How To' for installing OSX on a hackintosh. ;)

Why not ;) Using easyEFI pre-bootcd I got to the OSX installer running from the 8GB partition on an "msdos" style partioned disk, but of course the OSX installer insists on GPT style partioning and offers Disk Utility to relabel, but that would destroy the 8GB partition holding the installation files. With parted it also possible to create GPT disklabels from within Linux, but in that case the mach kernel in the 8GB partition panics. So it seems three media would work: one easyEFI bootcd, one disk with the 8GB partition, and one disk to install OSX on, but I haven't tried that yet.

Thanks for your guide, really nice to play with all these *nix flavors on common hardware ;)

Online Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17126
  • Karma: 434
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Yes it was on an intel Mac that was running Ubuntu... the owner didn't have an OSX Installation DVD and I don't own a Mac so I couldn't burn the OSX image to disk, and at the time I had no access to an external hard drive.

I'd be interested to know if your solution works, though I can see no reason why it wouldn't... if you get round to trying it, can you let me know?

I'm glad the guide was of some use to you :)
« Last Edit: October 28, 2010, 01:13:01 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline patrickg1

  • Jr. Member
  • **
  • Posts: 1
  • Karma: 0
  • I've just joined!
    • View Profile
    • Awards
What an awesome and informative instructional! 

After many attempts to install OSX on my HP g-72 Laptop , I found your post to be the most logical approach.
I have completed all the steps except the last one: booting.
I know this post is for running on a MAC machine, but I'm close to giving up, just thought I'd see if anyone had an idea.

How To:  boot to the HFS+ partition, and install.  Boot CDs such as iBoot, Empire EFI recognize the HFS Partition, but do not work.

Thanks in advance.

Online Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17126
  • Karma: 434
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Glad it was of some use to you :)

I haven't tried to install it on non Mac hardware, I'm not really a fan of Apple or OS-X and prefer Linux, but there are a lot of sites that cover building and installing OS-X on a "hackintosh"...

Maybe someone there can help:
http://kakewalk.se/forum/
or
http://www.insanelymac.com/forum/
or
http://www.hackintosh.com/
or
http://www.insanelymac.com/forum/index.php?showtopic=195248
etc.

In particular it *might* be something to do with your DSDT (Differentiated System Description Table) as I *think* the OS-X DSDT looks for particular hardware or signatures (so won't work with other hardware)... see here:
http://kakewalk.se/forum/viewtopic.php?f=3&t=708&sid=57521e315c7a06dfdf1c6762740b4bb9&start=10
but you should be able to use Linux to extract your working (Linux) DSDT... decompile it... modify it... recompile it... then insert it into OS-X... but I've never done this so can't really help... I could also be totally wrong.

Good luck, and let us know how you get on.

Also check this:
http://www.insanelymac.com/forum/index.php?showtopic=232968

and Google HP G72 DSDT
« Last Edit: February 19, 2011, 02:48:25 pm by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal