Browse Source

add script to start a vm

subDesTagesMitExtraKaese 3 weeks ago
parent
commit
6590344134
3 changed files with 48 additions and 0 deletions
  1. 7 0
      .gitignore
  2. 37 0
      start-vm.sh
  3. 4 0
      workspace/build.sh

+ 7 - 0
.gitignore

@@ -0,0 +1,7 @@
+# images
+*.img
+*.dtb
+zImage
+
+
+*.log

+ 37 - 0
start-vm.sh

@@ -0,0 +1,37 @@
+#!/bin/bash
+
+set -e
+
+SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+image="./workspace/nixos-rpi2.img"
+mountdir="/mnt/nixos-rpi2"
+dtb="bcm2836-rpi-2-b.dtb"
+kernel="zImage"
+
+loop=`losetup -f --show -P "$image"`
+echo "created loopback device $loop"
+
+
+mkdir -p "$mountdir"
+mount "${loop}p2" "$mountdir"
+echo "mounted to $mountdir"
+
+dtb_path=`find "$mountdir/nix/store/" -name "$dtb" | head -n1`
+cp "$dtb_path" .
+
+kernel_path=`find "$mountdir/nix/store/" -name "$kernel" | head -n1`
+cp "$kernel_path" .
+
+cd "$mountdir"
+# bash
+cd "$SCRIPT_PATH"
+
+umount "$mountdir"
+losetup -d "$loop"
+
+
+#qemu-system-arm -kernel "$kernel" -cpu arm1176 -m 256 -M versatilepb -serial stdio -append "root=/dev/sda2 rootfstype=ext4 rw" -dtb "$dtb" -hda "$image" -no-reboot
+
+qemu-img resize "$image" 4G
+qemu-system-arm -M raspi2b -append "rw earlyprintk loglevel=8 console=ttyAMA0,115200 dwc_otg.lpm_enable=0 root=/dev/sda2 rootdelay=1" -sd "$image" -dtb "$dtb" -kernel "$kernel" -m 1G -smp 4 -serial stdio -usb -device usb-mouse -device usb-kbd 2>&1 | tee qemu.log

+ 4 - 0
workspace/build.sh

@@ -1,5 +1,9 @@
+set -e
 
 nix-build '<nixpkgs/nixos>' \
   -A config.system.build.sdImage \
   --arg pkgs 'import <nixpkgs> { crossSystem = { system = "armv7l-linux"; }; }' \
   -I nixos-config=./rpi2.nix
+
+cp result/sd-image/nixos-rpi2.img .
+rm result