1 virt-resize, virt-sparsify, virt-customize, virt-sysprep, virt-builder
2 ----------------------------------------------------------------------
6 - Interested in manipulating disk images.
7 - May be familiar with disk images, formats, but may not be.
11 1000: Resizing a disk image
12 ----------------------------------------------------------------------
14 Show a disk image, use 'qemu-img info' to get data about it.
16 $ qemu-img info fedora-22.qcow2
19 --> Size : virtual and physical may not be related
21 What the guest would see when booted up:
23 $ virt-df -a fedora-22.qcow2 -h
25 Always use 'qemu-img info', not 'ls -l'.
27 What if the guest needs more space?
28 There are various ways to resize a disk image:
30 - Just make the container bigger ('qemu-img resize' or even 'truncate').
31 But the partitions won't get bigger. [illustrate with picture]
33 - Run a tool inside the guest, like parted. It won't usually work
34 if the disk is mounted.
36 - Run a tool alongside the guest, but still in a VM, eg. PartitionMagic,
39 - Use virt-resize on the host for offline resizing.
41 $ qemu-img create -f qcow2 fedora-22-bigger.qcow2 10G
42 $ virt-resize fedora-22.qcow2 fedora-22-bigger.qcow2 --expand sda3
43 $ virt-df -a fedora-22-bigger.qcow2 -h
45 virt-resize is quite flexible: For example you could give /dev/sda1
46 500 MB and give the rest to /dev/sda3, or you could tell virt-resize
47 to put the new space into an extra partition.
49 Also works for Windows.
52 2000: Sparsifying a disk image
53 ----------------------------------------------------------------------
55 Show a fully allocated disk image, this time with 'ls -lh':
57 $ qemu-img info fedora-22.img
58 $ du -sh fedora-22.img
59 $ virt-df -a fedora-22.img -h
63 $ virt-sparsify --inplace fedora-22.img
64 $ qemu-img info fedora-22.img
65 $ du -sh fedora-22.img
67 Explain the two modes for sparsification.
69 Also works for Windows.
72 3000: Customizing a disk image
73 ----------------------------------------------------------------------
75 The situation is that you have an existing guest operating system, and
76 you want to _offline_ install packages, set the root password, inject
77 files, set the hostname, or about a dozen other things.
79 $ virt-customize -a fedora-22.img --install gcc,gdb --root-password password:123456 --edit /etc/selinux/config:s/^SELINUX=.*/SELINUX=permissive/
80 $ virt-cat -a fedora-22.img /etc/selinux/config
82 Also works for a limited range of operations on Windows. On Windows,
83 most work is done using "firstboot" batch files that run once at the
87 4000: Sysprepping a disk image
88 ----------------------------------------------------------------------
90 SYSPREP.EXE is a Microsoft proprietary program for preparing a Windows
91 system for duplication. It removes the identity of the system.
93 We borrow the name of this program for the next tool, virt-sysprep,
94 which does a similar job for Linux systems, turning them into
95 templates from which you can clone further guests. This is a tool
96 you'll probably either use all the time or never need to use at all.
98 $ virt-sysprep -a fedora-22.img
100 It runs on the guest in-place.
102 It performs a serious of sysprepping operations, which you can read
105 There are some operations which are not enabled by default:
107 $ virt-sysprep --list-operations
109 You'll want to read the manual before using this.
111 This deletes the SSH host keys, because you wouldn't want those to be
112 duplicated across clones. But it can't set up a fresh random seed for
113 each clone. For that you need to set a random seed after the clone,
114 using virt-customize. Virt-builder which I'll talk about next also
115 sets a fresh random seed automatically.
118 5000: Building a disk image
119 ----------------------------------------------------------------------
121 Show a diagram of the whole process and how the tools are related.
123 preparing templates for virt-builder
124 virt-install ---> sysprep ---> sparsify ---> compress ---> templates
125 (OS installer) repository
127 running virt-builder as an end user
128 download a template ---> uncompress ---> resize/format ---> customize ---> result
133 $ virt-builder --notes rhel-7.1
134 $ virt-builder rhel-7.1
138 Any virt-customize options can be used:
140 $ virt-builder rhel-7.1 --install gcc --selinux-relabel
142 If you use the --size option, virt-resize is invoked which takes a bit
145 $ virt-builder rhel-7.1 --size 20G
146 $ virt-df -a rhel-7.1.img -h
148 virt-builder only builds disk images. It doesn't run them or upload
151 Other tools have been built around virt-builder.