run-install 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. # see https://forums.rancher.com/t/proposal-to-install-on-qemu/1236
  3. set -x -e
  4. cd $(dirname $0)/..
  5. source ./scripts/version
  6. BASE=$(pwd)
  7. STATE=/tmp
  8. DISK=${STATE}/rancheros.img
  9. CONFIG=${STATE}/cloud-config.yml
  10. export LOOPBACK=$(losetup -f)
  11. PARTITION=$(echo "${LOOPBACK}p1" | sed 's/dev/dev\/mapper/')
  12. DISPLAY_OPTS="-curses"
  13. # default
  14. #DISPLAY_OPTS="-nographic -serial stdio -display none"
  15. function clean_up {
  16. sudo umount mount || true
  17. sudo kpartx -d ${DISK} || true
  18. sudo losetup -d ${LOOPBACK} || true
  19. sudo rm ${DISK} || true
  20. }
  21. trap "clean_up; exit" SIGHUP SIGINT SIGTERM EXIT
  22. echo "writing to ${CONFIG} in ${STATE}"
  23. echo "#cloud-config" > ${CONFIG}
  24. echo "ssh_authorized_keys:" >> ${CONFIG}
  25. echo "- $(<${BASE}/assets/rancher.key.pub)" >> ${CONFIG}
  26. qemu-img create ${DISK} 1G
  27. sudo losetup ${LOOPBACK} ${DISK}
  28. echo "n
  29. p
  30. 1
  31. a
  32. w" | sudo fdisk ${LOOPBACK} || true
  33. sudo kpartx -a ${DISK}
  34. docker run --privileged -it --rm \
  35. -v /dev/mapper:/dev/mapper \
  36. -v ${STATE}:/cluster \
  37. rancher/os:${VERSION} \
  38. --isoinstallerloaded=1 \
  39. --force \
  40. --no-reboot \
  41. --debug \
  42. -c /cluster/cloud-config.yml \
  43. -t generic \
  44. -d ${LOOPBACK} \
  45. -p ${PARTITION} \
  46. --append "rancher.autologin=tty1"
  47. #-f /cluster/images.tar.xz:var/lib/system-docker/preload/images.tar.xz
  48. sync
  49. qemu-system-x86_64 -enable-kvm \
  50. ${DISPLAY_OPTS} \
  51. -m 1024 \
  52. -net nic,model=virtio \
  53. -net user,hostfwd=tcp::2222-:22 \
  54. -drive if=virtio,file=${DISK},format=raw