-
-
Notifications
You must be signed in to change notification settings - Fork 501
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
DietPi-PREP | Building using chroot #1775
Comments
Please, by all means. This is something i've been meaning to do for a long time, however, without a nudge in the right direction and flooded with other tasks, not been able to start it.
Yep, it is a nightmare, it would be much more beneficial if we could build/create the images via Qemu and chroot. |
Here you go http://github.com/pronvit/DietPi Procedure
Notes Basically I just commented out stuff that doesn't work inside chroot:
A big difference is that with chroot, any board-specific first boot procedures are not performed before running DietPi script. I only have a Tinker Board so could only test on it. Unfortunately, even with the original DietPi image I'm having issues with WiFi - it's not getting IP address most of the time, so I didn't test much after the first boot. Feel free to do whatever with the code as I guess my changes are not really suitable for a proper PR and merging. |
@pronvit @Fourdee I used qemu as VM on Windows Host, but found it to be extremely slow and didn't work to boot a DietPi image, as some manual fstab/cmdline.txt adjustments are needed and DietPi overwrites/readjusts them on 1st boot. I tried chroot then as well with a test system on USB stick, but for development the issue is, that you are not able to somehow "reboot" or re-initiate the system. For just running the preparation script it should work fine, indeed. How does the combination of qemu and chroot work now? Is it started as real VM then, instead of a "dead" image, where you chroot inside? On the other hand, then /proc /sys /dev etc should be present. Hardware info
Swapfile
fstab
After all, I guess it is still the safest way to create images directly on the machines. With some SD cards it is also not too much more effort. Flash/install pre-image and running preparation script must be done anyway once, or what do you mean by nightmare @Fourdee ? Performance on slow boards I can think of? |
Why do you want to "reboot", "re-initiate" or somehow boot the system at all? |
Not necessarily for image creation, just mentioned it as I was looking for some testing/development solutions as well, where e.g. some installation/configuration steps need system reboot or sometimes you want to test reboot behaviour especially. But this requires a VM at least. For this reason I am interested in what role qemu plays here. |
For running commands inside chroot. Just look at my |
Many thanks for this 👍 I really appreciate it. I've got side-tracked with other tasks at the moment, however, once I can, i'll take an in-depth look into your commit and guide.
@MichaIng Yep, basically, and the time to read SD card to image, risk of SD card corruption during read, etc etc. |
Flagged for v6.9, so it doesn't get put to the bottom of pile. |
I had another look into this. And indeed we might want to give it a try. Just thought through a bid again. Understand Service starts (systemctl (re)start) can be easily replaced by executing the ExecStart directly, if required. All other hardware related steps should be or are already done one first boot of destination system anyway. Not sure if ARMv6/7/8 need different qemu binaries? |
Just tested with a Raspbian Lite image on VM:
Then I remembered that it should not work to emulate inside an emulation. So I tried on x86 notebook, but same.
|
Im running qemu emulation this way: First I Mount the .img,
Unmount the image and run QEMU with the noreboot flag.
I remount my .img, clean my Then Im ready for the next step. --- Qemu is slow cuz it support only one core. This is my QEMU cmds :
For debian X86_64:
|
@FredericGuilbault So you run QEMU as VM.
And no VT-x/AMD-V acceleration AFAIK. The idea above is to run QEMU not as VM but only use it to execute ARM binaries: Actually the final image should be anyway ALWAYS tested one time (at least) on a real machine, verifying first run setup + boot sequence runs without issues, checking the boot/journalctl log for any anormalities. As long as we do not create our images from scratch there are simply too much possibilities of changes/conflicting bootloader/kernel configurations, first run scripts that come from the base-image and stuff. Taken this, the fastest method would be indeed to use:
All these steps can be done within a single script. Then some can test the image on a real machine before it is released. |
Work for me ™ thisSbc=RPi-ARMv6
IMAGE=./work/$thisSbc/raspbian.img
ROOTFS="$(pwd)/work/$thisSbc/rootfs"
BOOTFS="$(pwd)/work/$thisSbc/rootfs/boot"
#mount partitions
kpartx -sa $IMAGE
mount /dev/mapper/loop0p2 $ROOTFS
mount /dev/mapper/loop0p1 $BOOTFS
# mount binds
mount --bind /dev $ROOTFS/dev/
mount --bind /sys $ROOTFS/sys/
mount --bind /proc $ROOTFS/proc/
mount --bind /dev/pts $ROOTFS/dev/pts
# ld.so.preload fix
sed -i 's/^/#/g' $ROOTFS/etc/ld.so.preload
# copy qemu binary
cp /usr/bin/qemu-arm-static $ROOTFS/usr/bin/
# This is where the magic append
chroot $ROOTFS /bin/bash << EOF
ls /home/
apt-get install -y feh
EOF
# revert ld.so.preload fix
sed -i 's/^#//g' $ROOTFS/etc/ld.so.preload
# unmount
umount $ROOTFS/dev/
umount $ROOTFS/sys/
umount $ROOTFS/proc/
umount $ROOTFS/dev/pts
umount $BOOTFS
umount $ROOTFS
kpartx -d $imgFile
exit It's obv broken if you try on DietPi due to the fact that the first run scripts haven't been run yet. |
Emulation, chroot and automation will never replace real world testing and they come with their load of new issues and limitations. The point for me is productivity and reproducibility. It's often just a way to document the steps needed to have something done. |
Jep that is indeed a large benefit! Having things documented and clear defined steps to reproduce. |
Hi, im adding this article to the knowlege base. It explain diff between http://logan.tw/posts/2017/01/21/introduction-to-qemu-debootstrap/ *note that pi-gen is using |
@FredericGuilbault
I will play around with this soon, first to create an x86_64 image, so basically replacing Debian mini.iso installer with debootstrap + schroot, and see if DietPi-PREP can then run as before, in case after installing systemd to the target system.
|
rsync is sometime/often faster then cp, that might justs be a performance concern. I wonder if BTRFS also leave holes or it's just an ext4 problem? I remember messing with this when ext4 was new(long time ago enh) and copying to a new partition was the prefered method at the time.
+1 I think it's not just about functionality but also performance and SDcard wear. ...And FOSS |
Possibly, could run some tests on next image creation. However for me at least it doesn't matter if it takes 1 or 1.5 minutes, I think it was even much faster since only ~650M data...
The file system type would be bad if it would not leave holes. I mean to reduce disk writes it totally makes sense to not move all data around all the time only to close holes. Usually you do not care where data is stored physically. Of course new data should usually be written into the holes first, but I think this is done on ext4 as well. The issue is that DietPi-PREP removes much more data than it adds, so holes are just expected. It would be just nice to have a tool that explicitly moves all data physically to the partition/disk start. BTRFS is nothing that makes sense too soon, I think, there are simply too much boards with old kernel versions. E.g. I think swapfiles on BRTFS just became possible with kernel 4.18 or something.
I just remember (will verify before attempting the first debootstrap RPi image) that RPi cannot boot from ext4 actually, so the FAT boot partition is required anyway 😅. You mean performance and SDcard wear will benefit from a single ext4 partition? Only bootloader and kernel are there, read a single time on boot and never touched afterwards on usual operation. So I guess there is no measurable impact of having a separate /boot partition. https://sourceforge.net/projects/ext2fsd/ no dev since 2 years, many open bug reports in relation with Windows 10. Seems to be still not safe to use for writing to an ext4 partition. I guess Windows Subsystem for Linux (WSL) is capable of doing this safely, but it is only available on Windows 10 Pro edition and upwards (AFAIK?). And of course it is quite an overhead of installing it just to edit a single text file... |
From what I have read on armbian forum BRTFS cause less internal less read and write then ext4 but I did not validate this info, take it as a rhumor. I would vouch for having /boot partition in FAT32 for all SBC (even if it's not needed in some case like VirtualBox) it's a question of conviency and standardisation across OS and a tradition when it come about booting on SDcard/USB. I also agree that 99% of W$ users won't install an outdated driver for editing a single file. This would be a suicide move in term of adoption of Dietpi. Im working slowly on this but im working on a script to build lysmarine on top of dietpi. Wich is quite similar to building Dietpi in top other OS ( + lysmarine include compiling C++ projects and some nodejs library not available for armV6 ) IK it's not anyone priority ATM but I would totally agree Make it a common ground for both project. I kinda just need a repo to push to and some feedpack from DietPi people to make sure it stay in the common ground and you guys/girls will be happy to use it. ("A repo to push to" as I think the build tool should be seperated form the build content ) |
Perhaps we could create some testing images based on BTRFS for systems which offer a current enough kernel (with latest BTRFS support improvements, e.g. swap files). I have to check again the kernel changelogs where I found this.
I was thinking the same. However this is sadly not possible that easy, as in many cases the kernel, bootloader and dtoverlay packages either rely on symlinks and/or POSIX permissions, which is both not supported on FAT. We would require custom packages and e.g. initramfs hooks to work around this, which is currently impossible due to lack of man power and experience.
I hope that I find time soon to start with some build from scratch attempts, based on debootstrap and (s)chroot. That would be a much more transparent and cleaner solution. |
I have check about schroot and I Don't think it ca do well for distribution purpus as it rely on configuration files located in the /etc/ of the host system. And I found it intrusive. I ended up using proot. |
@FredericGuilbault |
Tried to fiddle around with qemu system emulation to get the RPi image booting on my Windows machine. No success with "native" methods, so using the kernel and dtb files from the image and any combination of machine, CPU and image/drive invocation that is usually mentioned on online guides. Interesting is that the "raspi2" machine is never mentioned, seems to not work at all, what is it for then? There is a "raspi3" machine available as well, but aarch64 only, so cannot boot Raspbian, and no network support. It seems that booting any Raspbian requires a special kernel file, most likely a dtb file as well. Those I could find in various guides, are totally outdated, not matching the current Raspbian images. I am a bid disappointed that, if there are already "raspi" machines available, that those are not able to boot an image right the same way an RPi would do, so using the contained bootloader to then load kernel, dtb files etc right from the image. But perhaps that is not even possible, not sure about the borders or qemu hardware emulation in general. IMO there is not much point (for our image creation process) in using ARM emulation, if one needs to use an external custom kernel and dtb (and in some cases even initrd), that do not match the ones from the image you want to create, CPU that does not match the one form the actual SBC, RAM size as well (in case of So
|
Finally Currently running large APT updates, mounting and some other tasks inside an DietPi RPi image. Works very well, only minor adjustments need to be done, e.g. Very nice for cross-compiling as well, which was the initial reason to go on with this topic. Ah now I found https://wiki.debian.org/RaspberryPi/qemu-user-static which mentions the ld.so.preload issue as well 😄. Since
|
Hi, I think i might have some time in the next 2 weeks to work on dietpi. The thing I would like to do is having a way to avoid using ramfs in qemu. This would allow me to use dietpi software and partition stretching tool in on my build script.
--Fred |
@FredericGuilbault I just created the first RPi image on VirtualBox VM via Here the script I'm having so far:
Will create some more images the next days, add env vars for DietPi-Imager to completely automate it, so that all steps from pre-image til archive upload are one automated script call with variables. However back to your initial idea, if I understood it correctly:
|
DietPi-RAMdisk is what I meant. If the chroot env can handle the mounts and syncs. There is no much need for my feature in reality. I would push this on some wishlist far away On lysmarine Im using : https://github.com/lysmarine/lysmarine_gen/blob/0.9.x/buildscript/rpi_build.sh caching at every step and reusing them is a huge time saver on repetitive compilation, Have you been able to make nodejs work in the chroot env ? |
Normal chroot needs much tinkering to allow mounts and even systemctl use, AFAIK, but
Makes sense, however for DietPi itself it is minimal, since it's 2.6M only. I wished GitHub would allow to download the archive as bz2 or even 7z/xz 🤔.
I did not try Node.js, will keep it in mind for next session. |
Oh I didin't know about systemd-nspawn. Seem like a nice tool. This is just a feeling but as is not a real environement booting seem like a receipt for overheads problems for something that is mainly just file manipulation. in all case it worth exploring. I will check if it's possible to make DietPi-RAMdisk mount in chroot. |
Yeah it depends on what you want to of course. In case of our image building, IMO it makes sense, since we want to have all installers and systemctl behave as it was a real system, as close as possible, to trigger possible issues in the first place before doing real machine tests. As well simple things like having APT installs enabling and starting services do not work in simple chroot, so the end result would be simply different. For our own services of course we could place the required symlinks and trigger the ExecStart commands manually, but APT AFAIK cannot do this, thus steps are missing or installs can even fail. Same for /dev /proc /sys access. which of course can be manually mounted into chroot, but systemd-nspawn automates this and handles/limits access reasonably. It is not yet everything perfect, e.g. I am still dealing with the issue that it can see its own loop mounts, but not their UUID or PARTUUID, which leads to missing /boot and / mounts in fstab after DietPi-PREP. |
I made a quick test and DietPi-RAM disk mount in chroot. |
Nearly all new images have been created via And I mark this issue as closed. I'll create a wrapper build script which:
So this is then something that can be done on any systemd-capable OS, basically 🙂. However this is something I gonna start with after v6.29 release. |
I'm now using DietPi scripts for my needs (building a minimal image booting to miRack) and I'm doing it in chroot environment. Qemu (you mentioned you don't have experience with it) isn't an issue here as you specify it only once to chroot into a mounted original OS image and then you don't even notice it (apart from being a VM, qemu can just transparently run binaries for other platforms).
I think apart from removing stuff I don't need, the only major thing I had to fix is that since you can't start services in chroot environment, mounting tmpfs on /DietPi needs to be done differently (I don't need it so I just removed all that).
If you're interested, I can provide more details how to set it up - creating images on real boards seems to be an overkill to me.
The text was updated successfully, but these errors were encountered: