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

Add QCOW2 build mechanism #349

Merged
merged 22 commits into from Feb 10, 2021
Merged

Add QCOW2 build mechanism #349

merged 22 commits into from Feb 10, 2021

Conversation

pandel
Copy link
Contributor

@pandel pandel commented Nov 18, 2019

What's this?
This PR integrates a build variant utilizing qcow2 based images. It is mainly focused on reducing build time and space. Some additional changes have been made to the export stages for this as well, but are only activated if you use the qcow2 mechanism.

How does it work?
This mechanism replaces the copy_previous style build by creating a base qcow2 image in WORK_DIR at the beginning of the first stage and adding additional so called backing images stage by stage on top of it. These backing images record only the changes of the stage they belong to. That leads to reduced space consumption and faster stage creation times. Only the two export stages (image and noobs) are created "the old fashioned" way, because it would need a more in depth rework of both export stages to use qcow2 for them as well. I think that this is not really necessary. Qow2-based export-image stage has been added with with 4ea3675, see my comment below.

I dont' like it! How to deactivate?
In this PR, qcow2 based building is activated by default. If you want to activate the normal build variant, set USE_QCOW2=0 inside your config file.

Further information
You will find further descriptions inside the updated README.md as well.

I developed and tested it under Kubuntu 18.04.03 LTS, with and without Docker and it works for me (not taking the current qemu/i386 problem into account, as this is all about image building).

@XECDesign
Copy link
Member

Looks alright at a glance, thanks. It might be a while before I can go through it properly.

@pandel
Copy link
Contributor Author

pandel commented Nov 18, 2019

Looks alright at a glance, thanks. It might be a while before I can go through it properly.

Thanks! Take your time!

pandel and others added 7 commits November 19, 2019 00:56
Merge upstream into qcow2
Force fs sync on umount and reverse kpartx/qemu-nbd unloading
Remove info regarding manual NBD_DEV setting. Not possible anymore.
@pandel
Copy link
Contributor Author

pandel commented Dec 2, 2019

Sorry for the additional commits. I try to stay up to date with the main repo while adding some features and make the whole patch more robust...

Commit 4ea3675 is the biggest so far, because I thought about the export stages again. As you know, when I opened this pull request I thought it wouldn't make any big difference to change the export stages.

But I found out that if I would create the base qcow2 image with the 2-partition layout (vfat/ext4) right from the beginning, I could use simple calls to qemu-img rebase, qemu-img commit and qemu-img convert to build an export image only with the additional amount of space the first stage needs. As a side effect, image building runs even faster with it, too.

@pandel
Copy link
Contributor Author

pandel commented Dec 4, 2019

For anyone who is wondering about the many syncs: I am running the whole thing from within a Ubuntu 18.04 VM under VMware Workstation on a laptop and on a DebianARM64 VM under Proxmox, respectively. Both systems can get under a heavy load and if the overall load gets too high, the image operations inside the VM fail from time to time. Sync makes it work...

@pandel
Copy link
Contributor Author

pandel commented Feb 4, 2020

Rework upstream merge to stay up-to-date.

@bbinet
Copy link
Contributor

bbinet commented Apr 23, 2020

This seems a useful addition to improve speed and space!

Any chance to see it merged in upstream repository?

@pandel
Copy link
Contributor Author

pandel commented Apr 23, 2020

As I am using this in all my derived pi-gen projects and never went back to traditional build mechanism, as it simply is too slow and uses too much space, I can assure you that this speeds up things like hell :-) - I don't understand why there is so little to no reaction but who knows...

I tried to keep up with the main repo the last months, resolve conflicts and stuff, but for now, from my side, I will not fix the mentioned conflicts at the moment, as they are simply of no interest to me.

@bbinet
Copy link
Contributor

bbinet commented Apr 24, 2020

@XECDesign Any chance this can get merged soon?

@XECDesign
Copy link
Member

