|
| 1 | +# kexec-alpine |
| 2 | + |
| 3 | +`kexec` is a Linux **system call** that allows you to load and **boot another kernel** from the currently running one. |
| 4 | + |
| 5 | +In this guide we will see how to boot **Alpine Linux** with `kexec` from **Debian 13** (_trixie_). |
| 6 | + |
| 7 | +:warning: **Warning**: **do NOT try this on your main system**! Use a virtual machine or a disposable test system instead. Your system can become **unbootable** if something goes wrong. I am **NOT responsible** for any data loss, system breakage, or any other damage that may result from following this guide. |
| 8 | + |
| 9 | +Download the **Alpine Linux ISO file**. In my case I chose the `virt` flavor because I'm testing in a _VirtualBox_ VM. Then **mount** it: |
| 10 | + |
| 11 | +```bash |
| 12 | +sudo mkdir -v /mnt/myiso |
| 13 | +sudo mount -rv alpine-virt-3.22.1-x86_64.iso /mnt/myiso |
| 14 | +``` |
| 15 | + |
| 16 | +Copy the **`boot` and `apks` directories** from the ISO to a filesystem that will be **directly accessible** by the new kernel at boot time, i.e. that does not depend on LVM, encryption, or other userspace setup. |
| 17 | + |
| 18 | +In my case the root filesystem (`/`) is a plain `ext4` partition, so copying to `/` works fine for me, but your setup may be different. For example, if you use LVM for `/` and have a dedicated `/boot` partition, you could copy to `/boot` instead. |
| 19 | + |
| 20 | +```bash |
| 21 | +sudo cp /mnt/myiso/{boot,apks} -Rivt/ |
| 22 | +``` |
| 23 | + |
| 24 | +Make sure you have the `kexec` command available on your system: |
| 25 | + |
| 26 | +```bash |
| 27 | +sudo apt update && sudo apt install -y kexec-tools |
| 28 | +``` |
| 29 | + |
| 30 | +Then run the following: |
| 31 | + |
| 32 | +```bash |
| 33 | +sudo kexec -l /mnt/myiso/boot/vmlinuz-virt --initrd=/mnt/myiso/boot/initramfs-virt |
| 34 | + |
| 35 | +sudo systemctl kexec |
| 36 | +``` |
| 37 | + |
| 38 | +At this point, _Alpine Linux_ should start. |
| 39 | + |
| 40 | +Note that, if you want it **running completely from RAM** now, you should stop all the services that may use the disk, such as `modloop`: |
| 41 | + |
| 42 | +```bash |
| 43 | +rc-service modloop stop |
| 44 | +``` |
| 45 | + |
| 46 | +To check that no disk is used anymore, you can use the `mount` and `df -h` commands. |
| 47 | + |
| 48 | +At this point you can do whatever you want with the disks, such as installing another OS: |
| 49 | + |
| 50 | +> :warning: **Warning**: the following command overwrites EVERYTHING on `/dev/sda`! Unrecoverable **data loss** will occur. |
| 51 | +
|
| 52 | +```bash |
| 53 | +curl -fsSL https://cloud.debian.org/images/cloud/trixie/latest/debian-13-nocloud-amd64.raw | dd of=/dev/sda bs=1M status=progress oflag=direct |
| 54 | +``` |
| 55 | + |
| 56 | +> **Note**: the `curl` command and\or `dd`'s `status=progress` option might be unavailable by default on _Alpine Linux_. |
| 57 | +
|
| 58 | +## Links |
| 59 | + |
| 60 | +- [kexec(8) - kexec-tools - Debian trixie - Debian Manpages](https://manpages.debian.org/trixie/kexec-tools/kexec.8.en.html) |
0 commit comments