2015-virt-tools: Don't clean files when run in --quick mode.
[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 1000: Resizing a disk image
12 ----------------------------------------------------------------------
13
14 Show a disk image, use 'qemu-img info' to get data about it.
15
16   $ qemu-img info fedora-22.qcow2
17
18 --> Format
19 --> Size : virtual and physical may not be related
20
21 What the guest would see when booted up:
22
23   $ virt-df -a fedora-22.qcow2 -h
24
25 Always use 'qemu-img info', not 'ls -l'.
26
27 What if the guest needs more space?
28 There are various ways to resize a disk image:
29
30  - Just make the container bigger ('qemu-img resize' or even 'truncate').
31      But the partitions won't get bigger.   [illustrate with picture]
32
33  - Run a tool inside the guest, like parted.  It won't usually work
34    if the disk is mounted.
35
36  - Run a tool alongside the guest, but still in a VM, eg. PartitionMagic,
37    GParted Live.
38
39  - Use virt-resize on the host for offline resizing.
40
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
44
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.
48
49 Also works for Windows.
50
51
52 2000: Sparsifying a disk image
53 ----------------------------------------------------------------------
54
55 Show a fully allocated disk image, this time with 'ls -lh':
56
57   $ qemu-img info fedora-22.img
58   $ du -sh fedora-22.img
59   $ virt-df -a fedora-22.img -h
60
61 Sparsify it in place:
62
63   $ virt-sparsify --inplace fedora-22.img
64   $ qemu-img info fedora-22.img
65   $ du -sh fedora-22.img
66
67 Explain the two modes for sparsification.
68
69 Also works for Windows.
70
71
72 3000: Customizing a disk image
73 ----------------------------------------------------------------------
74
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.
78
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
81
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
84 next boot.
85
86
87 4000: Sysprepping a disk image
88 ----------------------------------------------------------------------
89
90 SYSPREP.EXE is a Microsoft proprietary program for preparing a Windows
91 system for duplication.  It removes the identity of the system.
92
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.
97
98   $ virt-sysprep -a fedora-22.img
99
100 It runs on the guest in-place.
101
102 It performs a serious of sysprepping operations, which you can read
103 about in the manual.
104
105 There are some operations which are not enabled by default:
106
107   $ virt-sysprep --list-operations
108
109 You'll want to read the manual before using this.
110
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.
116
117
118 5000: Building a disk image
119 ----------------------------------------------------------------------
120
121 Show a diagram of the whole process and how the tools are related.
122
123                 preparing templates for virt-builder
124   virt-install ---> sysprep ---> sparsify ---> compress ---> templates
125   (OS installer)                                             repository
126
127                 running virt-builder as an end user
128   download a template ---> uncompress ---> resize/format ---> customize ---> result
129   or a cloud image
130
131
132   $ virt-builder -l
133   $ virt-builder --notes rhel-7.1
134   $ virt-builder rhel-7.1
135
136 Speed is important!
137
138 Any virt-customize options can be used:
139
140   $ virt-builder rhel-7.1 --install gcc --selinux-relabel
141
142 If you use the --size option, virt-resize is invoked which takes a bit
143 longer:
144
145   $ virt-builder rhel-7.1 --size 20G
146   $ virt-df -a rhel-7.1.img -h
147
148 virt-builder only builds disk images.  It doesn't run them or upload
149 them into glance.
150
151 Other tools have been built around virt-builder.