Last active
August 22, 2017 13:46
-
-
Save grafuls/cbb34a29e4ea01da937d3d783b52903a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
. /etc/os-release | |
IMAGE="container-demo.img" | |
die() { echo "FATAL: $@" >&2 ; exit 1 ; } | |
info() { echo "INFO: $@" ; } | |
install_dependencies() { | |
info "Checking dependencies" | |
if [[ "$ID" == "fedora" ]]; then | |
for PKG in qemu-system-x86 libguestfs-tools-c; do | |
if ! dnf list installed $PKG 2>&-; then | |
die "Please install '$PKG'" | |
fi | |
done | |
elif [[ "$ID" == "ubuntu" ]]; then | |
info "Please ensure to setup libguestfs correctly: http://libguestfs.org/guestfs-faq.1.html#downloading-installing-compiling-libguestfs" | |
info "Eventually you need to run this script using sudo" | |
for PKG in qemu-system-x86 libguestfs-tools; do | |
if ! dpkg -s $PKG >/dev/null ; then | |
die "Please install '$PKG'" | |
fi | |
done | |
else | |
die "Unsupported operating system '$ID'. Get a real OS." | |
fi | |
} | |
install_dependencies | |
if ! virt-builder -v -x centos-7.3 \ | |
--no-network \ | |
--smp 4 --memsize 2048 \ | |
--output $IMAGE \ | |
--format qcow2 \ | |
--size 20G \ | |
--hostname container-demo \ | |
--root-password password: \ | |
--run-command "echo -e Login as \'root\' to proceed.\\\\n >> /etc/issue" \ | |
--firstboot-command \ | |
"sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ; | |
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo ; | |
sudo yum -y install docker-ce ; | |
systemctl enable docker ; | |
systemctl start docker" | |
then | |
die "Failed on virt-builder. Unable to create image." | |
fi | |
QEMU_CMD=/usr/libexec/qemu-kvm | |
if [[ ! -x $QEMU_CMD ]] | |
then | |
QEMU_CMD=qemu-system-x86_64 | |
fi | |
$QEMU_CMD \ | |
--cpu host --machine accel=kvm:tcg \ | |
--nographic -m 2048 -smp 4 \ | |
-net nic \ | |
-object rng-random,id=objrng0,filename=/dev/urandom -device virtio-rng-pci,rng=objrng0 \ | |
-net user \ | |
$IMAGE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment