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.
12 ----------------------------------------------------------------------
14 Libguestfs is a fairly low-level C library for accessing disk images.
15 To perform everyday operations we've written "virt tools" over this.
17 Virt tools use libguestfs, qemu, qemu-img and many other programs and
18 perform operations that would hard to do by hand.
20 In the case of virt-resize, the tool does calculations (like partition
21 sizing) that require hard work and experience, so the virt-resize tool
22 captures a lot of knowledge about how not to break Windows bootloaders
23 and how to align partitions for performance that would be hard to
27 1000: Resizing a disk image
28 ----------------------------------------------------------------------
30 Show a disk image, use 'qemu-img info' to get data about it.
32 $ qemu-img info fedora-22.qcow2
35 --> Size : virtual and physical may not be related
37 What the guest would see when booted up:
39 $ virt-df -a fedora-22.qcow2 -h
41 Always use 'qemu-img info', not 'ls -l'.
43 What if the guest needs more space?
44 There are various ways to resize a disk image:
46 - Just make the container bigger ('qemu-img resize' or even 'truncate').
47 But the partitions won't get bigger. [illustrate with picture]
49 - Run a tool inside the guest, like parted. It won't usually work
50 if the disk is mounted.
52 - Run a tool alongside the guest, but still in a VM, eg. PartitionMagic,
55 - Use virt-resize on the host for offline resizing.
57 $ qemu-img create -f qcow2 fedora-22-bigger.qcow2 10G
58 $ virt-resize fedora-22.qcow2 fedora-22-bigger.qcow2 --expand sda3
59 $ virt-df -a fedora-22-bigger.qcow2 -h
61 virt-resize is quite flexible: For example you could give /dev/sda1
62 500 MB and give the rest to /dev/sda3, or you could tell virt-resize
63 to put the new space into an extra partition.
65 Also works for Windows.
68 2000: Sparsifying a disk image
69 ----------------------------------------------------------------------
71 Show a fully allocated disk image, this time with 'ls -lh':
73 $ qemu-img info fedora-22.img
74 $ du -sh fedora-22.img
75 $ virt-df -a fedora-22.img -h
79 $ virt-sparsify --inplace fedora-22.img
80 $ qemu-img info fedora-22.img
81 $ du -sh fedora-22.img
83 Explain the two modes for sparsification.
85 Also works for Windows.
88 3000: Customizing a disk image
89 ----------------------------------------------------------------------
91 The situation is that you have an existing guest operating system, and
92 you want to _offline_ install packages, set the root password, inject
93 files, set the hostname, or about a dozen other things.
95 $ virt-customize -a fedora-22.img --install gcc,gdb --root-password password:123456 --edit /etc/selinux/config:s/^SELINUX=.*/SELINUX=permissive/
96 $ virt-cat -a fedora-22.img /etc/selinux/config
98 Also works for a limited range of operations on Windows. On Windows,
99 most work is done using "firstboot" batch files that run once at the
103 4000: Sysprepping a disk image
104 ----------------------------------------------------------------------
106 SYSPREP.EXE is a Microsoft proprietary program for preparing a Windows
107 system for duplication. It removes the identity of the system.
109 We borrow the name of this program for the next tool, virt-sysprep,
110 which does a similar job for Linux systems, turning them into
111 templates from which you can clone further guests. This is a tool
112 you'll probably either use all the time or never need to use at all.
114 $ virt-sysprep -a fedora-22.img
116 It runs on the guest in-place.
118 It performs a serious of sysprepping operations, which you can read
121 There are some operations which are not enabled by default:
123 $ virt-sysprep --list-operations
125 You'll want to read the manual before using this.
127 This deletes the SSH host keys, because you wouldn't want those to be
128 duplicated across clones. But it can't set up a fresh random seed for
129 each clone. For that you need to set a random seed after the clone,
130 using virt-customize. Virt-builder which I'll talk about next also
131 sets a fresh random seed automatically.
134 5000: Building a disk image
135 ----------------------------------------------------------------------
137 Show a diagram of the whole process and how the tools are related.
139 preparing templates for virt-builder
140 virt-install ---> sysprep ---> sparsify ---> compress ---> templates
141 (OS installer) repository
143 running virt-builder as an end user
144 download a template ---> uncompress ---> resize/format ---> customize ---> result
149 $ virt-builder --notes rhel-7.1
150 $ virt-builder rhel-7.1
154 Any virt-customize options can be used:
156 $ virt-builder rhel-7.1 --install gcc --selinux-relabel
158 If you use the --size option, virt-resize is invoked which takes a bit
161 $ virt-builder rhel-7.1 --size 20G
162 $ virt-df -a rhel-7.1.img -h
164 virt-builder only builds disk images. It doesn't run them or upload
167 Other tools have been built around virt-builder.