From: Richard W.M. Jones Date: Thu, 10 Dec 2015 14:36:30 +0000 (+0000) Subject: 2015 virt tools talk. X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=d5ed61baa8deb36d33c7595cc83249991c66fe1f;p=libguestfs-talks.git 2015 virt tools talk. --- diff --git a/2015-virt-tools/.gitignore b/2015-virt-tools/.gitignore new file mode 100644 index 0000000..d678620 --- /dev/null +++ b/2015-virt-tools/.gitignore @@ -0,0 +1,2 @@ +/bindings +/history diff --git a/2015-virt-tools/0000-introduction.html b/2015-virt-tools/0000-introduction.html new file mode 100644 index 0000000..35916b1 --- /dev/null +++ b/2015-virt-tools/0000-introduction.html @@ -0,0 +1,21 @@ + + + + +
+

+ virt-resize, virt-sparsify, virt-customize, virt-sysprep, virt-builder +

+

+ Richard W.M. Jones
+ rjones @ redhat.com +

+

+ libguestfs is a library and set of tools for manipulating + virtual machine disk images. +

+

+ This talk is about the virt-tools which build on this + library to provide many useful abstractions. +

+
diff --git a/2015-virt-tools/1000-virt-resize.d/.gitignore b/2015-virt-tools/1000-virt-resize.d/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/2015-virt-tools/1000-virt-resize.d/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/2015-virt-tools/1000-virt-resize.term b/2015-virt-tools/1000-virt-resize.term new file mode 100755 index 0000000..adffc85 --- /dev/null +++ b/2015-virt-tools/1000-virt-resize.term @@ -0,0 +1,15 @@ +#!/bin/bash - + +source functions + +# History. +remember 'qemu-img info fedora-22.qcow2' +remember 'virt-df -a fedora-22.qcow2 -h' +remember 'qemu-img create -f qcow2 fedora-22-bigger.qcow2 10G' +remember 'virt-resize fedora-22.qcow2 fedora-22-bigger.qcow2 --expand sda3' +remember 'virt-df -a fedora-22-bigger.qcow2 -h' + +echo "Running virt-resize" + +cd 1000-virt-resize.d +terminal diff --git a/2015-virt-tools/2000-thin-provisioning.svg b/2015-virt-tools/2000-thin-provisioning.svg new file mode 100644 index 0000000..c7cc146 --- /dev/null +++ b/2015-virt-tools/2000-thin-provisioning.svg @@ -0,0 +1,275 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + deleted/unused space in the guest + unallocated disk blocks on the host + + diff --git a/2015-virt-tools/2000-virt-sparsify.d/.gitignore b/2015-virt-tools/2000-virt-sparsify.d/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/2015-virt-tools/2000-virt-sparsify.d/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/2015-virt-tools/2000-virt-sparsify.html b/2015-virt-tools/2000-virt-sparsify.html new file mode 100644 index 0000000..320c2e9 --- /dev/null +++ b/2015-virt-tools/2000-virt-sparsify.html @@ -0,0 +1,11 @@ + + + + +

Thin provisioning

+ + + + diff --git a/2015-virt-tools/2100-virt-sparsify.term b/2015-virt-tools/2100-virt-sparsify.term new file mode 100755 index 0000000..1f74a75 --- /dev/null +++ b/2015-virt-tools/2100-virt-sparsify.term @@ -0,0 +1,17 @@ +#!/bin/bash - + +source functions + +# History. + +remember 'qemu-img info fedora-22.img' +remember 'du -sh fedora-22.img' +remember 'virt-df -a fedora-22.img -h' +remember 'virt-sparsify --inplace fedora-22.img' +remember 'qemu-img info fedora-22.img' +remember 'du -sh fedora-22.img' + +echo "Running virt-sparsify" + +cd 2000-virt-sparsify.d +terminal diff --git a/2015-virt-tools/3000-virt-customize.d/.gitignore b/2015-virt-tools/3000-virt-customize.d/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/2015-virt-tools/3000-virt-customize.d/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/2015-virt-tools/3000-virt-customize.html b/2015-virt-tools/3000-virt-customize.html new file mode 100644 index 0000000..4011c94 --- /dev/null +++ b/2015-virt-tools/3000-virt-customize.html @@ -0,0 +1,17 @@ + + + + +

virt-customize

+ + diff --git a/2015-virt-tools/3100-virt-customize.term b/2015-virt-tools/3100-virt-customize.term new file mode 100755 index 0000000..070ccc9 --- /dev/null +++ b/2015-virt-tools/3100-virt-customize.term @@ -0,0 +1,13 @@ +#!/bin/bash - + +source functions + +# History. + +remember 'virt-customize -a fedora-22.img --install gcc,gdb --root-password password:123456 --edit /etc/selinux/config:s/^SELINUX=.*/SELINUX=permissive/' +remember 'virt-cat -a fedora-22.img /etc/selinux/config' + +echo "Running virt-customize" + +cd 3000-virt-customize.d +terminal diff --git a/2015-virt-tools/4000-virt-sysprep.d/.gitignore b/2015-virt-tools/4000-virt-sysprep.d/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/2015-virt-tools/4000-virt-sysprep.d/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/2015-virt-tools/4000-virt-sysprep.term b/2015-virt-tools/4000-virt-sysprep.term new file mode 100755 index 0000000..0b90a4c --- /dev/null +++ b/2015-virt-tools/4000-virt-sysprep.term @@ -0,0 +1,13 @@ +#!/bin/bash - + +source functions + +# History. + +remember 'virt-sysprep -a fedora-22.img' +remember 'virt-sysprep --list-operations' + +echo "Running virt-sysprep" + +cd 4000-virt-sysprep.d +terminal diff --git a/2015-virt-tools/5000-prepare-templates.html b/2015-virt-tools/5000-prepare-templates.html new file mode 100644 index 0000000..8d480fa --- /dev/null +++ b/2015-virt-tools/5000-prepare-templates.html @@ -0,0 +1,18 @@ + + + + +

virt-builder: Preparing templates

+ +

