diff options
| author | namilsk <namilsk@namilsk.tech> | 2026-01-12 15:52:46 +0300 |
|---|---|---|
| committer | namilsk <namilsk@namilsk.tech> | 2026-01-12 15:55:11 +0300 |
| commit | 781f014eb86f7e7dc05e660d427d54eabde3d2c0 (patch) | |
| tree | 838364368d72703a735c3beae23d1f2d50ba9d1a /vmtest/test.sh | |
| parent | f891020ddf6b9c2137cc29c023dbdab4a4b46669 (diff) | |
Added test script
Diffstat (limited to 'vmtest/test.sh')
| -rwxr-xr-x | vmtest/test.sh | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/vmtest/test.sh b/vmtest/test.sh new file mode 100755 index 0000000..33f1755 --- /dev/null +++ b/vmtest/test.sh @@ -0,0 +1,102 @@ +#!/bin/sh +set -e + +IMAGE_NAME="anthrill.iso" +ROOTFS_DIR="alpine-rootfs" +MNT_DIR="mnt" + +# nix-shell vmtest.nix + +if [ ! -f alpine-make-rootfs ]; then + wget https://raw.githubusercontent.com/alpinelinux/alpine-make-rootfs/v0.8.1/alpline-make-rootfs \ + && echo '2b21327244d2d63082dd4780e22549221e298206 alpine-make-rootfs' | sha1sum -c \ + || exit 1 + chmod +x alpine-make-rootfs +fi + + +./alpine-make-rootfs \ + --branch v3.22 \ + --packages 'linux-lts linux-firmware grub efibootmgr mkinitfs e2fsprogs dosfstools bash' \ + --timezone 'Europe/Moscow' \ + "$ROOTFS_DIR" + +rm -f "$ROOTFS_DIR/sbin/init" +install -Dm755 ../target/release/x86_64-linux-musl/init "$ROOTFS_DIR/sbin/init" + +cat > "$ROOTFS_DIR/etc/fstab" <<EOF +# <file system> <mount point> <type> <options> <dump> <pass> +/dev/sda2 / ext4 defaults 0 1 +/dev/sda1 /boot/efi vfat umask=0077 0 2 +EOF + + +KERNEL_VERSION=$(ls "$ROOTFS_DIR/lib/modules/" | grep -E '^[0-9]+\.' | head -n1) +if [ -z "$KERNEL_VERSION" ]; then + echo "Err: couldnt find kernel dir in $ROOTFS_DIR/lib/modules/" + exit 1 +fi + +mkdir -p "$MNT_DIR/root" "$MNT_DIR/boot" + +dd if=/dev/zero of="$IMAGE_NAME" bs=1M count=512 +sfdisk "$IMAGE_NAME" <<EOF +label: gpt +device: $IMAGE_NAME +unit: sectors + +start=2048, size=204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, name="EFI System Partition" +start=206848, size=, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, name="Linux filesystem" +EOF + +LOOP_DEV=$(sudo losetup --find --show --partscan "$IMAGE_NAME") +BOOT_PART="${LOOP_DEV}p1" +ROOT_PART="${LOOP_DEV}p2" + + +mkfs.vfat -F 32 "$BOOT_PART" +mkfs.ext4 "$ROOT_PART" + + +mount "$ROOT_PART" "$MNT_DIR/root" +mount "$BOOT_PART" "$MNT_DIR/boot" +cp -a "$ROOTFS_DIR"/* "$MNT_DIR/root/" +mkdir -p "$MNT_DIR/root/boot/efi" +mount --bind "$MNT_DIR/boot" "$MNT_DIR/root/boot/efi" + +chroot "$MNT_DIR/root" mkinitfs "$KERNEL_VERSION" + +mkdir -p "$MNT_DIR/root/boot/grub" +cat > "$MNT_DIR/root/boot/grub/grub.cfg" <<GRUBCFG +insmod part_gpt +insmod fat +insmod efi_gop +insmod efi_uga + +set timeout=3 +menuentry "Anthrill OS" { + linux /vmlinuz-${KERNEL_VERSION} root=/dev/sda2 ro quiet + initrd /initramfs-${KERNEL_VERSION} +} +GRUBCFG + +grub-install --target=x86_64-efi \ + --efi-directory="$MNT_DIR/boot" \ + --boot-directory="$MNT_DIR/root/boot" \ + --removable \ + --no-nvram \ + --bootloader-id=anthrill + +umount "$MNT_DIR/root/boot/efi" +umount "$MNT_DIR/boot" +umount "$MNT_DIR/root" +losetup -d "$LOOP_DEV" + +echo "Running qemu" +qemu-system-x86_64 \ + -machine q35,accel=kvm:tcg \ + -cpu host \ + -m 1G \ + -bios /usr/share/edk2-ovmf/OVMF_CODE.fd \ + -drive file="$IMAGE_NAME",format=raw,if=virtio \ + -net nic -net user |