Yeah, it's a worthwhile change, but I can't spend time checking it. Given that there's now verification that it works from another user, I am a bit more comfortable with accepting it as is.

@pandel
Copy link
Contributor Author

pandel commented Apr 24, 2020

If I find time the next days I can add the last changes from master branch to my branch to resolve the conflicts if you wish...

@XECDesign
Copy link
Member

That would be much appreciated.

@koenvervloesem
Copy link

I'm currently using pi-gen to build a custom image and the build needs half an hour on GitLab CI. I'm definitely interested in testing this PR if the conflicts have been resolved. That will give you some extra verification, @XECDesign.

@pandel How much of a speedup can I expect from a half-hour build in the traditional way?

@pandel
Copy link
Contributor Author

pandel commented Apr 24, 2020

@koenvervloesem I simply can't say. It really depends on the underlying hw or vm you are using, cached debs or not, network speed, whatnot. If you have a very fast hdd, then it might not be that much, because the file copying mechanism in the "old" way is fast enough. For me, creating a base qemu and then only derived ones for every next step is much faster.

EDIT:
I never used Gitlab CI, so I absolutely don't know its dependencies and if this will work, just for the record ;-)

@XECDesign
Copy link
Member

Image size looks okay, but alignment doesn't seem right - 4 sectors rather than 4MiB.

@XECDesign
Copy link
Member

XECDesign commented May 5, 2020

Partition id should be 0c, not 0b. Not sure if it makes a difference, but I remember having obscure issues in some cases, so I'd like to keep changes to a minimum.

@pandel
Copy link
Contributor Author

pandel commented May 6, 2020

Many thanks! I look into it as soon as possible. The change should alteady have corrected alignment but I will find the reason why it didn‘t!

@pandel
Copy link
Contributor Author

pandel commented May 12, 2020

Sorry, sorry, sorry! No time for nothing...

Alignment and partition type should be correct now. I also added the bootable flag to the FAT partition, just in case.

Please re-test a last time, hopefully...

@ghost
Copy link

ghost commented May 13, 2020

I also added the bootable flag to the FAT partition, just in case.

The bootable flag is ignored on the Raspberry Pi.

@pandel
Copy link
Contributor Author

pandel commented May 13, 2020

I also added the bootable flag to the FAT partition, just in case.

The bootable flag is ignored on the Raspberry Pi.

As I said, just in case ;-) - and it doesn't hurt anyway.

@pandel
Copy link
Contributor Author

pandel commented May 26, 2020

@XECDesign My last tests are working fine. Any recommendations? Is the partition layout now right for you?

@pandel
Copy link
Contributor Author

pandel commented Dec 24, 2020

@XECDesign Any news regarding this PR? Does it work for you?

@XECDesign
Copy link
Member

Thank you for keeping this up to date and sorry about delaying this again. One more bug release image release and then I'll circle around to PRs again.

@XECDesign XECDesign merged commit bf8c9f5 into RPi-Distro:master Feb 10, 2021
@XECDesign
Copy link
Member

I'll just merge this now to avoid further delays and address any issues with it if they come up.

Thanks

mmmspatz added a commit to mmmspatz/pi-gen that referenced this pull request Apr 7, 2021
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Feb 28, 2022
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Mar 1, 2022
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Mar 1, 2022
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Mar 4, 2022
mmmspatz added a commit to mmmspatz/pi-gen that referenced this pull request Mar 8, 2022
scuciurean pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Mar 23, 2022
mmmspatz added a commit to mmmspatz/pi-gen that referenced this pull request Apr 12, 2022
mmmspatz added a commit to mmmspatz/pi-gen that referenced this pull request May 8, 2022
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request Sep 16, 2022
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request May 30, 2023
SRaus pushed a commit to analogdevicesinc/adi-kuiper-gen that referenced this pull request May 30, 2023
wandering-andy pushed a commit to wandering-andy/pi-gen that referenced this pull request Oct 15, 2023
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.

None yet

4 participants