start-vm.sh 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash
  2. set -e
  3. SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. image="./workspace/nixos-rpi2.img"
  5. mountdir="/mnt/nixos-rpi2"
  6. dtb="bcm2836-rpi-2-b.dtb"
  7. kernel="zImage"
  8. loop=`losetup -f --show -P "$image"`
  9. echo "created loopback device $loop"
  10. mkdir -p "$mountdir"
  11. mount "${loop}p2" "$mountdir"
  12. echo "mounted to $mountdir"
  13. dtb_path=`find "$mountdir/nix/store/" -name "$dtb" | head -n1`
  14. cp "$dtb_path" .
  15. kernel_path=`find "$mountdir/nix/store/" -name "$kernel" | head -n1`
  16. cp "$kernel_path" .
  17. cd "$mountdir"
  18. # bash
  19. cd "$SCRIPT_PATH"
  20. umount "$mountdir"
  21. losetup -d "$loop"
  22. #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
  23. qemu-img resize "$image" 4G
  24. 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