1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | PREFIX=$(dirname $(readlink -f $0)) DISK=${PREFIX}/qwharfie.qcow INPUT=qwharfie.input.raw OUTPUT=qwharfie.output.raw CACHE=qwharfie.cache.qcow UUID=$(cat ${DISK}.uuid) INITRD=$(ls -1 ${PREFIX}/boot/initrd* | sort | head -n 1) KERNEL=$(ls -1 ${PREFIX}/boot/vmlinuz* | sort | head -n 1) QEMU=$(which qemu-system-x86_64) QWHARFIE_OUTPUT=1G QWHARFIE_CACHE=10G function error() { msg=${1} echo "error: ${msg}"; exit 1; } # Check, that all prerequisits are there [ -z ${DISK} ] && error "No hard drive image defined"; [ -z ${UUID} ] && error "No UUID for HD image found. Has to be a file, named '<img-name>.uuid'."; [ -z ${INITRD} ] && error "No initial ramdisk found (searched in /boot for initrd*)"; [ -z ${KERNEL} ] && error "No kernel found (searched in /boot for vmlinuz*)"; [ -z ${QEMU} ] && error "No QEMU system emulation found. Install Qemu system emulation for x86_64"; # Generate Makefile #${PREFIX}/../wharfie.py --gen-only #cp ${PREFIX}/../wharfie.mk . # Create input, output and cache images tar --exclude="${INPUT}" --exclude="${OUTPUT}" --exclude="${CACHE}" -cf ${INPUT} . if [ ! -f ${OUTPUT} ]; then qemu-img create -f raw ${OUTPUT} ${QWHARFIE_OUTPUT} fi if [ ! -f ${CACHE} ]; then if [ -f ${PREFIX}/${CACHE} ]; then cp ${PREFIX}/${CACHE} . else qemu-img create -f raw ${CACHE}.raw ${QWHARFIE_CACHE} # create partition table ( echo o # Create a new empty DOS partition table echo n # Add a new partition echo p # Primary partition echo 1 # Partition number echo # First sector (Accept default: 1) echo # Last sector (Accept default: varies) echo w # Write changes ) | sudo fdisk ${CACHE}.raw && l=$(sudo /sbin/kpartx -l ${CACHE}.raw | sed -n '/loop/ s,.*/dev/\(loop[0-9]\+\).*,\1, p;q;') && sudo /sbin/kpartx -as ${CACHE}.raw && # Create filesystem sudo mkfs.ext3 /dev/mapper/${l}p1 && sudo /sbin/kpartx -ds ${CACHE}.raw && qemu-img convert -O qcow2 ${CACHE}.raw ${CACHE} rm -f ${CACHE}.raw fi fi # Run Qemu ${QEMU} -machine accel=kvm -m 512 -hda ${DISK} -hdb ${CACHE} -hdc ${INPUT} -hdd ${OUTPUT} -net nic,model=virtio -net user -kernel ${KERNEL} -initrd ${INITRD} -append "root=UUID=${UUID} ro single console=ttyS0 fsck.mode=skip systemd.unit=multi-user.target" -nographic tar -xf ${OUTPUT} |