16.5. Booting virtual machines from a PXE server
Virtual machines (VMs) that use Preboot Execution Environment (PXE) can boot and load their configuration from a network. This chapter describes how to use libvirt
to boot VMs from a PXE server on a virtual or bridged network.
These procedures are provided only as an example. Ensure that you have sufficient backups before proceeding.
16.5.1. Setting up a PXE boot server on a virtual network
This procedure describes how to configure a libvirt
virtual network to provide Preboot Execution Environment (PXE). This enables virtual machines on your host to be configured to boot from a boot image available on the virtual network.
Conditions préalables
A local PXE server (DHCP and TFTP), such as:
- libvirt internal server
- manually configured dhcpd and tftpd
- dnsmasq
- Cobbler server
-
PXE boot images, such as
PXELINUX
configured by Cobbler or manually.
Procédure
-
Place the PXE boot images and configuration in
/var/lib/tftpboot
folder. Set folder permissions:
# chmod -R a+r /var/lib/tftpboot
Set folder ownership:
# chown -R nobody: /var/lib/tftpboot
Update SELinux context:
# chcon -R --reference /usr/sbin/dnsmasq /var/lib/tftpboot # chcon -R --reference /usr/libexec/libvirt_leaseshelper /var/lib/tftpboot
Shut down the virtual network:
# virsh net-destroy default
Open the virtual network configuration file in your default editor:
# virsh net-edit default
Edit the
<ip>
element to include the appropriate address, network mask, DHCP address range, and boot file, where BOOT_FILENAME is the name of the boot image file.<ip address='192.168.122.1' netmask='255.255.255.0'> <tftp root='/var/lib/tftpboot' /> <dhcp> <range start='192.168.122.2' end='192.168.122.254' /> <bootp file='BOOT_FILENAME' /> </dhcp> </ip>
Start the virtual network:
# virsh net-start default
Vérification
Verify that the
default
virtual network is active:# virsh net-list Name State Autostart Persistent --------------------------------------------------- default active no no
Ressources supplémentaires
16.5.2. Booting virtual machines using PXE and a virtual network
To boot virtual machines (VMs) from a Preboot Execution Environment (PXE) server available on a virtual network, you must enable PXE booting.
Conditions préalables
- A PXE boot server is set up on the virtual network as described in Setting up a PXE boot server on a virtual network.
Procédure
Create a new VM with PXE booting enabled. For example, to install from a PXE, available on the
default
virtual network, into a new 10 GB qcow2 image file:# virt-install --pxe --network network=default --memory 2048 --vcpus 2 --disk size=10
Alternatively, you can manually edit the XML configuration file of an existing VM:
Ensure the
<os>
element has a<boot dev='network'/>
element inside:<os> <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type> <boot dev='network'/> <boot dev='hd'/> </os>
Ensure the guest network is configured to use your virtual network:
<interface type='network'> <mac address='52:54:00:66:79:14'/> <source network='default'/> <target dev='vnet0'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
Vérification
-
Start the VM using the
virsh start
command. If PXE is configured correctly, the VM boots from a boot image available on the PXE server.
16.5.3. Booting virtual machines using PXE and a bridged network
To boot virtual machines (VMs) from a Preboot Execution Environment (PXE) server available on a bridged network, you must enable PXE booting.
Conditions préalables
- Network bridging is enabled.
- A PXE boot server is available on the bridged network.
Procédure
Create a new VM with PXE booting enabled. For example, to install from a PXE, available on the
breth0
bridged network, into a new 10 GB qcow2 image file:# virt-install --pxe --network bridge=breth0 --memory 2048 --vcpus 2 --disk size=10
Alternatively, you can manually edit the XML configuration file of an existing VM:
Ensure the
<os>
element has a<boot dev='network'/>
element inside:<os> <type arch='x86_64' machine='pc-i440fx-rhel7.0.0'>hvm</type> <boot dev='network'/> <boot dev='hd'/> </os>
Ensure the VM is configured to use your bridged network:
<interface type='bridge'> <mac address='52:54:00:5a:ad:cb'/> <source bridge='breth0'/> <target dev='vnet0'/> <alias name='net0'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
Vérification
-
Start the VM using the
virsh start
command. If PXE is configured correctly, the VM boots from a boot image available on the PXE server.
Ressources supplémentaires