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

make-disk-image: Support creating EFI images #32618

Merged
merged 1 commit into from Jan 22, 2018

Conversation

dezgeg
Copy link
Contributor

@dezgeg dezgeg commented Dec 12, 2017

This adds EFI support to make-disk-image. That is, for imageType == "efi" the image gets a GPT partition table instead of the usual DOS partition table, and a FAT32 ESP partition is created in addition to the root partition.

With a bunch of butchering of amazon-image.nix in master...dezgeg:aarch64-makediskimage I end up with a booting AArch64 image (using EFI GRUB) that can boot in QEMU. Still need to clean up & split those into it's own files but these changes should be ready for review now.

@copumpkin

@copumpkin
Copy link
Member

Very cool! Main nitpick is that I'd be inclined to just have a three-valued option for a parameter called partition-scheme, maybe with none, legacy, or gpt/efi. That way we don't have to maintain asserts for nonsensical combinations of parameters.

A little sad about the mkfs going into the VM but oh well 😄 maybe I'll someday submit a patch for that.

@dezgeg
Copy link
Contributor Author

dezgeg commented Dec 12, 2017

Very cool! Main nitpick is that I'd be inclined to just have a three-valued option for a parameter called partition-scheme, maybe with none, legacy, or gpt/efi. That way we don't have to maintain asserts for nonsensical combinations of parameters.

Sounds like a good idea. I will implement that.

A little sad about the mkfs going into the VM but oh well  maybe I'll someday submit a patch for that.

In theory you can do tricks like https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/cd-dvd/sd-image.nix#L99 but in the case of KVM actually being available that ends up being a net loss since it requires dd'ing hundreds of megabytes of mostly zeroes.

@dezgeg dezgeg mentioned this pull request Jan 11, 2018
5 tasks
@dezgeg
Copy link
Contributor Author

dezgeg commented Jan 14, 2018

Finally updated to the three-value enum. Need to do some testing that I didn't break something else.

Edit: At least the latest variant can build the OVA & EC2 image.

- Add a new parameter `imageType` that can specify either "efi" or
  "legacy" (the default which should see no change in behaviour by
  this patch).

- EFI images get a GPT partition table (instead of msdos) with a
  mandatory ESP partition (so we add an assert that `partitioned`
  is true).

- Use the partx tool from util-linux to determine exact start + size
  of the root partition. This is required because GPT stores a secondary
  partition table at the end of the disk, so we can't just have
  mkfs.ext4 create the filesystem until the end of the disk.

- (Unrelated to any EFI changes) Since we're depending on the
  `-E offset=X` option to mkfs which is only supported by e2fsprogs,
  disallow any attempts of creating partitioned disk images where
  the root filesystem is not ext4.
@dezgeg
Copy link
Contributor Author

dezgeg commented Jan 17, 2018

@copumpkin how does this look now?

@dezgeg dezgeg merged commit 962e79e into NixOS:master Jan 22, 2018
@copumpkin
Copy link
Member

Looks good, sorry for the delayed response!

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

Successfully merging this pull request may close these issues.

None yet

3 participants