+virt-install
+↓
+virt-sysprep
+↓
+virt-sparsify
+↓
+xz compress
+↓
+Online template repository
+(http://libguestfs.org/download/builder) +

diff --git a/2015-virt-tools/5000-virt-builder.d/.gitignore b/2015-virt-tools/5000-virt-builder.d/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/2015-virt-tools/5000-virt-builder.d/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/2015-virt-tools/5100-virt-builder-list.term b/2015-virt-tools/5100-virt-builder-list.term new file mode 100755 index 0000000..97dc6f5 --- /dev/null +++ b/2015-virt-tools/5100-virt-builder-list.term @@ -0,0 +1,13 @@ +#!/bin/bash - + +source functions + +# History. + +remember 'virt-builder -l' +remember 'virt-builder --notes rhel-7.1' + +echo "virt-builder" + +cd 5000-virt-builder.d +terminal diff --git a/2015-virt-tools/5200-run-virt-builder.html b/2015-virt-tools/5200-run-virt-builder.html new file mode 100644 index 0000000..677f810 --- /dev/null +++ b/2015-virt-tools/5200-run-virt-builder.html @@ -0,0 +1,17 @@ + + + + +

virt-builder: Running

+ +

+Download a template
+↓
+xz uncompress
+↓
+virt-resize
+↓
+virt-customize
+↓
+Disk image ready to boot +

diff --git a/2015-virt-tools/5300-run-virt-builder.term b/2015-virt-tools/5300-run-virt-builder.term new file mode 100755 index 0000000..dd42e31 --- /dev/null +++ b/2015-virt-tools/5300-run-virt-builder.term @@ -0,0 +1,15 @@ +#!/bin/bash - + +source functions + +# History. + +remember 'virt-builder rhel-7.1' +remember 'virt-builder rhel-7.1 --install gcc --selinux-relabel' +remember 'virt-builder rhel-7.1 --size 20G' +remember 'virt-df -a rhel-7.1.img -h' + +echo "Running virt-builder" + +cd 5000-virt-builder.d +terminal diff --git a/2015-virt-tools/5400-distro-metadata.html b/2015-virt-tools/5400-distro-metadata.html new file mode 100644 index 0000000..cfb769a --- /dev/null +++ b/2015-virt-tools/5400-distro-metadata.html @@ -0,0 +1,60 @@ + + + + +

virt-builder: Distro metadata

+ + + + + + +
+ +
+

+virt-install
+↓
+virt-sysprep
+↓
+virt-sparsify
+↓
+xz compress
+↓
+Online template repository
+(http://libguestfs.org/download/builder) +

+
+ +
+ +
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+[centos-6.6]
+name=CentOS 6.6
+arch=x86_64
+file=CentOS-6.6-x86_64-Cloud.raw.xz
+checksum[sha512]=fc403ea3555a560...
+format=raw
+size=6442450944
+compressed_size=199265736
+expand=/dev/sda3
+
+-----BEGIN PGP SIGNATURE-----
+
+ +
+ +

+virt-builder can pull templates from multiple +repositories. +

diff --git a/2015-virt-tools/9000-final.html b/2015-virt-tools/9000-final.html new file mode 100644 index 0000000..56479fe --- /dev/null +++ b/2015-virt-tools/9000-final.html @@ -0,0 +1,29 @@ + + + + +

More information

+ + diff --git a/2015-virt-tools/NOTES b/2015-virt-tools/NOTES new file mode 100644 index 0000000..9223840 --- /dev/null +++ b/2015-virt-tools/NOTES @@ -0,0 +1,151 @@ +virt-resize, virt-sparsify, virt-customize, virt-sysprep, virt-builder +---------------------------------------------------------------------- + +Audience: + + - Interested in manipulating disk images. + - May be familiar with disk images, formats, but may not be. + - Not developers. + + +1000: Resizing a disk image +---------------------------------------------------------------------- + +Show a disk image, use 'qemu-img info' to get data about it. + + $ qemu-img info fedora-22.qcow2 + +--> Format +--> Size : virtual and physical may not be related + +What the guest would see when booted up: + + $ virt-df -a fedora-22.qcow2 -h + +Always use 'qemu-img info', not 'ls -l'. + +What if the guest needs more space? +There are various ways to resize a disk image: + + - Just make the container bigger ('qemu-img resize' or even 'truncate'). + But the partitions won't get bigger. [illustrate with picture] + + - Run a tool inside the guest, like parted. It won't usually work + if the disk is mounted. + + - Run a tool alongside the guest, but still in a VM, eg. PartitionMagic, + GParted Live. + + - Use virt-resize on the host for offline resizing. + + $ qemu-img create -f qcow2 fedora-22-bigger.qcow2 10G + $ virt-resize fedora-22.qcow2 fedora-22-bigger.qcow2 --expand sda3 + $ virt-df -a fedora-22-bigger.qcow2 -h + +virt-resize is quite flexible: For example you could give /dev/sda1 +500 MB and give the rest to /dev/sda3, or you could tell virt-resize +to put the new space into an extra partition. + +Also works for Windows. + + +2000: Sparsifying a disk image +---------------------------------------------------------------------- + +Show a fully allocated disk image, this time with 'ls -lh': + + $ qemu-img info fedora-22.img + $ du -sh fedora-22.img + $ virt-df -a fedora-22.img -h + +Sparsify it in place: + + $ virt-sparsify --inplace fedora-22.img + $ qemu-img info fedora-22.img + $ du -sh fedora-22.img + +Explain the two modes for sparsification. + +Also works for Windows. + + +3000: Customizing a disk image +---------------------------------------------------------------------- + +The situation is that you have an existing guest operating system, and +you want to _offline_ install packages, set the root password, inject +files, set the hostname, or about a dozen other things. + + $ virt-customize -a fedora-22.img --install gcc,gdb --root-password password:123456 --edit /etc/selinux/config:s/^SELINUX=.*/SELINUX=permissive/ + $ virt-cat -a fedora-22.img /etc/selinux/config + +Also works for a limited range of operations on Windows. On Windows, +most work is done using "firstboot" batch files that run once at the +next boot. + + +4000: Sysprepping a disk image +---------------------------------------------------------------------- + +SYSPREP.EXE is a Microsoft proprietary program for preparing a Windows +system for duplication. It removes the identity of the system. + +We borrow the name of this program for the next tool, virt-sysprep, +which does a similar job for Linux systems, turning them into +templates from which you can clone further guests. This is a tool +you'll probably either use all the time or never need to use at all. + + $ virt-sysprep -a fedora-22.img + +It runs on the guest in-place. + +It performs a serious of sysprepping operations, which you can read +about in the manual. + +There are some operations which are not enabled by default: + + $ virt-sysprep --list-operations + +You'll want to read the manual before using this. + +This deletes the SSH host keys, because you wouldn't want those to be +duplicated across clones. But it can't set up a fresh random seed for +each clone. For that you need to set a random seed after the clone, +using virt-customize. Virt-builder which I'll talk about next also +sets a fresh random seed automatically. + + +5000: Building a disk image +---------------------------------------------------------------------- + +Show a diagram of the whole process and how the tools are related. + + preparing templates for virt-builder + virt-install ---> sysprep ---> sparsify ---> compress ---> templates + (OS installer) repository + + running virt-builder as an end user + download a template ---> uncompress ---> resize/format ---> customize ---> result + or a cloud image + + + $ virt-builder -l + $ virt-builder --notes rhel-7.1 + $ virt-builder rhel-7.1 + +Speed is important! + +Any virt-customize options can be used: + + $ virt-builder rhel-7.1 --install gcc --selinux-relabel + +If you use the --size option, virt-resize is invoked which takes a bit +longer: + + $ virt-builder rhel-7.1 --size 20G + $ virt-df -a rhel-7.1.img -h + +virt-builder only builds disk images. It doesn't run them or upload +them into glance. + +Other tools have been built around virt-builder. diff --git a/2015-virt-tools/README b/2015-virt-tools/README new file mode 100644 index 0000000..192228d --- /dev/null +++ b/2015-virt-tools/README @@ -0,0 +1,4 @@ +This is a talk about particular virt tools (virt-resize, +virt-sparsify, virt-customize, virt-sysprep, virt-builder) which I +gave privately to Red Hat colleagues (December 2015) and then recorded +for QEMU's Hangouts on Air programme. diff --git a/2015-virt-tools/bashrc b/2015-virt-tools/bashrc new file mode 100644 index 0000000..4c6a3c6 --- /dev/null +++ b/2015-virt-tools/bashrc @@ -0,0 +1,17 @@ +# -*- shell-script -*- + +# Colour ls. +if [ -f /etc/profile.d/colorls.sh ]; then . /etc/profile.d/colorls.sh; fi + +# Fancy prompt colours (see +# https://wiki.archlinux.org/index.php/Color_Bash_Prompt) +promptcol='\e[0;32m' ;# colour for the prompt +commandcol='\e[1;31m' ;# colour for the typed command +outputcol='\e[0m' ;# colour for command output + +export PS1="\n\[$promptcol\]\$ \[$commandcol\]" + +trap 'echo -ne "$outputcol"' DEBUG + +# Load key bindings (if any). +bind -f $talkdir/bindings diff --git a/2015-virt-tools/code.js b/2015-virt-tools/code.js new file mode 100644 index 0000000..e69de29 diff --git a/2015-virt-tools/functions b/2015-virt-tools/functions new file mode 100644 index 0000000..d5347e7 --- /dev/null +++ b/2015-virt-tools/functions @@ -0,0 +1,43 @@ +# -*- shell-script -*- +# This creates some standard functions. See also $talkdir/bashrc +# which runs in the same bash context as the terminal. + +# Place any local environment variables and settings in "local". +if [ -f local ]; then source local; fi + +# Environment variables. +export HISTFILE=$talkdir/history +export PATH=$talkdir:$PATH +export EDITOR="emacs -nw" + +# Ditch libvirt for stability :-( +export LIBGUESTFS_BACKEND=direct + +# remember +# +# This function does two things: (1) It adds the command and arguments +# to the shell history, so that commands can be recalled using up +# arrow or reverse search. (2) It makes a function key recall the +# command. The first command is assigned to F2, the second to F3 and +# so forth. + +rm -f $HISTFILE +touch $HISTFILE +rm -f $talkdir/bindings +touch bindings + +fnum=2 +keys=(- OP OQ OR OS '[15~' '[17~' '[18~' '[19~' '[20~' '[21~') + +remember () +{ + echo "$@" >> $HISTFILE + echo \"\\e${keys[$fnum]}\":\"\\C-k \\C-u"$@"\" >> $talkdir/bindings + ((fnum++)) +} + +terminal () +{ + chmod -w $HISTFILE + /bin/bash --rcfile $talkdir/bashrc "$@" +} diff --git a/2015-virt-tools/redhat.png b/2015-virt-tools/redhat.png new file mode 100644 index 0000000..f50076a Binary files /dev/null and b/2015-virt-tools/redhat.png differ diff --git a/2015-virt-tools/run b/2015-virt-tools/run new file mode 100755 index 0000000..9a80550 --- /dev/null +++ b/2015-virt-tools/run @@ -0,0 +1,46 @@ +#!/bin/bash - +# Run the talk. + +set -e + +# Avoid GNOME keyring stupidity +export GNOME_KEYRING_CONTROL= +export GNOME_KEYRING_PID= + +# Clean up everything. +find -name '*~' -delete +rm -f [1-9]000-*.d/* + +# No proxy. +#unset http_proxy +#unset https_proxy +#unset ftp_proxy + +# Get everything into the cache. +guestfish -a /dev/null run || exit 1 + +# If not 'quick mode', create the initial images. +if [ "$1" != "--quick" ]; then + pushd 1000-virt-resize.d + virt-builder --format qcow2 fedora-22 + popd + + pushd 2000-virt-sparsify.d + qemu-img convert ../1000-virt-resize.d/fedora-22.qcow2 -O raw -o preallocation=falloc fedora-22.img + popd + + pushd 3000-virt-customize.d + qemu-img convert ../1000-virt-resize.d/fedora-22.qcow2 -O raw fedora-22.img + popd + + pushd 4000-virt-sysprep.d + qemu-img convert ../1000-virt-resize.d/fedora-22.qcow2 -O raw fedora-22.img + popd + + pushd 5000-virt-builder.d + popd +fi + +# Run techtalk. +#techtalk-pse +~/d/techtalk-pse/techtalk-pse diff --git a/2015-virt-tools/style.css b/2015-virt-tools/style.css new file mode 100644 index 0000000..4a33b8f --- /dev/null +++ b/2015-virt-tools/style.css @@ -0,0 +1,67 @@ +/* Red Hat red is rgb(204,0,0). */ + +body { + background: url(redhat.png) no-repeat; + background-position: 98% 0; + /* font-size: 28pt; */ /* For max */ + font-size: 20pt; /* For 1024x768 */ + /* font-family: liberation, helvetica; */ + font-family: helvetica; +} + +body td, body th { /* why?? */ + font-size: 24pt; + padding-bottom: 8px; +} + +h1 { + color: rgb(204,0,0); + /*font-size: 48px;*/ + font-size: 40px; + top: 8; + left: 0; + border-bottom: 2px solid rgb(204,0,0); +} + +b { + color: rgb(204,0,0); +} + +div#titlepage { + margin-top: 100px; + text-align: center; +} + +div#titlepage p.title { + color: rgb(204,0,0); + font-weight: bold; + font-size: 48px; +} + +div#titlepage author { + font-size: 36px; +} + +/* Code */ +pre.code { + margin-left: 1em; + background: #eee; +} + +code { + color: rgb(204,0,0); +} + +/* Bullet points */ +li { + padding-bottom: 16px; +} + +/* Logo */ +img#fish { + position: absolute; + top: 128px; + right: 32px; + width: 200px; + /*height: 256px;*/ +} \ No newline at end of file