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: add compressed option to compress qcow2 images #31535

Merged
merged 3 commits into from Nov 13, 2017

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Nov 11, 2017

Motivation for this change

Compressed images take less space (about 3 times less), are faster to upload and to download to provision new instances. I'm interested in using this with qemu and OpenStack. I'm not going to test if compressed images are supported by Amazon or other cloud providers.

The commits are easier to review separately.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
    • nixos/tests/ec2.nix
    • nixos/tests/ec2.nix with compressed defaulted to true
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@orivej orivej requested a review from dezgeg November 11, 2017 19:58
@orivej orivej changed the title make-disk-iamge: add compressed option to compress qcow2 images make-disk-image: add compressed option to compress qcow2 images Nov 11, 2017
@orivej
Copy link
Contributor Author

orivej commented Nov 12, 2017

I thought that /nix/store on disk images is compressed in SquashFS. How come disk image compression gets size down by two thirds? Impressive, anyway.

You probably think about installation media images (.iso). Virtual machine images (.qcow2, .ami) are meant to be mutable, this is why they contain uncompressed /nix/store.

(In fact virtualization software often keeps the original image unmodified by storing writes performed by the guest operating system in a separate file, while all that a guest sees is a single writable disk. In this case it is perfect to keep the read only disk in the form that is compressed and supports fast random read access, and qcow2 compression provides exactly this.)

@lukateras
Copy link
Member

lukateras commented Nov 12, 2017

Sure, I've noticed that which is why I've deleted the comment. Didn't know about storing writes separately, interesting, makes sense to deduplicate this given instances are meant to be ephemeral and usually don't get heavy updates.

I'm not going to test if compressed images are supported by Amazon or other cloud providers.

At least Amazon doesn't support qcow2 at all: their import tool supports raw and vpc, though.

Copy link
Member

@copumpkin copumpkin left a comment

Choose a reason for hiding this comment

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

Apart from the enum shape, this looks great, thanks! I'm not necessarily treating it as a blocker but would prefer to have the 4-element enum to the boolean.

@@ -45,7 +49,9 @@ let
raw = "img";
};

nixpkgs = lib.cleanSource pkgs.path;
compress = optionalString compressed (assert format == "qcow2"; "-c");
Copy link
Member

Choose a reason for hiding this comment

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

Rather than putting an assert here, maybe we could just make format be one of vpc, qcow2, qcow2-compressed, and raw? From a types perspective it feels cleaner to have a 4-element enum than a boolean paired with a 3-element enum where 2 of the choices are invalid.

Copy link
Contributor Author

@orivej orivej Nov 12, 2017

Choose a reason for hiding this comment

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

This makes the naming difficult: we shouldn't rename format parameter as it is a part of the API, and there is no better name for the actual format as understood by qemu-img. Is this better: 27f5cc9?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative solution is to rename compressed into qcow2-compressed:

-  compress = optionalString compressed (assert format == "qcow2"; "-c");
+  compress = optionalString (format == "qcow2" && qcow2-compressed) "-c";

(This facilitates making qcow2 be compressed by default, although I'm not sure if that is useful.)

Copy link
Member

Choose a reason for hiding this comment

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

I quite like the qcow2-compressed version myself. Thanks!

@copumpkin copumpkin merged commit 6f13844 into NixOS:master Nov 13, 2017
@orivej orivej deleted the compress-qcow2 branch November 13, 2017 00:38
@vcunat
Copy link
Member

vcunat commented Nov 13, 2017

This is probably what broke tests on Hydra. Try nix-build nixos/release-combined.nix -A nixos.tests.ec2-nixops --dry-run --show-trace.

@orivej
Copy link
Contributor Author

orivej commented Nov 13, 2017

Sorry for not testing the final version thoroughly enough. Fixed in 470a775.

@vcunat
Copy link
Member

vcunat commented Nov 13, 2017

Now Hydra's repeatedly getting too many heap sections again, but that could be just bad luck...

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

5 participants