4 ms·
Unfortunately it's not safe as the kernel can still write to (what it thinks is) the old filesystem on the device, which will introduce corruption to the new di
by rwmj 7mo ago
Unfortunately it's not safe as the kernel can still write to (what it thinks is) the old filesystem on the device, which will introduce corruption to the new disk image.
However a fun fact is that you can (do not actually do this!) boot a qemu VM from /dev/sda. You have to use an overlay (eg. qemu -drive snapshot=on flag) so that qemu won't write through to /dev/sda. I use this trick in supernested, a script I wrote that runs nested within nested within nested VMs ad infinitum until your hypervisor crashes. http://git.annexia.org/?p=supernested.git;a=blob;f=run-supernested.sh.in;h=ea227f0c62eddc0c6d2e394b938d1a920a48e794;hb=HEAD#l65 http://git.annexia.org/?p=supernested.git;a=blob;f=run-super...
- vidarh 7mo agoThe second part in the series deals with that by mounting it read-only from initrd.
- Joker_vD 7mo agoWhat if we remount the filesystem(s) at /dev/sda as read-only first? Then make a small ramfs with statically-linked curl in it and exec it. Hmm. Ideally, you'd also want to call reboot(2) after it's done...
- akdev1l 7mo agoin most cases you could just drop back into the initramfs that is included in most distros Or if you have access to the boot command line you can also usually stop the boot process before pivot_root happens (hence you’ll be left running in the initramfs environment) On Fedora/EL it would be done by putting `rd.break` in the kernel command line
- astralbijection 7mo agoAll of those things get covered in parts 2, 3, and 4 :)
- Joker_vD 7mo agoThere's... no part 2 in the post? And it's the latest blog post on the site, as far as I can see.
- astralbijection 7mo agoIt does get linked at the very bottom, though admittedly it could be made clearer. https://astrid.tech/2026/03/24/1/swap-out-the-root-before-boot/ https://astrid.tech/2026/03/24/1/swap-out-the-root-before-bo...
- Joker_vD 7mo agoOh, I see, the posts got published in the reversed order. On the topic itself: wow, what a journey. And I personally fully support "come on, you should totally be able to just dump the system image onto your disk and reboot/exec it!"
- tremon 7mo agoYou also don't want to do this under any kind of memory pressure, because the kernel will happily drop read-only pages from memory if it thinks they can be re-read from disk when needed.
- duskwuff 7mo agoOne bit of magic you may be interested in is pivot_root, which allows another filesystem to take the place of the root filesystem (e.g. / and /mnt become /old and /). It's usually used during startup, to allow the "real" root filesystem to take the place of the initrd, but could have other uses.
- Dylan16807 7mo agoLast time I tried to use it though I just could not get it to let go of the main filesystem even after repeatedly killing the processes I could and restarting the rest. Taking control at the initrd stage, as in the second page of the article, is significantly more reliable. But have busybox in your initrd so you don't have to suffer. It takes up 0.5% of the size of my initrd file.
- ciupicri 7mo agoCould xfs_freeze help with this? [0]: https://www.man7.org/linux/man-pages/man8/xfs_freeze.8.html https://www.man7.org/linux/man-pages/man8/xfs_freeze.8.html
- astralbijection 7mo agoThat script sounds extremely unhinged, and I mean it as a compliment :) Without spoiling too much, the command at the very end of the series does something adjacent to this.
- tux3 7mo agoI used to dual-boot windows, but I was too lazy to actually reboot, so naturally I had Virtualbox just boot the physical Windows partition while Linux was running. Which is totally fine! It's not a real dual boot if you don't boot both partitions at the same time. As long as you don't install guest VBox drivers, those would make it hang when it boots as the host on physical hardware, since there's no longer someone above to answer the hypercalls.
- johnisgood 7mo agoYeah. That is a valid use. I mean, this is how I installed Windows to begin with, from Linux via QEMU, onto my other hard drive. I did reboot and test it out, and it worked just fine.
- ahartmetz 7mo agoI think Windows refused to do that at some point? So I booted the physical Linux partition from Windows if I needed both at the same time. That's on a laptop that otherwise almost always ran Linux.
- tiberious726 7mo agoIt whines about licensing, but I switch between booting my windows installation bare metal and as a VM all the time
- hdb2 7mo ago> I had Virtualbox just boot the physical Windows partition while Linux was running. Which is totally fine! I had no idea that this was possible, and I learned something new today. Thank you!
- kyrjtejkrtys 7mo agodepending on the size of your disk image and your uefi+boot partitions it's still possible to safely pull off. unmount the efi and boot partitions, write your image to the head of the disk, power cycle, then grow the last filesystem from the image to cover the rest of the disk. you might get lucky and have all three of uefi/boot/swap to work with. of course with the advent of uefi, you could instead just drop an installer image directly into the efi parition and boot that.