Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for installing macOS like AutoDMG #82

Merged
merged 11 commits into from
Nov 16, 2017

Conversation

jonanh
Copy link
Contributor

@jonanh jonanh commented May 14, 2017

I am one of those unlucky guys who have unfortunately discovered this project too late after Apple released Sierra 10.12.4 :-(

I am using it for prototyping my personal projects, and the price of WMware + vagrant wmware plugin made me drop the alternative WMware + AutoDMG + vfuse for now, so I took a look to how AutoDMG worked and I created a modified version of your prepare_iso.sh which uses installer -verboseR -dumplog -pkg "$MNT_ESD/Packages/OSInstall.mpkg" -target "$MNT_BASE_SYSTEM" to install macOS in a disk image that gets converted into a virtual box image by doing cat "$DISK_DEV" | VBoxManage convertfromraw stdin "$OUTPUT_DMG" "$DISK_SIZE_BYTES".

I also created a small tool to generate and export a OVF which can be used by the packer builder virtualbox-ovf. :-)

$ mkdir -p out; cd out;
$ sudo ../prepare_iso/prepare_vdi.sh -D DISABLE_REMOTE_MANAGEMENT /Applications/Install\ macOS\ Sierra.app/ .
$ ../prepare_iso/prepare_ovf.sh macOS_10.12.4_16E195.vdi
$ packer build -var provisioning_delay=30 -var source_path=macOS_10.12.4_16E195.ovf ../packer/template.json

@petemounce
Copy link
Contributor

I'd like to try this out but don't understand how to. Would it be possible to include a diff to the README.md to describe where it slots in? Thanks!

@jonanh
Copy link
Contributor Author

jonanh commented May 16, 2017

Sure. I will also try it with 10.12.5 as well :-)

@jonanh
Copy link
Contributor Author

jonanh commented May 16, 2017

BTW, if you want I can try as well simplifying the commands and make it a way that all the scripts can be launched in a sequence without having to know the output names.

@jonanh
Copy link
Contributor Author

jonanh commented May 16, 2017

I will add the following command to the README.

cd packer
sudo ../prepare_iso/prepare_vdi.sh \
  -D DISABLE_REMOTE_MANAGEMENT \
  -o macOS_10.12.vdi \
   /Applications/Install\ macOS\ Sierra.app/ \
  . && \
../prepare_iso/prepare_ovf.sh \
  macOS_10.12.vdi && \
packer build \
  -var provisioning_delay=30 \
  -var source_path="macOS_10.12.ovf" \
  template.json

@jonanh
Copy link
Contributor Author

jonanh commented May 17, 2017

BTW, it worked with 10.12.5 :-)

@timsutton
Copy link
Owner

Thanks a lot for putting in the time to work on this! Busy with some other things this week but I hope to have more time next week to look at how this can fit in.

The main disadvantage I see to using the OS install here is that it imposes the requirement to build the same major OS version for the VM as what's running on the host. https://github.com/chilcote/vfuse is also a related project that is kind of a combination of what you're talking about (typically using AutoDMG's output as its input) and what this project aims to achieve in terms of the Packer templates.

@lordmuffin
Copy link

This works awesome, had to use it to get 10.12.5 working. Should really incorporate this fork.

@timsutton
Copy link
Owner

Thanks all for the feedback and to @jonanh for providing all the extra documentation! I do intend to incorporate this contribution as soon as I'm able to make the time to give it a quick review.

fi

msg_status "Mounting BaseSystem.."
BASE_SYSTEM_DMG="$MNT_ESD/BaseSystem.dmg"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In High Sierra BaseSystem.dmg is not inside the InstallESD.dmg, it is in the same directory, in Installer.app/Contents/SharedSupport/BaseSystem.dmg. You could check for the existence of the file in both paths, then you would have compatibility with High Sierra as well.

render_template "$SUPPORT_DIR/user.plist" > "$SUPPORT_DIR/pkgroot/private/var/db/dslocal/nodes/Default/users/$USER.plist"
USER_GUID=$(/usr/libexec/PlistBuddy -c 'Print :generateduid:0' "$SUPPORT_DIR/user.plist")
# Generate a shadowhash from the supplied password
"$SUPPORT_DIR/generate_shadowhash" "$PASSWORD" > "$SUPPORT_DIR/pkgroot/private/var/db/shadow/hash/$USER_GUID"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this password is not correctly understood in High Sierra. System will boot, Vagrant user exists, but will never log in.

@jonanh
Copy link
Contributor Author

jonanh commented Sep 2, 2017

Thanks @jgimenez for the info! :-) I haven't tried it yet High Sierra. I will try to test it tomorrow.

@timsutton
Copy link
Owner

About the password, this is true - High Sierra no longer supports the legacy password hash format. A tool like https://github.com/gregneagle/pycreateuserpkg could be used to programmatically generate one which can be used from 10.8 and up.

@jonanh
Copy link
Contributor Author

jonanh commented Sep 7, 2017

I managed to get the prepare_vdi.sh generate an image. I fixed the new location of the BaseSystem.dmg, changed to APFS as the FS for the image and installed the os using the $INSTALLER_PATH/Contents/SharedSupport/InstallInfo.plist file instead of $MNT_ESD/Packages/OSInstall.mpkg package, but unfortunately the generated image doesn't boot for now. :-(

I will continue researching on it next week (I won't be able to work this weekend), but I have left the changes in a branch just in case someone wants to continue testing it.
jonanh#2

Once I get it working I will update the pull request. :-)

@jonanh
Copy link
Contributor Author

jonanh commented Sep 8, 2017

The problem seems to be that hdiutil is not creating an EFI partition anymore in High Sierra

$ hdiutil create -size "1g" -layout GPTSPUD -type SPARSE -fs "APFS" -volname "Macintosh HD" -uid 0 -gid 80 -mode 1775 test.sparseimage
$ hdiutil attach test.sparseimage -nomount
/dev/disk6          	GUID_partition_scheme          	
/dev/disk6s1        	Apple_APFS                     	
/dev/disk7          	EF57347C-0000-11AA-AA11-0030654	
/dev/disk7s1        	41504653-0000-11AA-AA11-0030654	/Volumes/Macintosh HD

@jgimenez
Copy link

jgimenez commented Sep 8, 2017 via email

@jonanh
Copy link
Contributor Author

jonanh commented Sep 8, 2017

Did you create the image from a High Sierra host? Do you mind checking how does look like the partitions of the generated image?

@jgimenez
Copy link

I created the image from a Sierra host. I unfortunately deleted everything, and now I upgraded to High Sierra, so I can't reproduce it, sorry...

@jonanh
Copy link
Contributor Author

jonanh commented Sep 27, 2017

Sorry for the delay, I have been quite busy lately :-(

In the end the problem was very simple, APFS is not supported by Virtualbox, and the EFI partition doesn't contain any boot loader like Linux does. I was assuming that the EFI BIOS wasn't able to read HFS+J partition (which turns out that they are), so I though that the installer was failing to copy something.

I updated the create_firstboot_pkg.sh script to use some of the modules used by Greg Neagle's pycreateuserpkg, and now it should work for High Sierra.

I also simplified the script a little bit, since HighSierra doesn't require the ESD to be mounted. But in the way of the simplification it stopped working with Sierra, so now I have to fix it again :D. I will make sure that it works in both and I will update the branch. :-)

@timsutton
Copy link
Owner

That's awesome @jonanh, thanks for the update. Would definitely like to incorporate your changes soon :)

… use InstallInfo.plist instead OSInstall.mpkg package
@jonanh jonanh force-pushed the create_prepare_vdi_based_on_autodmg branch from a2a90ab to d00d75e Compare September 30, 2017 14:54
@timsutton timsutton mentioned this pull request Sep 30, 2017
@timsutton
Copy link
Owner

Thank you @jonanh so much for 1) this contribution, the effort to make it DRY along with other scripts and files already in this repo, and the update for PBKDF2 in the password hash logic, and 2) your patience while this PR has sat idle. I finally had some time to run it through and while I didn't get to the point of actually using the results for further work with Virtualbox, everything seemed to work as expected.

Is there anything left that you wanted to do for this, or any attribution in the code that we need to cover for some of the files you added for the PBKDF2 hashing support?

@jonanh
Copy link
Contributor Author

jonanh commented Nov 8, 2017

Hey Tim, it has been a pleasure learning a little bit more about OSX and being able to contribute a small piece to your project! :-)

I borrowed those files from pycreateuserpkg, but though the copyright was cited in the headers of the files, now I am realising that neither pycreateuserpkg nor arc4random have a concrete license specified. I could contact the authors and ask them.

I have some improvements to the code that I wrote, but I can open a new PR afterwards. I think that I can improve the performance quite a lot by removing some exporting/reimporting steps. Though my priority wasn't the performance, since probably most of the users will create a new base box per major macOS version.

@timsutton
Copy link
Owner

Well, this clears up the one about pycreateuserpkg - we can attribute it licensed as Apache 2.0.

@timsutton
Copy link
Owner

I also just found that for a project, I wanted to source the create_firstboot_pkg from a script which was run via Packer directly, and which lived outside this repo. I added the following logic to it so that it would set SCRIPT_DIR differently if it had been sourced:

f0869e0

If you're good for me to merge this PR now I can just add this change back on top of master.

@timsutton timsutton merged commit 76dce81 into timsutton:master Nov 16, 2017
@jonanh
Copy link
Contributor Author

jonanh commented Nov 16, 2017

Sorry for the delay. Thanks for the review and merging! :-)

I wasn't contacted back from the author of arc4random.py about the licence, so I will try to port the BSD's arc4random this weekend.

@timsutton
Copy link
Owner

Oh, thanks! I'd forgotten about that one. I'll see about trying to fix up attributions meanwhile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants