Virt-install: Difference between revisions
(157 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=External= | =External= | ||
* | * RHEL7 Virtualization Administration - Creating Guests with virt-install https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/sect-Guest_virtual_machine_installation_overview-Creating_guests_with_virt_install.html | ||
=Internal= | =Internal= | ||
* [[Linux Virtualization Operations | * [[Linux_KVM_Virtualization_Guest_Operations#Create_a_Guest_Virtual_Machine|Linux Virtualization Guest Operations]] | ||
* [[Linux Virtualization Concepts]] | |||
=Overview= | =Overview= | ||
virt-install is a command-line utility for provisioning new virtual machines. It comes as part of the "virt-install" RPM package. | <code>virt-install</code> is a command-line utility for provisioning new virtual machines. It comes as part of the "virt-install" RPM package. virt-install needs root privileges on the virtualization host to work. | ||
The execution results in creation of a virtual machine XML definition, which can then be displayed with <code>[[virsh dumpxml]]</code> and edited with <code>[[virsh edit]]</code>, and in the initialization of the [[Linux_Virtualization_Concepts#Virtual_Machine_Image|virtual machine image]] as the result of the interactive O/S installation procedure. Note that the underlying volume does not need to be created in advance. The corresponding virtual machine root filesystem will be stored on an automatically created volume (<code>/main-storage-pool/<guest-name>.qcow2</code>). The volume will be created in the associated storage pool during the installation procedure, if the volume does not exist already. Additional block storage, in the form of different block devices available to the guest, can it be added later. The installation procedure may specify a minimal network configuration (DHCP and just host name), while the network can be further configured later. | |||
=Documentation= | =Documentation= | ||
<syntaxhighlight lang='bash'> | |||
virt-install --help | |||
</syntaxhighlight> | |||
=Procedure= | |||
==Prerequisites== | |||
If not already declared, create an "iso-images" directory-based storage pool. The procedure to create the storage pool is described here: {{Internal|KVM Virtualization Directory-Based Storage Pool Configuration|Directory-Based Storage Pool Configuration}} | |||
Once the pool is created, the ISO image can be simply placed in there: | |||
<syntaxhighlight lang='bash'> | |||
cp .../CentOS-7-x86_64-DVD-2009.iso /iso-images | |||
chown qemu:qemu CentOS-7-x86_64-DVD-2009.iso | |||
</syntaxhighlight> | |||
While the file does is not exposed yet as a volume, <code>virt-install</code> will expose it as a volume in the pool. Optionally, it can be exported as a pool volume in advance. The procedure to export the DVD ISO image as a pool volume is described here:{{Internal|KVM_Virtualization_Placing_an_ISO_Image_in_a_Directory-Based_Storage_Pool|Placing an ISO Image in a Directory-Based Storage Pool}} | |||
The command assumes that <code>main-storage-pool</code> was created and it is active. | |||
{{Warn|Download "Red Hat Enterprise Linux 7.4 Binary DVD" and not the Boot ISO or KVM Guest image, otherwise the installation via virt-install will fail.}} | |||
==Virtual Machine Creation== | |||
<font size=-2> | |||
virt-install | |||
[[#Guest_Virtual_Machine_Name|--name]] ''<virtual-machine-name>'' | |||
[[Virt-install#Memory_Amount|--memory]] 1024 | |||
[[#--vcpus|--vcpus]] 2 | |||
[[#--os-variant|--os-variant]]=''<os-variant>'' | |||
[[#Distribution_Tree_Installation_Source|--location]] /iso-images/rhel-server-7.3-x86_64-'''dvd'''.iso | |||
[[#--extra-args.3D|--extra-args]]="console=tty0 console=ttyS0,115200n8" | |||
[[#--disk|--disk]]=/iso-images/rhel-server-7.3-x86_64-'''dvd'''.iso,device=cdrom | |||
[[#--disk|--disk]]=/main-storage-pool/''<virtual-machine-name>''.qcow2,size=''<image-partition-size-in-GiB-without-alphanumeric-unit>'' | |||
[[#Network_Specification|--network]] default | |||
[[#Graphics|--graphics]] none | |||
</font> | |||
===Notes=== | |||
* ⚠️ The size of the root partition determines how the RedHat/Centos installer will partition the space (create just a root partition "/" or a root "/" and a home "/home" partition. The cut-off is 50GB. For more details see [[Centos_7_Text_Installer#Root_Partition_Size|Centos 7 Text Installer | Root_Partition_Size]]. | |||
* For <code>noper430</code> installations, these commands are usually saved as <code>/root/environments/single-hosts/<''host-name''>/<''host-name''>-virt-install.sh</code> and it is recommended to do so for any guest created on that virtualization host. | |||
===Procedure=== | |||
<font size=-2> | |||
Starting install... | |||
Retrieving file .treeinfo... | |||
[...] | |||
Welcome to CentOS Linux 7 (Core) dracut-033-572.el7 (Initramfs)! | |||
[...] | |||
</font> | |||
===Interactive O/S Installation Procedure=== | |||
The command will enter in text interactive mode. Different installers will have their own installation procedure: | |||
* [[Centos 7 Text Installer|Centos 7 Text Installer]] | |||
==Results== | |||
The installation process should end up in console access to the newly installed host. | |||
The virtual machine will appear in [[virsh list]]: | |||
<font size=-2> | |||
Id Name State | |||
---------------------------------------------------- | |||
... | |||
9 gp running | |||
</font> | |||
The XML definition of the virtual machine will be accessible with <code>[[virsh dumpxml]]</code> and can be edited with <code>[[virsh edit]]</code>: | |||
{{Internal|KVM Virtual Machine XML Defintion|KVM Virtual Machine XML Definition}} | |||
The virtual machine root filesystem is stored on an automatically created storage pool volume <code>/main-storage-pool/<vm-name>.qcow2</code>. | |||
The storage volume is automatically added to the main storage pool. Query with <code>[[virsh vol-list|virsh vol-list main-storage-pool --details]]</code>: | |||
<font size=-2> | |||
Name Path | |||
----------------------------------------------------------------------------- | |||
<vm-name>.qcow2 /main-storage-pool/<vm-name>.qcow2 | |||
... | |||
</font> | |||
There are two network interfaces: <code>lo</code> and <code>eth0</code>, configured by DHCP. | |||
There should be just a root partition (/) that occupies the entire block device. | |||
Continue with [[#Post-Install|Post-Install]] below. | |||
==Post-Install== | |||
===Remove the ISO Image from Guest Storage=== | |||
If the ISO image remains mounted, it will not be usable by other guests, so it is a good idea to remove it. If left mounted, the attempt to create other guest will result in: | |||
<syntaxhighlight lang='bash'> | |||
ERROR Disk /iso-images/CentOS-7-x86_64-DVD-7.9.2009.iso is already in use by other guests ['c3kb']. | |||
</syntaxhighlight> | |||
The procedure to remove it is available here: {{Internal|Linux_Virtualization_Remove_Storage_from_Guest|Remove Storage from Guest}} | |||
===Configure the Guest to Start at Boot=== | |||
{{Internal|Virsh_autostart#Configure_to_Automatically_Start_at_Boot|Configure Guest to Automatically Start at Boot}} | |||
===Network Post-Configuration=== | |||
By default, guests are configured to attach in NAT mode to the "default" virtual network running on the virtualization host. | |||
Additional network configurations: | |||
{{Internal|Attaching_a_Guest_Directly_to_a_Virtualization_Host_Network_Interface_with_a_macvtap_Driver#Overview|Attaching a Guest Directly to a Virtualization Host Network Interface with a macvtap Driver}} | |||
===Storage Post-Configuration=== | |||
{{Internal|Linux_Virtualization_Adding_Storage_to_Guests|Adding Storage to Guests}} | |||
===Generic RHEL/Centos Post-Install Tasks=== | |||
{{Internal|RHEL_7/Centos_7_Installation#Post-Install_Tasks|Post-Install}} | |||
===Configure Access from Local Network=== | |||
On the main machine, add this to <code>.basrhc</code>: | |||
< | <syntaxhighlight lang='bash'> | ||
alias gp='ssh -p 53531 root@192.168.1.15' | |||
</ | </syntaxhighlight> | ||
=Mandatory Options= | =Mandatory Options= | ||
Line 28: | Line 136: | ||
--name test-01 | --name test-01 | ||
</pre> | </pre> | ||
For more details about a virtual machine name see: {{Internal|KVM_Virtual_Machine_XML_Configuration_Example#name|KVM Virtual Machine Definition 'name'}} | |||
==Memory Amount== | ==Memory Amount== | ||
Line 36: | Line 146: | ||
--memory 1024 | --memory 1024 | ||
</pre> | </pre> | ||
Equivalent: --ram and -r. | |||
The amount can be changed after the virtual machine is creating by editing the definition with [[virsh edit]]. | |||
==Guest Storage Specification== | ==Guest Storage Specification== | ||
Line 44: | Line 158: | ||
Specifies guest storage, relative to the storage provided by the virtualization host. The most common option is to refer storage from a [[Linux_Virtualization_Concepts#Storage_Pool|storage pool]], but other options are also available. | Specifies guest storage, relative to the storage provided by the virtualization host. The most common option is to refer storage from a [[Linux_Virtualization_Concepts#Storage_Pool|storage pool]], but other options are also available. | ||
It is recommended to follow the [[Linux_Virtualization_Naming_Conventions#Virtual_Machine_Image_Naming_Convention|virtual machine image name convention]] when naming the media to use for storing the virtual machine image. | |||
<pre> | <pre> | ||
Line 54: | Line 170: | ||
--disk /storage-pool-path/volume-path,size=8,sparse=false,cache=none | --disk /storage-pool-path/volume-path,size=8,sparse=false,cache=none | ||
</pre> | </pre> | ||
--disk device=cdrom,bus=scsi | |||
If ISO images are shared with the guests as "cdrom"s as shown below, the ISO images should be deployed into an active directory-based storage pool. If the image is not available in a storage pool, libvirt will automatically build a storage pool for it, and sometimes build multiple storage pools for the same image, which is something we want to avoid. If the storage pool exists, but the ISO image is not declared as a storage volume, virt-install will create the corresponding storage volume (e.g. /iso-images/rhel-server-7.3-x86_64-dvd.iso). | |||
--disk=/iso-images/rhel-dvd.iso,device=cdrom | |||
====--nodisks==== | |||
==Installation Method Option== | |||
====--os-variant==== | |||
This is an important option, used to optimize guest configuration. Valid "--os-variant" values can be obtained with [[osinfo-query#os|osinfo-query os]] command | |||
Example: | |||
<pre> | <pre> | ||
-- | --os-variant=rhel7.3 | ||
</pre> | </pre> | ||
If a more recent os-variant is not available (the following error message is generated): | |||
- | |||
ERROR Error validating install location: Distro 'rhel7.4' does not exist in our dictionary | |||
the dictionary can be updated by performing an yum update on the virtualization host. | |||
====--os-type==== | ====--os-type==== | ||
Line 77: | Line 206: | ||
</pre> | </pre> | ||
====-- | Note that man girt-install does not refer --os-type, it can probably be inferred from [[#--os-variant|--os-variant]]. | ||
===Distribution Tree Installation Source=== | |||
The distribution tree installation source is specified with <span id='--location'>'''--location'''</span>. virt-install can fetch a bootable kernel/initrd pair from the source declared with --location to launch the install. | |||
Options: | |||
====ISO File==== | |||
<pre> | |||
--location /path/to/iso-file.iso | |||
</pre> | |||
Example: | --location is followed by a path to an ISO file containing an installable distribution image. Note that the file should be readable by the "qemu" user. Also note that the file will not be accessible by the guest after initial boot, so the OS installer will need another way to access the rest of the install media. For an example of how to do that, see [[Virt-install_Examples#Text-Based_Anaconda_Guest_Installation|Text-Based Anaconda Guest Installation Example]]. An equivalent format, though less flexible as it does not accept --extra-args, uses --cdrom option: | ||
<pre> | <pre> | ||
-- | --cdrom /path/to/iso-file.iso | URL-with-the-same-format-as-the-ones-used-for--location-argument | ||
</pre> | </pre> | ||
For an end-to-end example of how to create a guest VM from a CDROM image, see: {{Internal|Virt-install_Examples#Text-Based_Anaconda_Guest_Installation|Text-Based Anaconda Guest Installation}} | |||
====Directory==== | |||
<pre> | <pre> | ||
--location | --location /directory | ||
</pre> | </pre> | ||
--location is followed by a path to a local directory containing an installable distribution image. Note that the directory will not be accessible by the guest after initial boot, so the OS installer will need another way to access the rest of the install media. For an example of how to do that, see [[Virt-install_Examples#Text-Based_Anaconda_Guest_Installation|Text-Based Anaconda Guest Installation Example]]. | |||
====HTTP Server==== | |||
<pre> | <pre> | ||
--location http://host/path | --location http://host/path | ||
</pre> | </pre> | ||
====FTP Server==== | |||
<pre> | <pre> | ||
--location | --location ftp://host/path | ||
</pre> | </pre> | ||
==== | ====NFS Server==== | ||
< | <pre> | ||
--location nfs:host:/path | |||
--location nfs://host/path | |||
</pre> | |||
===Optional Installation Method Option=== | ===Optional Installation Method Option=== | ||
Line 145: | Line 293: | ||
==Network Specification== | ==Network Specification== | ||
The network specification is optional, if | The network specification is optional. If "--network" is not used, or if "--network default" is used, the guest will connect to the [[KVM_Virtual_Networking_Concepts#The_Default_Networking_Configuration|default network]]: | ||
--network default | |||
< | Otherwise, it can be specified with <span id='--network'>'--network NETWORK-SPEC'</span>, as follows: | ||
<font color=red> | |||
TODO: | |||
<pre> | <pre> | ||
--network bridge=mybr0 | --network bridge=mybr0 | ||
</pre> | </pre> | ||
If using a bridge, the bridge must be previously created, as described here [[KVM_Virtualization_Bridged_Networking_Configuration|Bridged Networking Configuration]]. | TODO: If using a bridge, the bridge must be previously created, as described here [[KVM_Virtualization_Bridged_Networking_Configuration|Bridged Networking Configuration]]. | ||
TODO: | |||
<pre> | <pre> | ||
--network network=my_libvirt_virtual_net | --network network=my_libvirt_virtual_net | ||
</pre> | </pre> | ||
TODO: | |||
<pre> | <pre> | ||
--network network=mynet,model=virtio,mac=00:11.. | --network network=mynet,model=virtio,mac=00:11.. | ||
</pre> | </pre> | ||
TODO: | |||
<pre> | <pre> | ||
--network none | --network none | ||
</pre> | </pre> | ||
</font> | |||
==--vcpus== | ==--vcpus== | ||
Specifies the number of virtual CPUs for the guest. | Specifies the number of virtual CPUs for the guest: | ||
<pre> | |||
--vcpus 2 | |||
</pre> | |||
The amount can be changed after the virtual machine is creating by editing the definition with [[virsh edit]]. | |||
==Virtualization Platform Options== | ==Virtualization Platform Options== | ||
Line 201: | Line 368: | ||
=Examples= | =Examples= | ||
{{Internal|Virt-install_Examples|virt-install Examples}} | |||
virt-install | |||
Latest revision as of 02:38, 30 July 2023
External
- RHEL7 Virtualization Administration - Creating Guests with virt-install https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/sect-Guest_virtual_machine_installation_overview-Creating_guests_with_virt_install.html
Internal
Overview
virt-install
is a command-line utility for provisioning new virtual machines. It comes as part of the "virt-install" RPM package. virt-install needs root privileges on the virtualization host to work.
The execution results in creation of a virtual machine XML definition, which can then be displayed with virsh dumpxml
and edited with virsh edit
, and in the initialization of the virtual machine image as the result of the interactive O/S installation procedure. Note that the underlying volume does not need to be created in advance. The corresponding virtual machine root filesystem will be stored on an automatically created volume (/main-storage-pool/<guest-name>.qcow2
). The volume will be created in the associated storage pool during the installation procedure, if the volume does not exist already. Additional block storage, in the form of different block devices available to the guest, can it be added later. The installation procedure may specify a minimal network configuration (DHCP and just host name), while the network can be further configured later.
Documentation
virt-install --help
Procedure
Prerequisites
If not already declared, create an "iso-images" directory-based storage pool. The procedure to create the storage pool is described here:
Once the pool is created, the ISO image can be simply placed in there:
cp .../CentOS-7-x86_64-DVD-2009.iso /iso-images
chown qemu:qemu CentOS-7-x86_64-DVD-2009.iso
While the file does is not exposed yet as a volume, virt-install
will expose it as a volume in the pool. Optionally, it can be exported as a pool volume in advance. The procedure to export the DVD ISO image as a pool volume is described here:
The command assumes that main-storage-pool
was created and it is active.
Download "Red Hat Enterprise Linux 7.4 Binary DVD" and not the Boot ISO or KVM Guest image, otherwise the installation via virt-install will fail.
Virtual Machine Creation
virt-install --name <virtual-machine-name> --memory 1024 --vcpus 2 --os-variant=<os-variant> --location /iso-images/rhel-server-7.3-x86_64-dvd.iso --extra-args="console=tty0 console=ttyS0,115200n8" --disk=/iso-images/rhel-server-7.3-x86_64-dvd.iso,device=cdrom --disk=/main-storage-pool/<virtual-machine-name>.qcow2,size=<image-partition-size-in-GiB-without-alphanumeric-unit> --network default --graphics none
Notes
- ⚠️ The size of the root partition determines how the RedHat/Centos installer will partition the space (create just a root partition "/" or a root "/" and a home "/home" partition. The cut-off is 50GB. For more details see Centos 7 Text Installer | Root_Partition_Size.
- For
noper430
installations, these commands are usually saved as/root/environments/single-hosts/<host-name>/<host-name>-virt-install.sh
and it is recommended to do so for any guest created on that virtualization host.
Procedure
Starting install... Retrieving file .treeinfo... [...] Welcome to CentOS Linux 7 (Core) dracut-033-572.el7 (Initramfs)! [...]
Interactive O/S Installation Procedure
The command will enter in text interactive mode. Different installers will have their own installation procedure:
Results
The installation process should end up in console access to the newly installed host.
The virtual machine will appear in virsh list:
Id Name State ---------------------------------------------------- ... 9 gp running
The XML definition of the virtual machine will be accessible with virsh dumpxml
and can be edited with virsh edit
:
The virtual machine root filesystem is stored on an automatically created storage pool volume /main-storage-pool/<vm-name>.qcow2
.
The storage volume is automatically added to the main storage pool. Query with virsh vol-list main-storage-pool --details
:
Name Path ----------------------------------------------------------------------------- <vm-name>.qcow2 /main-storage-pool/<vm-name>.qcow2 ...
There are two network interfaces: lo
and eth0
, configured by DHCP.
There should be just a root partition (/) that occupies the entire block device.
Continue with Post-Install below.
Post-Install
Remove the ISO Image from Guest Storage
If the ISO image remains mounted, it will not be usable by other guests, so it is a good idea to remove it. If left mounted, the attempt to create other guest will result in:
ERROR Disk /iso-images/CentOS-7-x86_64-DVD-7.9.2009.iso is already in use by other guests ['c3kb'].
The procedure to remove it is available here:
Configure the Guest to Start at Boot
Network Post-Configuration
By default, guests are configured to attach in NAT mode to the "default" virtual network running on the virtualization host.
Additional network configurations:
Storage Post-Configuration
Generic RHEL/Centos Post-Install Tasks
Configure Access from Local Network
On the main machine, add this to .basrhc
:
alias gp='ssh -p 53531 root@192.168.1.15'
Mandatory Options
Guest Virtual Machine Name
The name of the guest virtual machine must be specified with --name or -n:
--name test-01
For more details about a virtual machine name see:
Memory Amount
virt-install needs the amount of memory allocated to the guest, in MiB, which must be specified with --memory:
--memory 1024
Equivalent: --ram and -r.
The amount can be changed after the virtual machine is creating by editing the definition with virsh edit.
Guest Storage Specification
One of the following must be specified:
--disk
Specifies guest storage, relative to the storage provided by the virtualization host. The most common option is to refer storage from a storage pool, but other options are also available.
It is recommended to follow the virtual machine image name convention when naming the media to use for storing the virtual machine image.
--disk size=10
Specified a new 10 GiB image on the default storage pool.
--disk /storage-pool-path/volume-path,size=8,sparse=false,cache=none
--disk device=cdrom,bus=scsi
If ISO images are shared with the guests as "cdrom"s as shown below, the ISO images should be deployed into an active directory-based storage pool. If the image is not available in a storage pool, libvirt will automatically build a storage pool for it, and sometimes build multiple storage pools for the same image, which is something we want to avoid. If the storage pool exists, but the ISO image is not declared as a storage volume, virt-install will create the corresponding storage volume (e.g. /iso-images/rhel-server-7.3-x86_64-dvd.iso).
--disk=/iso-images/rhel-dvd.iso,device=cdrom
--nodisks
Installation Method Option
--os-variant
This is an important option, used to optimize guest configuration. Valid "--os-variant" values can be obtained with osinfo-query os command
Example:
--os-variant=rhel7.3
If a more recent os-variant is not available (the following error message is generated):
ERROR Error validating install location: Distro 'rhel7.4' does not exist in our dictionary
the dictionary can be updated by performing an yum update on the virtualization host.
--os-type
The quest operating system type.
Example:
--os-type=linux
Note that man girt-install does not refer --os-type, it can probably be inferred from --os-variant.
Distribution Tree Installation Source
The distribution tree installation source is specified with --location. virt-install can fetch a bootable kernel/initrd pair from the source declared with --location to launch the install.
Options:
ISO File
--location /path/to/iso-file.iso
--location is followed by a path to an ISO file containing an installable distribution image. Note that the file should be readable by the "qemu" user. Also note that the file will not be accessible by the guest after initial boot, so the OS installer will need another way to access the rest of the install media. For an example of how to do that, see Text-Based Anaconda Guest Installation Example. An equivalent format, though less flexible as it does not accept --extra-args, uses --cdrom option:
--cdrom /path/to/iso-file.iso | URL-with-the-same-format-as-the-ones-used-for--location-argument
For an end-to-end example of how to create a guest VM from a CDROM image, see:
Directory
--location /directory
--location is followed by a path to a local directory containing an installable distribution image. Note that the directory will not be accessible by the guest after initial boot, so the OS installer will need another way to access the rest of the install media. For an example of how to do that, see Text-Based Anaconda Guest Installation Example.
HTTP Server
--location http://host/path
FTP Server
--location ftp://host/path
NFS Server
--location nfs:host:/path --location nfs://host/path
Optional Installation Method Option
--boot
--boot BOOT_OPTS is used to configure guest boot settings:
--boot hd,cdrom,menu=on
--boot init=/sbin/init
--pxe
Boot from the network using the PXE protocol.
--import
Build guest around an existing disk image.
--extra-args=
--extra-args EXTRA_ARGS Additional arguments to pass to the install kernel booted from --location.
Optional Configuration
Graphics
Specifies the type of graphical tool to use for interactive installation or can be set to "none" for a fully automated installation.
--graphics none|spice|...
Network Specification
The network specification is optional. If "--network" is not used, or if "--network default" is used, the guest will connect to the default network:
--network default
Otherwise, it can be specified with '--network NETWORK-SPEC', as follows:
TODO:
--network bridge=mybr0
TODO: If using a bridge, the bridge must be previously created, as described here Bridged Networking Configuration.
TODO:
--network network=my_libvirt_virtual_net
TODO:
--network network=mynet,model=virtio,mac=00:11..
TODO:
--network none
--vcpus
Specifies the number of virtual CPUs for the guest:
--vcpus 2
The amount can be changed after the virtual machine is creating by editing the definition with virsh edit.
Virtualization Platform Options
-v, --hvm
This guest should be a fully virtualized guest.
-p, --paravirt
This guest should be a paravirtualized guest.
--container
This guest should be a container guest.
--virt-type
Represents the hypervisor name to use ("kvm", "qemu", "xen", etc.)
Access to a Host Directory
"--filesystem" can be used to specify a host directory to be available on the guest.
Example:
--filesystem /my/host/source/dir,/dir/in/guest