Created
March 25, 2022 05:43
-
-
Save versusvoid/5ec344f1f9e9e47c1fa713159a693cc2 to your computer and use it in GitHub Desktop.
Quck and dirty qemu linux image from linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# initially empty image with 8GiB max size | |
truncate -s 8GiB sda.img | |
# make dos (mbr) table with one partition | |
cfdisk sda.img | |
# mount image as loopback | |
DEV=$(sudo losetup --find --show --partscan sda.img) | |
# make root fs | |
sudo mkfs.ext4 ${DEV}p1 | |
# mount it | |
sudo mount ${DEV}p1 /mnt | |
# bootstrap | |
sudo debootstrap --include=linux-image-amd64,grub2 --components=main,universe stable /mnt | |
# install-configure loader | |
sudo systemd-nspawn -D /mnt --bind=$DEV --bind=${DEV}p1 bash -c 'grub-install | |
--target=i386-pc $DEV && grub-mkconfig -o /boot/grub/grub.cfg' | |
# fix root partition | |
sudo sed s/loop.p1/sda1/g -i /mnt/boot/grub/grub.cfg | |
# reset root password | |
sudo sed 's/root:[^:]\+/root:/g' -i /mnt/etc/shadow | |
# unmount | |
sudo umount /mnt | |
sudo losetup -d $DEV |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment