123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #!/bin/bash
- set -e
- # help: build and run RancherOS, requires KVM local
- cd $(dirname $0)/..
- source ./scripts/run-common
- while [ "$#" -gt 0 ]; do
- case $1 in
- --append)
- shift 1
- QEMU_APPEND="${QEMU_APPEND} $1"
- ;;
- --name)
- shift 1
- NAME="$1"
- ;;
- --cloud-config)
- shift 1
- CLOUD_CONFIG="$1" || :
- if [ ! -f ${CLOUD_CONFIG} ]; then
- echo No such file: "'"${CLOUD_CONFIG}"'" 1>&2
- exit 1
- fi
- ;;
- --second-drive)
- SECOND_DRIVE=1
- ;;
- --arch)
- shift 1
- ARCH="$1"
- ;;
- --qemu)
- QEMU=1
- ;;
- --qind)
- QIND=1
- QEMU=0
- ;;
- --kvm)
- KVM=1
- ;;
- --no-format)
- FORMAT=0
- ;;
- --no-rm-usr)
- RM_USR=0
- ;;
- --no-rebuild)
- REBUILD=0
- ;;
- --fresh)
- FRESH=1
- ;;
- --installed)
- ./scripts/create-installed
- INSTALLED=1
- ;;
- *)
- break
- ;;
- esac
- shift 1
- done
- if [ "$QEMU" == "1" ] && ! which qemu-system-${QEMUARCH}; then
- QEMU=0
- fi
- if [[ ! -e ${KERNEL} || ! -e ${INITRD_SRC} ]]; then
- echo "Failed to find ${KERNEL} or ${INITRD_SRC}" 1>&2
- exit 1
- fi
- if [ "$REBUILD" == "1" ] || [ ! -e ${INITRD} ]; then
- cp bin/ros ${INITRD_SRC}/usr/bin/ros
- ./scripts/hash-initrd
- pushd ${INITRD_SRC} >/dev/null
- find . | cpio -H newc -o | gzip -1 > ${INITRD}
- popd >/dev/null
- fi
- KERNEL_ARGS="${DEFAULT_KERNEL_ARGS} ${QEMU_APPEND}"
- if [ "$FORMAT" == "1" ]; then
- KERNEL_ARGS="${KERNEL_ARGS} rancher.state.dev=LABEL=RANCHER_STATE rancher.state.autoformat=[/dev/sda,/dev/vda]"
- fi
- if [ "$RM_USR" == "1" ]; then
- KERNEL_ARGS="${KERNEL_ARGS} rancher.rm_usr"
- fi
- if [ "$KVM" == "" ] && [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; then
- KVM=1
- fi
- if [ "$QEMU" == "1" ]; then
- HD=${BASE}/state/hd.img
- HD2=${BASE}/state/hd2.img
- [ "$FRESH" == "1" ] && rm -f ${HD} ${HD2} >/dev/null 2>&1 || :
- if [ ! -e ${HD} ]; then
- mkdir -p $(dirname ${HD})
- qemu-img create -f qcow2 -o size=10G ${HD}
- fi
- if [ "$SECOND_DRIVE" == "1" ]; then
- qemu-img create -f qcow2 -o size=10G ${HD2}
- SECOND_DRIVE_ENABLE=$(eval "${hd["$ARCH"]} ${HD2}")
- fi
- CCROOT=${BUILD}/cloud-config
- rm -rf ${CCROOT}
- mkdir -p ${CCROOT}
- USER_DATA=${CCROOT}/openstack/latest/user_data
- mkdir -p $(dirname ${USER_DATA})
- rm -f ${USER_DATA} || :
- if [ -n "$CLOUD_CONFIG" ]; then
- cat ${CLOUD_CONFIG} > ${USER_DATA}
- else
- echo "#cloud-config" > ${USER_DATA}
- echo "ssh_authorized_keys:" >> ${USER_DATA}
- echo "- $(<${BASE}/assets/rancher.key.pub)" >> ${USER_DATA}
- fi
- CPU=${cpu["$ARCH"]}
- if [ "$KVM" == "1" ] && [ "$ARCH" == "$HOST_ARCH" ]; then
- KVM_ENABLE="-enable-kvm"
- CPU="-cpu host"
- fi
- HOME=${HOME:-/}
- if [ "$INSTALLED" == "1" ]; then
- set -x
- exec qemu-system-${QEMUARCH} -serial stdio \
- -rtc base=utc,clock=host \
- ${KVM_ENABLE} \
- ${CPU} \
- ${machine["$ARCH"]} \
- -m 2048 \
- ${network["$ARCH"]} \
- $(eval "${hd["$ARCH"]} ${HD}") \
- ${SECOND_DRIVE_ENABLE} \
- -smp 1 \
- -nographic \
- -display none \
- -fsdev local,security_model=passthrough,readonly,id=fsdev0,path=${CCROOT} \
- -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2 \
- -fsdev local,security_model=none,id=fsdev1,path=${HOME} \
- -device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home \
- ${QEMU_ARGS} \
- "${@}"
- else
- set -x
- exec qemu-system-${QEMUARCH} -serial stdio \
- -rtc base=utc,clock=host \
- ${KVM_ENABLE} \
- ${CPU} \
- ${machine["$ARCH"]} \
- -kernel ${KERNEL} \
- -initrd ${INITRD} \
- -m 2048 \
- ${network["$ARCH"]} \
- $(eval "${hd["$ARCH"]} ${HD}") \
- ${SECOND_DRIVE_ENABLE} \
- -smp 1 \
- -append "${KERNEL_ARGS}" \
- -nographic \
- -display none \
- -fsdev local,security_model=passthrough,readonly,id=fsdev0,path=${CCROOT} \
- -device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=config-2 \
- -fsdev local,security_model=none,id=fsdev1,path=${HOME} \
- -device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home \
- ${QEMU_ARGS} \
- "${@}"
- fi
- elif [ "$QIND" == "1" ]; then
- NAME=${NAME:-ros-qind}
- if [ "$FRESH" == "1" ]; then
- docker rm -fv ${NAME} >/dev/null 2>&1 || :
- fi
- if ! docker inspect ${NAME} >/dev/null 2>&1; then
- if [ "$KVM" == "1" ]; then
- KVM_ENABLE="--device=/dev/kvm:/dev/kvm"
- fi
- mkdir -p ./tmp
- TMP=$(mktemp -d ./tmp/ros-qind-XXXXXX)
- mkdir -p ${TMP}/stuff
- trap "rm -rf ${TMP}" EXIT
- ln ${CLOUD_CONFIG} ${KERNEL} ${INITRD} ./assets/rancher.key ./assets/rancher.key.pub ${TMP}/stuff/
- KERNEL_FILE=$(basename ${KERNEL})
- INITRD_FILE=$(basename ${INITRD})
- if [ -n "$CLOUD_CONFIG" ]; then
- CLOUD_CONFIG_ENABLE="--cloud-config /stuff/$(basename ${CLOUD_CONFIG})"
- else
- SSH_PUB_ENABLE="--ssh-pub /stuff/rancher.key.pub"
- fi
- set -x
- docker create --name=${NAME} -it ${KVM_ENABLE} \
- rancher/qind \
- --hostname "rancher-dev" \
- ${CLOUD_CONFIG_ENABLE} \
- ${SSH_PUB_ENABLE} \
- -m 1G -kernel /stuff/${KERNEL_FILE} -initrd /stuff/${INITRD_FILE} -append "${KERNEL_ARGS}" \
- "${@}"
- docker cp ${TMP}/stuff ${NAME}:/stuff
- rm -rf ${TMP}
- fi
- exec docker start -ai ${NAME}
- else
- exit 42
- fi
|