Add RAID viewer.
[libguestfs-talks.git] / 2015-virt-tools / NOTES
1 virt-resize, virt-sparsify, virt-customize, virt-sysprep, virt-builder
2 ----------------------------------------------------------------------
3
4 Audience:
5
6  - Interested in manipulating disk images.
7  - May be familiar with disk images, formats, but may not be.
8  - Not developers.
9
10
11 0000: Introduction
12 ----------------------------------------------------------------------
13
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.
16
17 Virt tools use libguestfs, qemu, qemu-img and many other programs and
18 perform operations that would hard to do by hand.
19
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
24 teach.
25
26
27 1000: Resizing a disk image
28 ----------------------------------------------------------------------
29
30 Show a disk image, use 'qemu-img info' to get data about it.
31
32   $ qemu-img info fedora-22.qcow2
33
34 --> Format
35 --> Size : virtual and physical may not be related
36
37 What the guest would see when booted up:
38
39   $ virt-df -a fedora-22.qcow2 -h
40
41 Always use 'qemu-img info', not 'ls -l'.
42
43 What if the guest needs more space?
44 There are various ways to resize a disk image:
45
46  - Just make the container bigger ('qemu-img resize' or even 'truncate').
47      But the partitions won't get bigger.   [illustrate with picture]
48
49  - Run a tool inside the guest, like parted.  It won't usually work
50    if the disk is mounted.
51
52  - Run a tool alongside the guest, but still in a VM, eg. PartitionMagic,
53    GParted Live.
54
55  - Use virt-resize on the host for offline resizing.
56
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
60
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.
64
65 Also works for Windows.
66
67
68 2000: Sparsifying a disk image
69 ----------------------------------------------------------------------
70
71 Show a fully allocated disk image, this time with 'ls -lh':
72
73   $ qemu-img info fedora-22.img
74   $ du -sh fedora-22.img
75   $ virt-df -a fedora-22.img -h
76
77 Sparsify it in place:
78
79   $ virt-sparsify --inplace fedora-22.img
80   $ qemu-img info fedora-22.img
81   $ du -sh fedora-22.img
82
83 Explain the two modes for sparsification.
84
85 Also works for Windows.
86
87
88 3000: Customizing a disk image
89 ----------------------------------------------------------------------
90
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.
94
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
97
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
100 next boot.
101
102
103 4000: Sysprepping a disk image
104 ----------------------------------------------------------------------
105
106 SYSPREP.EXE is a Microsoft proprietary program for preparing a Windows
107 system for duplication.  It removes the identity of the system.
108
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.
113
114   $ virt-sysprep -a fedora-22.img
115
116 It runs on the guest in-place.
117
118 It performs a serious of sysprepping operations, which you can read
119 about in the manual.
120
121 There are some operations which are not enabled by default:
122
123   $ virt-sysprep --list-operations
124
125 You'll want to read the manual before using this.
126
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.
132
133
134 5000: Building a disk image
135 ----------------------------------------------------------------------
136
137 Show a diagram of the whole process and how the tools are related.
138
139                 preparing templates for virt-builder
140   virt-install ---> sysprep ---> sparsify ---> compress ---> templates
141   (OS installer)                                             repository
142
143                 running virt-builder as an end user
144   download a template ---> uncompress ---> resize/format ---> customize ---> result
145   or a cloud image
146
147
148   $ virt-builder -l
149   $ virt-builder --notes rhel-7.1
150   $ virt-builder rhel-7.1
151
152 Speed is important!
153
154 Any virt-customize options can be used:
155
156   $ virt-builder rhel-7.1 --install gcc --selinux-relabel
157
158 If you use the --size option, virt-resize is invoked which takes a bit
159 longer:
160
161   $ virt-builder rhel-7.1 --size 20G
162   $ virt-df -a rhel-7.1.img -h
163
164 virt-builder only builds disk images.  It doesn't run them or upload
165 them into glance.
166
167 Other tools have been built around virt-builder.