-
-
Save fr34k8/cd196412b2a5e1773257 to your computer and use it in GitHub Desktop.
ubuntu-auto-install: install a ubuntu image with kvm
This file contains 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
## how i verified hwe-t kernel boots / functions. | |
$ sudo apt-get update | |
$ sudo apt-get install qemu-system-x86 | |
$ sudo chmod 666 /dev/kvm | |
$ burl="http://archive.ubuntu.com/ubuntu/dists/precise-proposed/main/installer-amd64/current/images/trusty-netboot/ubuntu-installer/" | |
$ wget "$burl/amd64/linux" -O kernel | |
$ wget "$burl/amd64/initrd.gz" -O initrd | |
$ md5sum kernel initrd | |
eabacd97fa75fcf0946531f597390107 kernel | |
ccf58028315106c22b7187e1026a988a initrd | |
$ qemu-img create -f qcow2 disk.img 4G | |
$ PRESEED_URL=http://some.url | |
$ qemu-system-x86_64 -enable-kvm -m 1024 -curses \ | |
-device virtio-net-pci,netdev=net00 -netdev type=user,id=net00 \ | |
-drive if=virtio,file=disk.img,cache=unsafe \ | |
-no-reboot -kernel kernel -initrd initrd \ | |
-append "apt-setup/proposed=true nomodeset fb=false priority=critical locale=en_US url=$PRESEED_URL" | |
# the kernel command line params are: | |
# apt-setup/proposed=true: required per LP: #1172101 | |
# nomodeset fb=false: for -curses friendliness | |
# | |
## took defaults for everything other than | |
## * http_proxy (put in local proxy: http://192.168.1.130:3128/ ) | |
## * user: ubuntu passwd: ubuntu | |
## Then boot the system, removing the '-kernel and -initrd' | |
## verify that I'm running a 3.13 kernel | |
$ uname -r | |
3.13.0-30-generic | |
## just for my random information, you can then make it boot | |
## sanely in curses mode only by: | |
## echo "blacklist vga16fb" | sudo tee /etc/modprobe.d/novga16fb.conf | |
## sudo sed -i -e 's,\(GRUB_CMDLINE_LINUX_DEFAULT\)=.*,\1="quiet nomodeset",' \ | |
## -e 's,#GRUB_TERMINAL=console,GRUB_TERMINAL=console,' \ | |
## /etc/default/grub | |
## sudo update-grub | |
## sudo update-initramfs -u |
This file contains 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
# based on http://bit.ly/uquick-doc | |
#d-i mirror/country string manual | |
#d-i mirror/http/hostname string mymirror.org | |
#d-i mirror/http/directory string /rep | |
#d-i mirror/http/proxy string | |
#d-i mirror/http/mirror select mymirror.org | |
d-i debian-installer/locale string en_US.UTF-8 | |
d-i debian-installer/splash boolean false | |
d-i console-setup/ask_detect boolean false | |
d-i console-setup/layoutcode string us | |
d-i console-setup/variantcode string | |
d-i netcfg/get_nameservers string | |
d-i netcfg/get_ipaddress string | |
d-i netcfg/get_netmask string 255.255.255.0 | |
d-i netcfg/get_gateway string | |
d-i netcfg/confirm_static boolean true | |
d-i clock-setup/utc boolean true | |
d-i partman-auto/method string regular | |
d-i partman-lvm/device_remove_lvm boolean true | |
d-i partman-lvm/confirm boolean true | |
d-i partman/confirm_write_new_label boolean true | |
d-i partman/choose_partition select Finish partitioning and write changes to disk | |
d-i partman/confirm boolean true | |
d-i partman/confirm_nooverwrite boolean true | |
d-i partman/default_filesystem string ext3 | |
d-i clock-setup/utc boolean true | |
d-i clock-setup/ntp boolean true | |
d-i clock-setup/ntp-server string ntp.ubuntu.com | |
d-i passwd/root-login boolean false | |
d-i passwd/make-user boolean true | |
d-i passwd/user-fullname string ubuntu | |
d-i passwd/username string ubuntu | |
d-i passwd/user-password-crypted password $6$.1eHH0iY$ArGzKX2YeQ3G6U.mlOO3A.NaL22Ewgz8Fi4qqz.Ns7EMKjEJRIW2Pm/TikDptZpuu7I92frytmk5YeL.9fRY4. | |
d-i passwd/user-uid string | |
d-i user-setup/allow-password-weak boolean false | |
d-i user-setup/encrypt-home boolean false | |
d-i passwd/user-default-groups string adm cdrom dialout lpadmin plugdev sambashare | |
d-i apt-setup/services-select multiselect security | |
d-i apt-setup/security_host string security.ubuntu.com | |
d-i apt-setup/security_path string /ubuntu | |
d-i debian-installer/allow_unauthenticated string false | |
d-i pkgsel/upgrade select safe-upgrade | |
d-i pkgsel/language-packs multiselect | |
d-i pkgsel/update-policy select none | |
d-i pkgsel/updatedb boolean true | |
d-i grub-installer/skip boolean false | |
d-i lilo-installer/skip boolean false | |
d-i grub-installer/only_debian boolean true | |
d-i grub-installer/with_other_os boolean true | |
d-i finish-install/keep-consoles boolean false | |
d-i finish-install/reboot_in_progress note | |
d-i cdrom-detect/eject boolean true | |
d-i debian-installer/exit/halt boolean false | |
d-i debian-installer/exit/poweroff boolean false | |
d-i pkgsel/include string vim openssh-server | |
d-i preseed/late_command string \ | |
in-target sh -c '\ | |
echo blacklist vga16fb > /etc/modprobe.d/novga16fb.conf; \ | |
gld=GRUB_CMDLINE_LINUX_DEFAULT; gtr=GRUB_TERMINAL; \ | |
printf "$gld=\n$gtr=console\n" >> /etc/default/grub ; \ | |
update-initramfs -u; \ | |
update-grub;' |
This file contains 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 | |
VERBOSITY=0 | |
TEMP_D="" | |
DEF_PRESEED="http://bit.ly/uquick" | |
DEF_SIZE=4 | |
DEF_MIRROR="http://archive.ubuntu.com/ubuntu" | |
DEF_ARCH=$(uname -m) | |
[ "$DEF_ARCH" = "x86_64" ] && DEF_ARCH=amd64 | |
error() { echo "$@" 1>&2; } | |
errorp() { printf "$@" 1>&2; } | |
fail() { [ $# -eq 0 ] || error "$@"; exit 1; } | |
failp() { [ $# -eq 0 ] || errorp "$@"; exit 1; } | |
Usage() { | |
cat <<EOF | |
Usage: ${0##*/} [ options ] release [ arch [ size ] ] | |
Do an install of Ubuntu for release. | |
arch : the arch to use (amd64 i386). Default: ${DEF_ARCH} | |
size : size of the image (in GigaBytes). Default: ${DEF_SIZE} | |
options: | |
-o | --output IMAGE_FILE write the image to IMAGE_FILE | |
default: <release>-<arch>.img | |
-s | --preseed PRESEED use the preseed at preseed | |
default: ${DEF_PRESEED} | |
-m | --mirror MIRROR mirror to download iso from MIRROR | |
default: ${DEF_MIRROR} | |
--iso ISO use ISO file rather than downloading | |
EOF | |
} | |
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || error "$@"; exit 1; } | |
cleanup() { | |
[ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}" | |
} | |
dl() { | |
local url="$1" out="${2}" opts="" | |
[ "$url" = "$out" ] && return | |
[ $VERBOSITY -lt 1 ] && opts="-q" | |
case "$url" in | |
http://*|ftp://*) wget $opts "$url" -O "${out}";; | |
*) cat "${url}" -O "${out}";; | |
esac | |
} | |
debug() { | |
local level=${1}; shift; | |
[ "${level}" -ge "${VERBOSITY}" ] && return | |
error "${@}" | |
} | |
short_opts="hm:o:p:v" | |
long_opts="help,iso:,mirror:,output:,preseed:,verbose" | |
getopt_out=$(getopt --name "${0##*/}" \ | |
--options "${short_opts}" --long "${long_opts}" -- "$@") && | |
eval set -- "${getopt_out}" || | |
bad_Usage | |
release="${DEF_RELEASE}" | |
preseed="${DEF_PRESEED}" | |
output="" | |
mirror="${DEF_MIRROR}" | |
arch="${DEF_ARCH}" | |
iso="" | |
while [ $# -ne 0 ]; do | |
cur=${1}; next=${2}; | |
case "$cur" in | |
-h|--help) Usage ; exit 0;; | |
-i|--iso) iso=${2}; shift;; | |
-m|--mirror) mirror=${2}; shift;; | |
-o|--output) output=${2}; shift;; | |
-p|--preseed) preseed=${2}; shift;; | |
-v|--verbose) VERBOSITY=$((${VERBOSITY}+1));; | |
--) shift; break;; | |
esac | |
shift; | |
done | |
[ $# -ne 0 ] || bad_Usage "must provide arguments" | |
[ $# -lt 1 -o $# -gt 3 ] && bad_Usage "must provide 1,2, or 3 args" | |
release=$1 | |
arch=${2:-${DEF_ARCH}} | |
size=${3:-${DEF_SIZE}} | |
size=${size%G} | |
[ -n "$output" ] || output="${release}-${arch}.img" | |
TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXX") || | |
fail "failed to make tempdir" | |
trap cleanup EXIT | |
if [ -z "$iso" ]; then | |
iso="${release}-${arch}-mini.iso" | |
if [ -f "$iso" ]; then | |
debug 1 "using existing iso ${iso}" | |
else | |
url="${mirror}/dists/$release/main/installer-$arch/current/images/netboot/mini.iso" | |
debug 1 "downloading ${url}" | |
dl "${url}" "${iso}" || fail "failed to download $iso from $url" | |
fi | |
fi | |
dl "$preseed" preseed.cfg || | |
fail "failed to download preseed: ${preseed}" | |
debug 1 "extracting kernel and ramdisk" | |
for f in /linux /initrd.gz ; do | |
isoinfo -RJ -x "$f" -i "$iso" > "${f##*/}.dist" || | |
fail "failed to extract $f from $iso" | |
done | |
debug 1 "repacking initramfs" | |
zcat initrd.gz.dist > initrd && | |
echo "./preseed.cfg" | cpio -o --format=newc --append -F initrd && | |
gzip -9 initrd -c > initrd.gz && rm -f initrd || | |
fail "failed to repack initrd" | |
debug 1 "creating a ${size}G disk in ${output}" | |
qemu-img create -f qcow2 "${output}" "${size}G" || | |
fail "failed to create image" | |
set -x | |
${KVM:-kvm} -kernel linux -initrd initrd.gz \ | |
-append "priority=critical locale=en_US" \ | |
-drive "file=${output},if=virtio,cache=unsafe" \ | |
-cdrom "${iso}" -m 512 -boot d -no-reboot \ | |
# vi: ts=4 noexpandtab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment