Skip to content

Instantly share code, notes, and snippets.

@frobware
Created March 2, 2016 10:28
Show Gist options
  • Save frobware/c3502773119eb4da7273 to your computer and use it in GitHub Desktop.
Save frobware/c3502773119eb4da7273 to your computer and use it in GitHub Desktop.
boot-ppc64.sh
#!/bin/bash
## this is an attempt to run ppc64le (ppc64el) guest on intel host
##
## there is a bootlog of this script working top to bottom
## including qemu kernel boot output and verification of network
## and disk device from initramfs
## http://paste.ubuntu.com/12255929/
# get boot-kernel and boot-initrd from maas-images (not required)
# see http://maas.ubuntu.com/images/ephemeral-v2/daily/wily/ppc64el/
# or use sstream-query
serial="20160123"
rel="trusty"
burl="http://maas.ubuntu.com/images/ephemeral-v2/daily/$rel/ppc64el/$serial"
cloudimg_url="http://cloud-images.ubuntu.com/daily/server/$rel/current/$rel-server-cloudimg-ppc64el-disk1.img"
fail() { echo "$@" 1>&2; exit 1; }
## get files from maas ephemeral images
for kfpath in $rel/generic/boot-initrd $rel/generic/boot-kernel root-image.gz; do
kfile="${kfpath##*/}"
[ -f "$kfile" ] && continue
wget --progress=dot:mega "$burl/$kfpath" -O "$kfile.tmp" &&
mv "$kfile.tmp" "$kfile" ||
{ rm -f "$kfile.tmp"; fail "failed get $kfile from $burl/$kfpath"; }
done
cloudimg=${cloudimg_url##*/}
if [ ! -f "${cloudimg}.dist" ]; then
wget --progress=dot:mega "$cloudimg_url" -O "$cloudimg.tmp" &&
mv "$cloudimg.tmp" "$cloudimg.dist" ||
fail "failed download $cloudimg_url"
fi
if [ ! -f "$cloudimg.raw" ]; then
echo "creating $cloudimg.raw from $cloudimg.dist"
qemu-img convert -O raw "$cloudimg.dist" "$cloudimg.raw" ||
fail "failed convert $cloudimg.dist -> $cloudimg.raw"
fi
## check for packages and install any needed.
pkgs=""
if ! which qemu-system-ppc64 &>/dev/null; then
pkgs="$pkgs qemu-system-ppc"
fi
if ! which cloud-localds &>/dev/null; then
pkgs="$pkgs cloud-image-utils"
sudo sh -c "apt-get -q update && apt-get install -qy $pkgs" ||
fail "failed get packages [$pkgs]"
fi
## create user-data, meta-data and then seed.img from that
cat > user-data <<EOF
#cloud-config
password: passw0rd
chpasswd: { expire: False }
ssh_pwauth: True
EOF
cat > meta-data <<EOF
instance-id: $(uuidgen || echo i-abcdefg)
EOF
cloud-localds seed.img user-data meta-data ||
fail "failed create seed.img"
if ! [ -f extra.img ]; then
qemu-img create -f qcow2 extra.img 8G ||
fail "failed create extra.img"
fi
if ! [ -f disk1.img ]; then
qemu-img create -f qcow2 -b "${cloudimg}.raw" disk1.img 10G ||
fail "failed create disk1.img from $cloudimg"
fi
if [ ! -f root-image ]; then
echo "uncompressing root-image.gz"
zcat root-image.gz > root-image.tmp &&
mv "root-image.tmp" "root-image" ||
fail "failed uncompress root-image.gz"
fi
kparms=(
console=hvc0 root=LABEL=cloudimg-rootfs
#overlayroot=tmpfs
)
cmd=(
qemu-system-ppc64el
-echr 0x05 -machine pseries,usb=off -m 4096
-device spapr-vscsi
-nographic -vga none
-device virtio-net-pci,netdev=net00 -netdev type=user,id=net00
# -drive if=virtio,file=root-image
-drive file=virtio,file=disk1.img,format=qcow2
-drive if=virtio,file=seed.img,format=raw
# -drive if=virtio,file=extra.img
# -kernel boot-kernel -initrd boot-initrd -append "${kparms[*]}"
)
echo "${cmd[@]}" "${cmd[@]}"
"${cmd[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment