File: virt-builder.pod

package info (click to toggle)
libguestfs 1%3A1.44.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,932 kB
  • sloc: ansic: 458,017; ml: 51,424; sh: 13,191; java: 9,578; makefile: 7,931; cs: 6,328; haskell: 5,674; python: 3,871; perl: 3,528; erlang: 2,446; xml: 1,347; ruby: 350; pascal: 257; javascript: 157; lex: 135; yacc: 128; cpp: 10
file content (1908 lines) | stat: -rw-r--r-- 55,940 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
=begin html

<img src="virt-builder.svg" width="250"
  style="float: right; clear: right;" />

=end html

=head1 NAME

virt-builder - Build virtual machine images quickly

=head1 SYNOPSIS

 virt-builder os-version
    [-o|--output DISKIMAGE] [--size SIZE] [--format raw|qcow2]
    [--arch ARCHITECTURE] [--attach ISOFILE]
__CUSTOMIZE_SYNOPSIS__

 virt-builder -l|--list [--long] [--list-format short|long|json] [os-version]

 virt-builder --notes os-version

 virt-builder --print-cache

 virt-builder --cache-all-templates

 virt-builder --delete-cache

 virt-builder --get-kernel DISKIMAGE
    [--format raw|qcow2] [--output OUTPUTDIR]

=head1 DESCRIPTION

Virt-builder is a tool for quickly building new virtual machines.  You
can build a variety of VMs for local or cloud use, usually within a
few minutes or less.  Virt-builder also has many ways to customize
these VMs.  Everything is run from the command line and nothing
requires root privileges, so automation and scripting is simple.

Note that virt-builder does not install guests from scratch.  It takes
cleanly prepared, digitally signed OS templates and customizes them.
This approach is used because it is much faster, but if you need to do
fresh installs you may want to look at L<virt-install(1)> and
L<oz-install(1)>.

The easiest way to get started is by looking at the examples in the
next section.

=head1 EXAMPLES

=head2 List the virtual machines available

 virt-builder --list

will list out the operating systems available to install.  A selection
of freely redistributable OSes is available as standard.  You can add
your own too (see below).

After choosing a guest from the list, you may want to see if there
are any installation notes:

 virt-builder --notes fedora-27

=head2 Build a virtual machine

 virt-builder fedora-27

will build a Fedora 25 image for the same architecture as virt-builder
(so running it from an i686 installation will try to build an i686
image, if available).  This will have all default
configuration (minimal size, no user accounts, random root password,
only the bare minimum installed software, etc.).

You I<do not> need to run this command as root.

The first time this runs it has to download the template over the
network, but this gets cached (see L</CACHING>).

The name of the output file is derived from the template name, so
above it will be F<fedora-27.img>.  You can change the output filename
using the I<-o> option:

 virt-builder fedora-27 -o mydisk.img

You can also use the I<-o> option to write to existing devices or
logical volumes.

 virt-builder fedora-27 --format qcow2

As above, but write the output in qcow2 format to F<fedora-27.qcow2>.

 virt-builder fedora-27 --size 20G

As above, but the output size will be 20 GB.  The guest OS is resized
as it is copied to the output (automatically, using
L<virt-resize(1)>).

 virt-builder fedora-27 --arch i686

As above, but using an i686 template, if available.

=head2 Setting the root password

 virt-builder fedora-27 --root-password file:/tmp/rootpw

Create a Fedora 25 image.  The root password is taken from the file
F</tmp/rootpw>.

Note if you I<don’t> set I<--root-password> then the guest is given
a I<random> root password which is printed on stdout.

You can also create user accounts.  See L</USERS AND PASSWORDS> below.

=head2 Set the hostname

 virt-builder fedora-27 --hostname virt.example.com

Set the hostname to C<virt.example.com>.

=head2 Installing software

To install packages from the ordinary (guest) software repository
(eg. dnf or apt):

 virt-builder fedora-27 --install "inkscape,@Xfce Desktop"

(In Fedora, C<@> is used to install groups of packages.  On Debian
you would install a meta-package instead.)

To update the installed packages to the latest version:

 virt-builder debian-7 --update

For guests which use SELinux, like Fedora and Red Hat Enterprise
Linux, you may need to do SELinux relabelling after installing or
updating packages (see L</SELINUX> below):

 virt-builder fedora-27 --update --selinux-relabel

=head2 Customizing the installation

There are many options that let you customize the installation.  These
include: I<--run>/I<--run-command>, which run a shell script or
command while the disk image is being generated and lets you add or
edit files that go into the disk image.
I<--firstboot>/I<--firstboot-command>, which let you add
scripts/commands that are run the first time the guest boots.
I<--edit> to edit files.  I<--upload> to upload files.

For example:

 cat <<'EOF' > /tmp/dnf-update.sh
 dnf -y --best update
 EOF
 
 virt-builder fedora-27 --firstboot /tmp/dnf-update.sh

or simply:

 virt-builder fedora-27 --firstboot-command 'dnf -y --best update'

which makes the L<dnf(8)> C<update> command run once the first time
the guest boots.

Or:

 virt-builder fedora-27 \
   --edit '/etc/dnf/dnf.conf:
             s/gpgcheck=1/gpgcheck=0/'

which edits F</etc/dnf/dnf.conf> inside the disk image (during disk
image creation, long before boot).

You can combine these options, and have multiple options of all types.

=head1 OPTIONS

=over 4

=item B<--help>

Display help.

=item B<--arch> ARCHITECTURE

Use the specified architecture for the output image.  This means
there must be sources providing the requested template for the
requested architecture.

See also L</ARCHITECTURE>.

=item B<--attach> ISOFILE

During the customization phase, the given disk is attached to the
libguestfs appliance.  This is used to provide extra software
repositories or other data for customization.

You probably want to ensure the volume(s) or filesystems in the
attached disks are labelled (or use an ISO volume name) so that you
can mount them by label in your run-scripts:

 mkdir /tmp/mount
 mount LABEL=EXTRA /tmp/mount

You can have multiple I<--attach> options, and the format can be any
disk format (not just an ISO).

See also: I<--run>,
L</Installing packages at build time from a side repository>,
L<genisoimage(1)>, L<virt-make-fs(1)>.

=item B<--attach-format> FORMAT

Specify the disk format for the next I<--attach> option.  The
C<FORMAT> is usually C<raw> or C<qcow2>.  Use C<raw> for ISOs.

=item B<--cache> DIR

=item B<--no-cache>

I<--cache> DIR sets the directory to use/check for cached template
files.  If not set, defaults to either
F<$XDG_CACHE_HOME/virt-builder/> or F<$HOME/.cache/virt-builder/>.

I<--no-cache> disables template caching.

=item B<--cache-all-templates>

Download all templates to the cache and then exit.  See L</CACHING>.

Note this doesn't cache everything.  More templates might be uploaded.
Also this doesn't cache packages (the I<--install>, I<--update> options).

=item B<--check-signature>

=item B<--no-check-signature>

Check/don’t check the digital signature of the OS template.  The
default is to check the signature and exit if it is not correct.
Using I<--no-check-signature> bypasses this check.

See also I<--fingerprint>.

=item B<--colors>

=item B<--colours>

Use ANSI colour sequences to colourize messages.  This is the default
when the output is a tty.  If the output of the program is redirected
to a file, ANSI colour sequences are disabled unless you use this
option.

=item B<--curl> CURL

Specify an alternate L<curl(1)> binary.  You can also use this to add
curl parameters, for example to disable https certificate checks:

 virt-builder --curl "curl --insecure" [...]

=item B<--delete-cache>

Delete the template cache.  See L</CACHING>.

=item B<--no-delete-on-failure>

Don’t delete the output file on failure to build.  You can use this to
debug failures to run scripts.  See L</DEBUGGING BUILDS> for ways to
debug images.

The default is to delete the output file if virt-builder fails (or,
for example, some script that it runs fails).

=item B<--fingerprint> 'AAAA BBBB ...'

Check that the index and templates are signed by the key with the
given fingerprint.  (The fingerprint is a long string, usually written
as 10 groups of 4 hexadecimal digits).

You can give this option multiple times.  If you have multiple source
URLs, then you can have either no fingerprint, one fingerprint or
multiple fingerprints.  If you have multiple, then each must
correspond 1-1 with a source URL.

=item B<--format> qcow2

=item B<--format> raw

For ordinary builds, this selects the output format.  The default is I<raw>.

With I<--get-kernel> this specifies the input format.

To create an old-style qcow2 file (for compatibility with RHEL 6 or
very old qemu E<lt> 1.1), after running virt-builder, use this
command:

 qemu-img amend -f qcow2 -o compat=0.10 output.qcow2

=item B<--get-kernel> IMAGE

This option extracts the kernel and initramfs from a previously built
disk image called C<IMAGE> (in fact it works for any VM disk image,
not just ones built using virt-builder).

Note this method is B<deprecated>: there is a separate tool for this,
L<virt-get-kernel(1)>, which has more options for the file extraction.

The kernel and initramfs are written to the current directory, unless
you also specify the I<--output> C<outputdir> B<directory> name.

The format of the disk image is automatically detected unless you
specify it by using the I<--format> option.

In the case where the guest contains multiple kernels, the one with
the highest version number is chosen.  To extract arbitrary kernels
from the disk image, see L<guestfish(1)>.  To extract the entire
F</boot> directory of a guest, see L<virt-copy-out(1)>.

=item B<--gpg> GPG

Specify an alternate L<gpg(1)> (GNU Privacy Guard) binary.  By default
virt-builder looks for either C<gpg2> or C<gpg> in the C<$PATH>.

You can also use this to add gpg parameters, for example to specify an
alternate home directory:

 virt-builder --gpg "gpg --homedir /tmp" [...]

=item B<-l> [os-version]

=item B<--list> [os-version]

=item B<--list> B<--list-format> format [os-version]

=item B<--list> B<--long> [os-version]

List all the available templates if no guest is specified, or only for the
specified one.

It is possible to choose with I<--list-format> the output format for the list
templates:

=over 4

=item B<short>

The default format, prints only the template identifier and, next to it,
its short description.

=item B<long>

Prints a textual list with the details of the available sources, followed
by the details of the available templates.

=item B<json>

Prints a JSON object with the details of the available sources and
the details of the available templates.

The C<version> key in the main object represents the "compatibility version",
and it is bumped every time the resulting JSON output is incompatible with
the previous versions (for example the structure has changed, or non-optional
keys are no more present).

=back

I<--long> is a shorthand for the C<long> format.

See also: I<--source>, I<--notes>, L</SOURCES OF TEMPLATES>.

=item B<--machine-readable>

=item B<--machine-readable>=format

This option is used to make the output more machine friendly
when being parsed by other programs.  See
L</MACHINE READABLE OUTPUT> below.

=item B<-m> MB

=item B<--memsize> MB

Change the amount of memory allocated to I<--run> scripts.  Increase
this if you find that I<--run> scripts or the I<--install> option are
running out of memory.

The default can be found with this command:

 guestfish get-memsize

=item B<--network>

=item B<--no-network>

Enable or disable network access from the guest during the installation.

Enabled is the default.  Use I<--no-network> to disable access.

The network only allows outgoing connections and has other minor
limitations.  See L<virt-rescue(1)/NETWORK>.

If you use I<--no-network> then certain other options such as
I<--install> will not work.

This does not affect whether the guest can access the network once it
has been booted, because that is controlled by your hypervisor or
cloud environment and has nothing to do with virt-builder.

Generally speaking you should I<not> use I<--no-network>.  But here
are some reasons why you might want to:

=over 4

=item 1.

Because the libguestfs backend that you are using doesn't support the
network.  (See: L<guestfs(3)/BACKEND>).

=item 2.

Any software you need to install comes from an attached ISO, so you
don't need the network.

=item 3.

You don’t want untrusted guest code trying to access your host network
when running virt-builder.  This is particularly an issue when you
don't trust the source of the operating system templates.  (See
L</SECURITY> below).

=item 4.

You don’t have a host network (eg. in secure/restricted environments).

=back

=item B<--no-sync>

Do not sync the output file on exit.

Virt-builder C<fsync>s the output file or disk image when it exits.

The reason is that qemu/KVM’s default caching mode is C<none> or
C<directsync>, both of which bypass the host page cache.  Therefore
these would not work correctly if you immediately started the guest
after running virt-builder - they would not see the complete output
file.  (Note that you should not use these caching modes - they are
fundamentally broken for this and other reasons.)

If you are not using these broken caching modes, you can use
I<--no-sync> to avoid this unnecessary sync and gain considerable
extra performance.

=item B<--notes> os-version

List any notes associated with this guest, then exit (this does not do
the install).

=item B<-o> filename

=item B<--output> filename

Write the output to F<filename>.  If you don’t specify this option,
then the output filename is generated by taking the C<os-version>
string and adding C<.img> (for raw format) or C<.qcow2> (for qcow2
format).

Note that the output filename could be a device, partition or logical
volume.

When used with I<--get-kernel>, this option specifies the output
directory.

=item B<--print-cache>

Print information about the template cache.  See L</CACHING>.

=item B<-q>

=item B<--quiet>

Don’t print ordinary progress messages.

=item B<--size> SIZE

Select the size of the output disk, where the size can be specified
using common names such as C<32G> (32 gigabytes) etc.

Virt-builder will resize filesystems inside the disk image
automatically.

If the size is not specified, then one of two things happens.  If the
output is a file, then the size is the same as the template.  If the
output is a device, partition, etc then the size of that device is
used.

To specify size in bytes, the number must be followed by the lowercase
letter I<b>, eg: S<C<--size 10737418240b>>.

=item B<--smp> N

Enable N E<ge> 2 virtual CPUs for I<--run> scripts to use.

=item B<--source> URL

Set the source URL to look for indexes.

You can give this option multiple times to specify multiple sources.

See also L</SOURCES OF TEMPLATES> below.

Note that you should not point I<--source> to sources that you don’t
trust (unless the source is signed by someone you do trust).  See also
the I<--no-network> option.

=item B<--no-warn-if-partition>

Do not emit a warning if the output device is a partition.  This
warning avoids a common user error when writing to a USB key or
external drive, when you should normally write to the whole device
(S<I<--output /dev/sdX>>), not to a partition on the device
(S<I<--output /dev/sdX1>>).  Use this option to I<suppress> this
warning.

=item B<-v>

=item B<--verbose>

Enable debug messages and/or produce verbose output.

When reporting bugs, use this option and attach the complete output to
your bug report.

=item B<-V>

=item B<--version>

Display version number and exit.

=item B<-x>

Enable tracing of libguestfs API calls.

=back

=head2 Customization options

__CUSTOMIZE_OPTIONS__

=head1 REFERENCE

=head2 INSTALLING PACKAGES

There are several approaches to installing packages or applications in
the guest which have different trade-offs.

=head3 Installing packages at build time

If the guest OS you are installing is similar to the host OS (eg.
both are Linux), and if libguestfs supports network connections, then
you can use I<--install> to install packages like this:

 virt-builder fedora-27 --install inkscape

This uses the guest’s package manager and the host’s network
connection.

=head3 Updating packages at build time

To update the installed packages in the template at build time:

 virt-builder fedora-27 --update

Most of the templates that ship with virt-builder come with a very
minimal selection of packages (known as a "JEOS" or "Just Enough
Operating System"), which are up to date at the time the template is
created, but could be out of date by the time you come to install an
OS from the template.  This option updates those template packages.

=head3 Installing packages at first boot

Another option is to install the packages when the guest first boots:

 virt-builder fedora-27 --firstboot-install inkscape

This uses the guest’s package manager and the guest’s network
connection.

The downsides are that it will take the guest a lot longer to boot
first time, and there’s nothing much you can do if package
installation fails (eg. if a network problem means the guest can't
reach the package repositories).

=head3 Installing packages at build time from a side repository

If the software you want to install is not available in the main
package repository of the guest, then you can add a side repository.
Usually this is presented as an ISO (CD disk image) file containing
extra packages.

You can create the disk image using either L<genisoimage(1)> or
L<virt-make-fs(1)>.  For genisoimage, use a command like this:

 genisoimage -o extra-packages.iso -R -J -V EXTRA cdcontents/

Create a script that mounts the ISO and sets up the repository.  For
dnf, create /tmp/install.sh containing:

 mkdir /tmp/mount
 mount LABEL=EXTRA /tmp/mount
 
 cat <<'EOF' > /etc/yum.repos.d/extra.repo
 [extra]
 name=extra
 baseurl=file:///tmp/mount
 enabled=1
 EOF
 
 dnf -y install famousdatabase

For apt, create /tmp/install.sh containing:

 mkdir /tmp/mount
 mount LABEL=EXTRA /tmp/mount
 
 apt-cdrom -d=/tmp/mount add
 apt-get -y install famousdatabase

Use the I<--attach> option to attach the CD / disk image and the
I<--run> option to run the script:

 virt-builder fedora-27 \
   --attach extra-packages.iso \
   --run /tmp/install.sh

=head2 USERS AND PASSWORDS

The I<--root-password> option is used to change the root password
(otherwise a random password is used).  This option takes a password
C<SELECTOR> in one of the following formats:

=over 4

=item B<--root-password> file:FILENAME

Read the root password from C<FILENAME>.  The whole first line
of this file is the replacement password.  Any other lines are
ignored.  You should create the file with mode 0600 to ensure
no one else can read it.

=item B<--root-password> password:PASSWORD

Set the root password to the literal string C<PASSWORD>.

B<Note: this is not secure> since any user on the same machine can
see the cleartext password using L<ps(1)>.

=item B<--root-password> random

Choose a random password, which is printed on stdout.  The password
has approximately 120 bits of randomness.

This is the default.

=item B<--root-password> disabled

The root account password is disabled.  This is like putting C<*>
in the password field.

=item B<--root-password> locked:file:FILENAME

=item B<--root-password> locked:password:PASSWORD

=item B<--root-password> locked:random

The root account is locked, but a password is placed on the
account.  If first unlocked (using C<passwd -u>) then logins will
use the given password.

=item B<--root-password> locked

=item B<--root-password> locked:disabled

The root account is locked I<and> password is disabled.

=back

=head3 Creating user accounts

To create user accounts, use the L<useradd(8)> command with
L<--firstboot-command> like this:

 virt-builder --firstboot-command \
    'useradd -m -p "" rjones ; chage -d 0 rjones'

The above command will create an C<rjones> account with no password,
and force the user to set a password when they first log in.  There
are other ways to manage passwords, see L<useradd(8)> for details.

=head2 KEYBOARD LAYOUT

Because there are so many different ways to set the keyboard layout in
Linux distributions, virt-builder does not yet attempt to have a
simple command line option.  This section describes how to set the
keyboard for some common Linux distributions.

=head3 Keyboard layout with systemd

For distros that use systemd C<localectl>, use a command like this:

 virt-builder fedora-27 \
   --firstboot-command 'localectl set-keymap uk'

See L<localectl(1)> and
L<https://www.happyassassin.net/2013/11/23/keyboard-layouts-in-fedora-20-and-previously/>
for more details.

=head3 Keyboard layout using F</etc/sysconfig/keyboard>

For RHEL E<le> 6, Fedora E<le> 18 and similar, upload or modify the
keyboard configuration file using the I<--upload>, I<--write> or
I<--edit> options.  For example:

 virt-builder centos-6 \
   --edit '/etc/sysconfig/keyboard: s/^KEYTABLE=.*/KEYTABLE="uk"/'

The format of this file can be found documented in many places online.

=head3 Keyboard layout with Debian-derived distros

For Debian-derived distros using F</etc/default/keyboard>, upload or
modify the keyboard file using the I<--upload>, I<--write> or
I<--edit> options.  For example:

 virt-builder debian-8 \
   --edit '/etc/default/keyboard: s/^XKBLAYOUT=.*/XKBLAYOUT="gb"/'

See L<https://wiki.debian.org/Keyboard>.

=head2 LANGUAGE

Most Linux distributions support multiple locale settings so that you
can have guest messages printed in another language such as Russian.

However there is no single setting which controls this, since extra
packages may need to be installed to support console and X fonts, and
keyboard input methods.  The packages required, and their
configuration is highly distro-specific, and it is outside the scope
of virt-builder to do this.

This section contains examples for some common Linux distributions.

=head3 Setting Japanese in Fedora 25

 virt-builder fedora-27 \
   --size 20G \
   --update \
   --install @japanese-support \
   --install @xfce \
   --install xorg-x11-server-Xorg,xorg-x11-drivers,rsyslog \
   --link /usr/lib/systemd/system/graphical.target:/etc/systemd/system/default.target \
   --firstboot-command 'localectl set-locale LANG=ja_JP.utf8' \
   --firstboot-command 'localectl set-keymap jp' \
   --firstboot-command 'systemctl isolate graphical.target'

=head3 Setting Japanese in Debian 8 (Jessie)

Note that although this enables Japanese in the text console too, it
is unlikely that you will see properly rendered Japanese there.
However Japanese is properly rendered in X applications and terminals.

 pkgs=locales,xfce4,\
 ibus,ibus-anthy,\
 fonts-ipafont-gothic,fonts-ipafont-mincho,\
 fonts-takao-mincho,\
 xfonts-intl-japanese,xfonts-intl-japanese-big,\
 iceweasel-l10n-ja,manpages-ja
 
 virt-builder debian-8 \
   --size 20G \
   --install $pkgs \
   --edit '/etc/locale.gen: s,^#\s*ja,ja,' \
   --write '/etc/default/locale:LANG="ja_JP.UTF-8"' \
   --run-command "locale-gen"

=head2 LOG FILE

Scripts and package installation that runs at build time (I<--run>,
I<--run-command>, I<--install>, I<--update>, but I<not> firstboot) is
logged in one of the following locations:

=over 4

=item F</tmp/builder.log>

On Linux, BSD, and other non-Windows guests.

=item F<C:\Temp\builder.log>

On Windows, DOS guests.

=item F</builder.log>

If F</tmp> or F<C:\Temp> is missing.

=back

If you don’t want the log file to appear in the final image, then
use the I<--no-logfile> command line option.

=head2 SSH KEYS

The I<--ssh-inject> option is used to inject ssh keys for users in
the guest, so they can login without supplying a password.

The C<SELECTOR> part of the option value is optional; in this case,
I<--ssh-inject> C<USER> means that we look in the I<current>
user’s F<~/.ssh> directory to find the default public ID file.  That
key is uploaded.  "default public ID" is the I<default_ID_file> file
described in L<ssh-copy-id(1)>.

If specified, the C<SELECTOR> can be in one of the following formats:

=over 4

=item B<--ssh-inject> USER:file:FILENAME

Read the ssh key from F<FILENAME>.  F<FILENAME> is usually a I<.pub>
file.

=item B<--ssh-inject> USER:string:KEY_STRING

Use the specified C<KEY_STRING>.  C<KEY_STRING> is usually a public
string like I<ssh-rsa AAAA.... user@localhost>.

=back

In any case, the F<~USER/.ssh> directory and the
F<~USER/.ssh/authorized_keys> file will be created if not existing
already.

=head2 FIRST BOOT SCRIPTS

The I<--firstboot> and I<--firstboot-command> options allow you to
execute commands at the first boot of the guest.  To do so, an init
script for the guest init system is installed, which takes care of
running all the added scripts and commands.

Supported operating systems are:

=over 4

=item Linux

Init systems supported are: systemd, System-V init (known also as sysvinit),
and Upstart (using the System-V scripts).

Note that usually init scripts run as root, but with a more limited
environment than what could be available from a normal shell:
for example, C<$HOME> may be unset or empty.

The output of the first boot scripts is available in the guest as
F<~root/virt-sysprep-firstboot.log>.

=item Windows

F<rhsrvany.exe>, available from sources at
L<https://github.com/rwmjones/rhsrvany>, or F<pvvxsvc.exe>, available
with SUSE VMDP is installed to run the
first boot scripts.  It is required, and the setup of first boot
scripts will fail if it is not present.

F<rhsrvany.exe> or F<pvvxsvc.exe> is copied from the location pointed to by the
C<VIRT_TOOLS_DATA_DIR> environment variable; if not set, a compiled-in
default will be used (something like F</usr/share/virt-tools>).

The output of the first boot scripts is available in the guest as
F<C:\Program Files\Guestfs\Firstboot\log.txt>.

=back

=head2 SUBSCRIPTION-MANAGER

It is possible to automate the registration and attaching of the
system using C<subscription-manager>.  This is typical on
Red Hat Enterprise Linux guests.  There are few options which ease
this process, avoid executing commands manually and exposing
passwords on command line.

I<--sm-register> starts the registration process, and requires
I<--sm-credentials> to be specified; the format of the C<SELECTOR>
of I<--sm-credentials> is one of the following formats:

=over 4

=item B<--sm-credentials> USER:file:FILENAME

Read the password for the specified C<USER> from F<FILENAME>.

=item B<--sm-credentials> USER:password:PASSWORD

Use the literal string C<PASSWORD> for the specified C<USER>.

=back

I<--sm-attach> attaches the system to subscriptions; the format
of its C<SELECTOR> is one of the following:

=over 4

=item B<--sm-attach> auto

C<subscription-manager> attaches to the best-fitting subscriptions
for the system.

=item B<--sm-attach> file:FILENAME

Read the pool ID from F<FILENAME>.

=item B<--sm-attach> pool:POOL

Use the literal string C<POOL> as pool ID.

=back

I<--sm-remove> removes all the subscriptions from the guest, while
I<--sm-unregister> completely unregister the system.

=head2 INSTALLATION PROCESS

When you invoke virt-builder, installation proceeds as follows:

=over 4

=item *

The template image is downloaded.

If the template image is present in the cache, the cached version
is used instead.  (See L</CACHING>).

=item *

The template signature is checked.

=item *

The template is uncompressed to a tmp file.

=item *

The template image is resized into the destination, using
L<virt-resize(1)>.

=item *

Extra disks are attached (I<--attach>).

=item *

A new random seed is generated for the guest.

=item *

Guest customization is performed, in the order specified on the
command line.

=item *

SELinux relabelling is done (I<--selinux-relabel>).

=back

=head2 IMPORTING THE DISK IMAGE

=head3 Importing into libvirt

Import the disk image into libvirt using L<virt-install(1)>
I<--import> option.

 virt-install --import \
   --name guest --ram 2048 \
   --disk path=disk.img,format=raw --os-variant fedora27

Notes:

=over 4

=item 1.

You I<must> specify the correct format.  The format is C<raw> unless
you used virt-builder’s I<--format> option.

=item 2.

I<--os-variant> is highly recommended, because it will present optimum
devices to enable the guest to run most efficiently.  To get a list
of all variants, do:

 osinfo-query os

The above tool is provided by libosinfo package.

=item 3.

You can run virt-install as root or non-root.  Each works slightly
differently because libvirt manages a different set of virtual
machines for each user.  In particular virt-manager normally shows the
root-owned VMs, whereas Boxes shows the user-owned VMs, and other
tools probably work differently as well.

=back

=head3 Importing into OpenStack

Import the image into Glance (the OpenStack image store) by doing:

 glance image-create --name fedora-27-image --file fedora-27.img \
   --disk-format raw --container-format bare \
   --is-public True

The I<--file> parameter is the virt-builder-generated disk image.  It
should match virt-builder’s I<--output> option.  The I<--disk-format>
parameter should match virt-builder’s I<--format> option (or C<raw> if
you didn't use that option).  The I<--container-format> should always
be C<bare> since virt-builder doesn't put images into containers.

You can use the S<C<glance image-show I<fedora-27-image>>> command to
display the properties of the image.

To boot up an instance of your image on a Nova compute node, do:

 nova boot fedora-27-server --image fedora-27-image \
   --flavor m1.medium

Use S<C<nova flavor-list>> to list possible machine flavors.  Use
S<C<nova list>> to list running instances.

=head3 Booting directly using qemu or KVM

The qemu command line is not very stable or easy to use, hence libvirt
should be used if possible.  However a command line similar to the
following could be used to boot the virtual machine:

 qemu-system-x86_64 \
   -machine accel=kvm:tcg \
   -cpu host \
   -m 2048 \
   -drive file=disk.img,format=raw,if=virtio

As with libvirt, it is very important that the correct format is
chosen.  It will be C<raw> unless the I<--format> option was used.

=head2 CONFIGURATION MANAGEMENT

=head3 Puppet

To enable the Puppet agent in a guest, install the package, point
the configuration at your Puppetmaster, and ensure the agent runs
at boot.

A typical virt-builder command would be:

 virt-builder fedora-27 \
   --hostname client.example.com \
   --update \
   --install puppet \
   --append-line '/etc/puppet/puppet.conf:[agent]' \
   --append-line '/etc/puppet/puppet.conf:server = puppetmaster.example.com/' \
   --run-command 'systemctl enable puppet' \
   --selinux-relabel

The precise instructions vary according to the Linux distro.  For
further information see:
L<https://docs.puppet.com/puppet/latest/install_pre.html>

=head2 DEBUGGING BUILDS

If virt-builder itself fails, then enable debugging (I<-v>) and report
a bug (see L</BUGS> below).

If virt-builder fails because some script or package it is installing
fails, try using I<--no-delete-on-failure> to preserve the output
file, and continue reading this section.

If virt-builder is successful but the image doesn't work, here are
some things to try:

=over 4

=item Use virt-rescue

Run L<virt-rescue(1)> on the disk image:

 virt-rescue -a disk.img

This gives you a rescue shell.  You can mount the filesystems from the
disk image on F</sysroot> and examine them using ordinary Linux
commands.  You can also chroot into the guest to reinstall the
bootloader.  The virt-rescue man page has a lot more information and
examples.

=item Use guestfish

Run L<guestfish(1)> on the disk image:

 guestfish -a disk.img -i

Use guestfish commands like C<ll /directory> and C<cat /file> to
examine directories and files.

=item Use guestmount

Mount the disk image safely on the host using FUSE and L<guestmount(1)>:

 mkdir /tmp/mp
 guestmount -a disk.img -i /tmp/mp
 cd /tmp/mp

To unmount the disk image do:

 fusermount -u /tmp/mp

=item Add a serial console

If the guest hangs during boot, it can be helpful to add a serial
console to the guest, and direct kernel messages to the serial
console.  Adding the serial console will involve looking at the
documentation for your hypervisor.  To direct kernel messages to the
serial console, add the following on the kernel command line:

 console=tty0 console=ttyS0,115200

=back

=head2 SOURCES OF TEMPLATES

virt-builder reads the available sources from configuration files,
with the I<.conf> extension and located in the following paths:

=over 4

=item *

$XDG_CONFIG_HOME/virt-builder/repos.d/ (C<$XDG_CONFIG_HOME> is
F<$HOME/.config> if not set).

=item *

$XDG_CONFIG_DIRS/virt-builder/repos.d/ (where C<$XDG_CONFIG_DIRS>
means any of the directories in that environment variable, or just F</etc/xdg>
if not set)

=back

Each I<.conf> file in those paths has a simple text format like the
following:

 [libguestfs.org]
 uri=http://libguestfs.org/download/builder/index.asc
 gpgkey=file:///etc/xdg/virt-builder/repos.d/libguestfs.gpg

The part in square brackets is the repository identifier, which is
used as unique identifier.

The following fields can appear:

=over 4

=item C<uri=URI>

The URI of the index file which this repository refers to.

This field is required.

=item C<gpgkey=URI>

This optional field represents the URI (although only I<file://> URIs
are accepted) of the key used to sign the index file.
If not present, the index file referred by I<uri=..> is not signed.

=item C<proxy=MODE>

This optional field specifies the proxy mode, to be used when downloading
the index file of this repository.  The possible values are:

=over 4

=item B<no>, B<off>

No proxy is being used at all, even overriding the system configuration.

=item B<system>

The proxy used is the system one.

=item I<anything else>

Specifies the actual proxy configuration to be used, overriding the system
configuration.

=back

If not present, the assumed value is to respect the proxy settings of the
system (i.e. as if B<system> would be specified).

=item C<format=FORMAT>

This optional field specifies the format of the repository.
The possible values are:

=over 4

=item B<native>

The native format of the C<virt-builder> repository.  See also
L</Creating and signing the index file> below.

=item B<simplestreams>

The URI represents the root of a Simple Streams v1.0 tree of metadata.

For more information about Simple Streams, see also
L<https://launchpad.net/simplestreams>.

=back

If not present, the assumed value is C<native>.

=back

For serious virt-builder use, you may want to create your own
repository of templates.

=head3 Libguestfs.org repository

Out of the box, virt-builder downloads the file
L<http://libguestfs.org/download/builder/index.asc> which is an index
of available templates plus some information about each one, wrapped
up in a digital signature.  The command C<virt-builder --list> lists
out the information in this index file.

The templates hosted on libguestfs.org were created using shell
scripts, kickstart files and preseed files which can be found in the
libguestfs source tree, in C<builder/templates>.

=head3 Setting up the repository

You can set up your own site containing an index file and some
templates, and then point virt-builder at the site by creating a
I<.conf> file pointing to it.

Note that if your index is signed, you will need to properly fill
I<gpgkey=..> in your I<.conf> file, making sure to deploy also the
GPG key file.

 virt-builder --source https://example.com/builder/index.asc \
    --fingerprint 'AAAA BBBB ...' \
    --list

You can host this on any web or FTP server, or a local or network
filesystem.

=head3 Setting up a GPG key

If you don’t have a GnuPG key, you will need to set one up.  (Strictly
speaking this is optional, but if your index and template files are
not signed then virt-builder users will have to use the
I<--no-check-signature> flag every time they use virt-builder.)

To create a key, see the GPG manual
L<http://www.gnupg.org/gph/en/manual.html>.

Export your GPG public key:

 gpg --export -a "you@example.com" > pubkey
 
=head3 Create the templates

There are many ways to create the templates.  For example you could
clone existing guests (see L<virt-sysprep(1)>), or you could install a
guest by hand (L<virt-install(1)>).  To see how the templates were
created for virt-builder, look at the scripts in C<builder/templates>

Virt-builder supports any image format (e.g. raw, qcow2, etc) as
template, both as-is, and compressed as XZ.  This way, existing images
(e.g. cleaned using L<virt-sysprep(1)>) can be used as templates.

For best results when compressing the templates, use the following xz
options (see L<nbdkit-xz-plugin(1)> for further explanation):

 xz --best --block-size=16777216 disk

=head3 Creating and signing the index file

The index file has a simple text format (shown here without the
digital signature):

 [fedora-18]
 name=Fedora® 18
 osinfo=fedora18
 arch=x86_64
 file=fedora-18.xz
 checksum[sha512]=...
 format=raw
 size=6442450944
 compressed_size=148947524
 expand=/dev/sda3
 
 [fedora-19]
 name=Fedora® 19
 osinfo=fedora19
 arch=x86_64
 file=fedora-19.xz
 checksum[sha512]=...
 revision=3
 format=raw
 size=4294967296
 compressed_size=172190964
 expand=/dev/sda3

The part in square brackets is the C<os-version>, which is the same
string that is used on the virt-builder command line to build that OS.

The index file creation and signature can be eased with the
L<virt-builder-repository(1)> tool.

After preparing the C<index> file in the correct format, clearsign it
using the following command:

 gpg --clearsign --armor index

This will create the final file called F<index.asc> which can be
uploaded to the server (and is the I<uri=..> URL).  As noted above,
signing the index file is optional, but recommended.

The following fields can appear:

=over 4

=item C<name=NAME>

The user-friendly name of this template.  This is displayed in the
I<--list> output but is otherwise not significant.

=item C<osinfo=ID>

This optional field maps the operating system to the associated
libosinfo ID.  Virt-builder does not use it (yet).

=item C<arch=ARCH>

The architecture of the operating system installed within the
template. This field is required.

=item C<file=PATH>

The path (relative to the index) of the xz-compressed template.

Note that absolute paths or URIs are B<not> permitted here.  This is
because virt-builder has a "same origin" policy for templates so they
cannot come from other servers.

=item C<sig=PATH>

B<This option is deprecated>.  Use the checksum field instead.

The path (relative to the index) of the GPG detached signature of the
xz file.

Note that absolute paths or URIs are B<not> permitted here.  This is
because virt-builder has a "same origin" policy for templates so they
cannot come from other servers.

The file can be created as follows:

 gpg --detach-sign --armor -o disk.xz.sig disk.xz

=item C<checksum[sha512]=7b882fe9b82eb0fef...>

The SHA-512 checksum of the file specified in I<file=..> is checked
after it is downloaded.  To work out the signature, do:

 sha512sum disk.xz

Note if you use this, you don’t need to sign the file, ie. don’t use
C<sig>.  This option overrides C<sig>.

=item C<checksum=7b882fe9b82eb0fef...>

C<checksum> is an alias for C<checksum[sha512]>.

If you need to interoperate with virt-builder = 1.24.0 then you have
to use C<checksum> because that version would give a parse error with
square brackets and numbers in the key of a field.  This is fixed in
virt-builder E<ge> 1.24.1.

=item C<revision=N>

The revision is an integer which is used to control the template
cache.  Increasing the revision number causes clients to download the
template again even if they have a copy in the cache.

The revision number is optional.  If omitted it defaults to C<1>.

=item C<format=raw>

=item C<format=qcow2>

Specify the format of the disk image; in case it is compressed, that
is the format before the compression.  If not given, the format is
autodetected, but generally it is better to be explicit about the
intended format.

Note this is the source format, which is different from the
I<--format> option (requested output format).  Virt-builder does
on-the-fly conversion from the source format to the requested output
format.

=item C<size=NNN>

The virtual size of the image in bytes.  This is the size of the image
when uncompressed.  If using a non-raw format such as qcow2 then it
means the virtual disk size, not the size of the qcow2 file.

This field is required.

Virt-builder also uses this as the minimum size that users can request
via the I<--size> option, or as the default size if there is no
I<--size> option.

=item C<compressed_size=NNN>

The actual size of the disk image in bytes, i.e. what was specified
in I<file=..>.  This is just used for information (when using C<long>,
and C<json> formats of I<--list>).

=item C<expand=/dev/sdaX>

When expanding the image to its final size, instruct L<virt-resize(1)>
to expand the named partition in the guest image to fill up all
available space.  This works like the virt-resize I<--expand> option.

You should usually put the device name of the guest’s root filesystem here.

It’s a good idea to use this, but not required.  If the field is
omitted then virt-resize will create an extra partition at the end of
the disk to cover the free space, which is much less user-friendly.

=item C<lvexpand=/dev/VolGroup/LogVol>

When expanding the image to its final size, instruct L<virt-resize(1)>
to expand the named logical volume in the guest image to fill up all
available space.  This works like the virt-resize I<--lv-expand> option.

If the guest uses LVM2 you should usually put the LV of the guest’s
root filesystem here.  If the guest does not use LVM2 or its root
filesystem is not on an LV, don't use this option.

=item C<notes=NOTES>

Any notes that go with this image, especially notes describing what
packages are in the image, how the image was prepared, and licensing
information.

This information is shown in the I<--notes> and I<--list> I<--long> modes.

You can use multi-line notes here by indenting each new line with at
least one character of whitespace (even on blank lines):

 notes=This image was prepared using
  the following kickstart script:
                                <-- one space at beginning of line
  part /boot --fstype ext3
  ...

=item C<hidden=true>

Using the hidden flag prevents the template from being listed by the
I<--list> option (but it is still installable).  This is used for test
images.

=item C<aliases=ALIAS1 ALIAS2 ...>

This optional field specifies a list of aliases, separated by spaces,
for the image.  For example, an alias could be used to always point
to the latest version of a certain image, leaving the old versions
available in the index instead of updating the same image (see the
C<revision> field).

=back

=head3 Running virt-builder against multiple sources

It is possible to use multiple sources with virt-builder.
The recommended way is to deploy I<.conf> files pointing to the
index files. Another way is to specify the sources using
multiple I<--source> and/or I<--fingerprint> options:

 virt-builder \
   --source http://example.com/s1/index.asc \
   --source http://example.com/s2/index.asc

You can provide N or 1 fingerprints.  In the case where you
provide N fingerprints, N = number of sources and there is a 1-1
correspondence between each source and each fingerprint:

 virt-builder \
   --source http://example.com/s1/index.asc --fingerprint '0123 ...' \
   --source http://example.com/s2/index.asc --fingerprint '9876 ...'

In the case where you provide 1 fingerprint, the same fingerprint
is used for all sources.

You C<must> provide at least 1 fingerprint.

=head3 Licensing of templates

You should be aware of the licensing of images that you distribute.
For open source guests, provide a link to the source code in the
C<notes> field and comply with other requirements (eg. around
trademarks).

=head3 Formal specification of the index file

The index file format has a formal specification defined by the flex
scanner and bison parser used to parse the file.  This can be found in
the following files in the libguestfs source tree:

 builder/index-scan.l
 builder/index-parse.y

A tool called L<virt-index-validate(1)> is available to validate the
index file to ensure it is correct.

Note that the parser and tool can work on either the signed or
unsigned index file (ie. F<index> or F<index.asc>).

The index is always encoded in UTF-8.

=head2 CACHING

=head3 Caching templates

Since the templates are usually very large, downloaded templates are
cached in the user’s home directory.

The location of the cache is F<$XDG_CACHE_HOME/virt-builder/> or
F<$HOME/.cache/virt-builder>.

You can print out information about the cache directory, including
which guests are currently cached, by doing:

 virt-builder --print-cache

The cache can be deleted if you want to save space by doing:

 virt-builder --delete-cache

You can download all (current) templates to the local cache by doing:

 virt-builder --cache-all-templates

To disable the template cache, use I<--no-cache>.

Only templates are cached.  The index and detached digital signatures
are not cached.

=head3 Caching packages

Virt-builder uses L<curl(1)> to download files and it also uses the
current C<http_proxy> (etc) settings when installing packages
(I<--install>, I<--update>).

You may therefore want to set those environment variables in order to
maximize the amount of local caching that happens.  See
L</ENVIRONMENT VARIABLES> and L<curl(1)>.

=head3 Local mirrors

To increase both speed and reliability of installing packages, you can
set up a local mirror of the target distribution, and point the guest
package manager at that.

=head4 Using a local mirror with Fedora

To install a Fedora guest using a local mirror:

 virt-builder fedora-27 \
   --edit '/etc/yum.repos.d/fedora.repo:
       s{.*baseurl=.*}{baseurl=http://example.com/mirror/};
       s{.*metalink=.*}{};
   ' \
   --edit '/etc/yum.repos.d/fedora-updates.repo:
       s{.*baseurl=.*}{baseurl=http://example.com/mirror-updates/};
       s{.*metalink=.*}{};
   ' \
   --run-command 'dnf -y update' \
   --install 'pkg1,pkg2,...'

=head4 Using a local mirror with Debian

Assuming that you are using C<apt-proxy> to mirror the repository, you
should create a new F<sources.list> file to point to your proxy (see
L<https://help.ubuntu.com/community/AptProxy>) and then do:

 virt-builder debian-8 \
   --upload sources.list:/etc/apt/sources.list \
   --run-command 'apt-get -y update' \
   --install 'pkg1,pkg2,...'

=head2 DIGITAL SIGNATURES

Virt-builder uses GNU Privacy Guard (GnuPG or gpg) to verify that the
index and templates have not been tampered with.

The source points to an index file, which is optionally signed.

Virt-builder downloads the index and checks that the signature is
valid and the signer’s fingerprint matches the specified fingerprint
(ie. the one specified in I<gpgkey=..> in the I<.conf>, or with
I<--fingerprint>, in that order).

For checking against the built-in public key/fingerprint, this
requires importing the public key into the user’s local gpg keyring
(that’s just the way that gpg works).

When a template is downloaded, its signature is checked in the same
way.

Although the signatures are optional, if you don’t have them then
virt-builder users will have to use I<--no-check-signature> on the
command line.  This prevents an attacker from replacing the signed
index file with an unsigned index file and having virt-builder
silently work without checking the signature.  In any case it is
highly recommended that you always create signed index and templates.

=head2 ARCHITECTURE

Virt-builder can build a guest for any architecture no matter what the
host architecture is.  For example an x86-64 guest on an ARM host.

However certain options may not work, specifically options
that require running commands in the guest during the build process:
I<--install>, I<--update>, I<--run>, I<--run-command>.  You may need
to replace these with their firstboot-equivalents.

An x86-64 host building 32 bit i686 guests should work without any
special steps.

=head2 SECURITY

Virt-builder does not need to run as root (in fact, should not be run
as root), and doesn't use setuid, C<sudo> or any similar mechanism.

I<--install>, I<--update>, I<--run> and I<--run-command> are
implemented using an appliance (a small virtual machine) so these
commands do not run on the host.  If you are using the libguestfs
libvirt backend and have SELinux enabled then the virtual machine is
additionally encapsulated in an SELinux container (sVirt).

However these options will have access to the host’s network and since
the template may contain untrusted code, the code might try to access
host network resources which it should not.  You can use
I<--no-network> to prevent this.

Firstboot commands run in the context of the guest when it is booted,
and so the security of your hypervisor / cloud should be considered.

Virt-builder injects a random seed into every guest which it builds.
This helps to ensure that TCP sequence numbers, UUIDs, ssh host keys
etc are truly random when the guest boots.

You should check digital signatures and not ignore any signing errors.

=head2 CLONES

If you wish to create many new guests of the same type, it is tempting
to run virt-builder once and then copy the output file.  You should
B<not> do this.  You should run virt-builder once for each new guest
you need.

The reason is that each clone needs to have (at least) a separate
random seed, and possibly other unique features (such as filesystem
UUIDs) in future versions of virt-builder.

Another thing you should I<not> do is to boot the guest, then clone
the booted disk image.  The reason is that some guests create unique
machine IDs, SSH host keys and so on at first boot, and you would not
want clones to have duplicate identities.

See also: L<virt-sysprep(1)>.

=head2 PERFORMANCE

The most important aspect of getting good performance is caching.
Templates gets downloaded into the cache the first time they are used,
or if you use the I<--cache-all-templates> option.  See L</CACHING>
above for further information.

Packages required for the I<--install> and I<--update> options are
downloaded using the host network connection.  Setting the
C<http_proxy>, C<https_proxy> and C<ftp_proxy> environment variables
to point to a local web cache may ensure they only need to be
downloaded once.  You can also try using a local package repository,
although this can be complex to set up and varies according to which
Linux distro you are trying to install.

=head3 Using I<--no-sync>

Use I<--no-sync>.  However read the caveats in the L</OPTIONS> section
above, since this can cause disk corruption if not used correctly.

=head3 Skipping virt-resize

Virt-builder can skip the virt-resize step under certain conditions.
This makes virt-builder much faster.  The conditions are:

=over 4

=item *

the output must be a regular file (not a block device), B<and>

=item *

the user did B<not> use the I<--size> option, B<and>

=item *

the output format is the same as the template format (usually raw).

=back

=head3 pxzcat

Virt-builder uses an internal implementation of pxzcat (parallel
xzcat) if liblzma was found at build time.  If liblzma was not found
at build time, regular C<xzcat> is used which is single-threaded.

=head3 User-Mode Linux

You can use virt-builder with the User-Mode Linux (UML) backend.  This
may be faster when running virt-builder inside a virtual machine
(eg. in the cloud).

To enable the UML backend, read the instructions in
L<guestfs(3)/USER-MODE LINUX BACKEND>.

Currently you have to use the I<--no-network> option.  This should be
fixed in a future version.

The qcow2 output format is not supported by UML.  You can only create
raw-format guests.

=head2 SELINUX

Guests which use SELinux (such as Fedora and Red Hat Enterprise Linux)
require that each file has a correct SELinux label.

Virt-builder does not know how to give new files a label, so there are
two possible strategies it can use to ensure correct labelling:

=over 4

=item Using I<--selinux-relabel>

This runs L<setfiles(8)> just before finalizing the guest, which sets
SELinux labels correctly in the disk image.

This is the recommended method.

=item I<--touch> F</.autorelabel>

Guest templates may already contain a file called F</.autorelabel> or
you may touch it.

For guests that use SELinux, this causes L<restorecon(8)> to run at
first boot.  Guests will reboot themselves once the first time you use
them, which is normal and harmless.

=back

Please note that if your guest uses SELinux, and you are doing operations
on it which might create new files or change existing ones, you are
recommended to use I<--selinux-relabel>.  This will help in making sure
that files have the right SELinux labels.

=head1 MACHINE READABLE OUTPUT

The I<--machine-readable> option can be used to make the output more
machine friendly, which is useful when calling virt-builder from other
programs, GUIs etc.

Use the option on its own to query the capabilities of the
virt-builder binary.  Typical output looks like this:

 $ virt-builder --machine-readable
 virt-builder
 arch
 config-file
 customize
 json-list
 pxzcat

A list of features is printed, one per line, and the program exits
with status 0.

It is possible to specify a format string for controlling the output;
see L<guestfs(3)/ADVANCED MACHINE READABLE OUTPUT>.

=head1 ENVIRONMENT VARIABLES

For other environment variables which affect all libguestfs programs,
see L<guestfs(3)/ENVIRONMENT VARIABLES>.

=over 4

=item C<http_proxy>

=item C<https_proxy>

=item C<no_proxy>

Set the proxy for downloads.  These environment variables (and more)
are actually interpreted by L<curl(1)>, not virt-builder.

=item C<HOME>

Used to determine the location of the template cache, and the location
of the user' sources.  See L</CACHING> and L</SOURCES OF TEMPLATES>.

=item C<VIRT_TOOLS_DATA_DIR>

This can point to the directory containing data files used for Windows
firstboot installation.

Normally you do not need to set this.  If not set, a compiled-in
default will be used (something like F</usr/share/virt-tools>).

This directory may contain the following files:

=over 4

=item F<rhsrvany.exe>

This is the RHSrvAny Windows binary, used to install a "firstboot"
script in Windows guests.  It is required if you intend to use the
I<--firstboot> or I<--firstboot-command> options with Windows guests.

See also: C<https://github.com/rwmjones/rhsrvany>

=item F<pvvxsvc.exe>

This is a Windows binary shipped with SUSE VMDP, used to install a "firstboot"
script in Windows guests.  It is required if you intend to use the
I<--firstboot> or I<--firstboot-command> options with Windows guests.

=back

=item C<XDG_CACHE_HOME>

Used to determine the location of the template cache.  See L</CACHING>.

=item C<XDG_CONFIG_HOME>

Used to determine the location of the user' sources.  See
L</SOURCES OF TEMPLATES>.

=item C<XDG_CONFIG_DIRS>

Used to determine the location of the system sources.  See
L</SOURCES OF TEMPLATES>.

=back

=head1 EXIT STATUS

This program returns 0 if successful, or non-zero if there was an
error.

=head1 SEE ALSO

L<guestfs(3)>,
L<guestfish(1)>,
L<guestmount(1)>,
L<virt-builder-repository(1)>,
L<virt-copy-out(1)>,
L<virt-customize(1)>,
L<virt-get-kernel(1)>,
L<virt-install(1)>,
L<virt-rescue(1)>,
L<virt-resize(1)>,
L<virt-sysprep(1)>,
L<oz-install(1)>,
L<gpg(1)>,
L<gpg2(1)>,
L<curl(1)>,
L<virt-make-fs(1)>,
L<genisoimage(1)>,
L<http://libguestfs.org/>.

=head1 AUTHOR

Richard W.M. Jones L<http://people.redhat.com/~rjones/>

=head1 COPYRIGHT

Copyright (C) 2013 Red Hat Inc.