|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Script to start any CustomPiOS raspbian image from qemu |
| 3 | +# Usage: qemu_boot.sh </path/to/zip/with/img/file.zip> |
| 4 | +set -x |
| 5 | +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 6 | + |
| 7 | +ZIP_IMG=$1 |
| 8 | +DEST=/tmp |
| 9 | +source ${DIR}/common.sh |
| 10 | + |
| 11 | +IMG_NAME=$(unzip -Z "${ZIP_IMG}" | head -n 3 | tail -n 1 | awk '{ print $9 }') |
| 12 | +BASE_IMG_PATH=${DEST}/"${IMG_NAME}" |
| 13 | + |
| 14 | + |
| 15 | +if [ ! -f "${BASE_IMG_PATH}" ]; then |
| 16 | + unzip -o "${ZIP_IMG}" -d "${DEST}" |
| 17 | + |
| 18 | + BASE_ROOT_PARTITION=2 |
| 19 | + BASE_MOUNT_PATH=${DEST}/mount |
| 20 | + mkdir -p "${BASE_MOUNT_PATH}" |
| 21 | + |
| 22 | + sudo bash -c "$(declare -f mount_image); $(declare -f detach_all_loopback); mount_image $BASE_IMG_PATH $BASE_ROOT_PARTITION $BASE_MOUNT_PATH" |
| 23 | + |
| 24 | + pushd "${BASE_MOUNT_PATH}" |
| 25 | + sudo bash -c "$(declare -f fixLd); fixLd" |
| 26 | + sudo sed -e '/PARTUUID/ s/^#*/#/' -i etc/fstab |
| 27 | + sudo bash -c 'echo "/dev/sda1 /boot vfat defaults 0 2" >> etc/fstab' |
| 28 | + popd |
| 29 | + |
| 30 | + pushd "${BASE_MOUNT_PATH}/boot" |
| 31 | + rm -rf /tmp/debian_bootpart || true |
| 32 | + mkdir /tmp/debian_bootpart |
| 33 | + cp kernel8.img /tmp/debian_bootpart |
| 34 | + DTB_PATH="$(ls *-3-b.dtb | head)" |
| 35 | +# sudo bash -c 'cp initrd.img*-arm64 /tmp/debian_bootpart' |
| 36 | + cp ${DTB_PATH} /tmp/debian_bootpart |
| 37 | +# sudo bash -c 'cp cmdline.txt /tmp/debian_bootpart' |
| 38 | +# sudo bash -c 'cp vmlinuz-*-arm64 /tmp/debian_bootpart' |
| 39 | + popd |
| 40 | + sudo bash -c "$(declare -f mount_image); $(declare -f detach_all_loopback); unmount_image $BASE_MOUNT_PATH force" |
| 41 | + |
| 42 | + |
| 43 | +fi |
| 44 | + |
| 45 | + |
| 46 | +#/usr/bin/qemu-system-aarch64 -kernel ${KERNEL_PATH} -cpu host -m 256 -M virt -dtb ${DTB_PATH} -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda ${BASE_IMG_PATH} -net nic -net user,hostfwd=tcp::5022-:22 |
| 47 | + |
| 48 | +#sudo qemu-system-arm -enable-kvm -m 1024 -cpu host -M virt -nographic -pflash flash0.img -pflash flash1.img -drive if=none,file=vivid-server-cloudimg-arm64-uefi1.img,id=hd0 -device virtio-blk-device,drive=hd0 -netdev type=tap,id=net0 -device virtio-net-device,netdev=net0,mac=$randmac |
| 49 | + |
| 50 | +#/usr/bin/qemu-system-arm -kernel ${KERNEL_PATH} -cpu arm1176 -m 256 -M versatilepb -dtb ${DTB_PATH} -no-reboot -serial stdio -append 'root=/dev/sda2 panic=1 rootfstype=ext4 rw' -hda ${BASE_IMG_PATH} -net nic -net user,hostfwd=tcp::5022-:22 |
| 51 | + |
| 52 | + |
| 53 | + DTB_PATH=$(ls /tmp/debian_bootpart/*-3-b.dtb | head) |
| 54 | + |
| 55 | + qemu-system-aarch64 \ |
| 56 | + -kernel /tmp/debian_bootpart/kernel8.img \ |
| 57 | + -dtb "${DTB_PATH}" \ |
| 58 | + -m 1024 -M raspi3 \ |
| 59 | + -cpu cortex-a53 \ |
| 60 | + -serial stdio \ |
| 61 | + -append "rw earlycon=pl011,0x3f201000 console=ttyAMA0 loglevel=8 root=/dev/mmcblk0p2 fsck.repair=yes net.ifnames=0 rootwait memtest=1" \ |
| 62 | + -drive file="${BASE_IMG_PATH}",format=raw,if=sd \ |
| 63 | + -no-reboot |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +#sudo umount ${BASE_MOUNT_PATH} |
| 68 | + |
0 commit comments