Skip to content

Commit

Permalink
editing libvirt-rocky.md (rocky-linux#2512)
Browse files Browse the repository at this point in the history
* remove duplicate level one heading (the "title:" meta adds the level one heading when included)
* add context to fenced code blocks
* replace passive voice with active
* Sentence style capitalization on headings
* Some minor sentence simplification
  • Loading branch information
sspencerwire authored Nov 27, 2024
1 parent 08519ba commit 650929b
Showing 1 changed file with 88 additions and 54 deletions.
142 changes: 88 additions & 54 deletions docs/guides/virtualization/libvirt-rocky.md
Original file line number Diff line number Diff line change
@@ -1,136 +1,170 @@
---
title: Setting Up libvirt on Rocky Linux
author: Howard Van Der Wal
contributors: N/A
contributors: Steven Spencer
tested with: 9.5
tags:
- libvirt
- kvm
- virtualization
---

# Setting Up libvirt on Rocky Linux 9

## Introduction

[libvirt](https://libvirt.org/) is an incredible virtualization API that enables you to virtualize almost any operating system of your choice with the power of KVM as the hypervisor, and QEMU as the emulator.
[libvirt](https://libvirt.org/) is an incredible virtualization API that allows for the virtualization of almost any operating system of your choice with the power of KVM as the hypervisor, and QEMU as the emulator.

This document will provide the instructions for setting up libvirt on Rocky Linux 9.

## Prerequisites

* A 64 bit machine running Rocky Linux 9.
* Ensure that virtualization is enabled in your BIOS settings. If the following command returns output, that means virtualization is enabled:
```
* Ensure the enabling of virtualization in your BIOS settings. If the following command returns output, that means enabling of virtualization is complete:

```bash
sudo grep -e 'vmx' /proc/cpuinfo
```

## Repository Setup and Package Installation
## Repository setup and package installation

* Enable the EPEL (Extra Packages for Enterprise Linux) repository.
```
* Enable the EPEL (Extra Packages for Enterprise Linux) repository:

```bash
sudo dnf install -y epel-release
```
* Install the required packages for `libvirt` (optionally for `virt-manager` if you wish to use a GUI to manage your VMs).
```

* Install the required packages for `libvirt` (optionally for `virt-manager` if you want to use a GUI to manage your VMs):

```bash
sudo dnf install -y bridge-utils virt-top libguestfs-tools bridge-utils virt-viewer qemu-kvm libvirt virt-manager virt-install
```

## libvirt User Setup
## libvirt user setup

* Add your user to the `libvirt` group. This allows you to manage your VMs and use commands such as `virt-install` as a non-root user.
```
* Add your user to the `libvirt` group. This enables the management of your VMs and use commands such as `virt-install` as a non-root user:

```bash
sudo usermod -aG libvirt $USER
```
* Activate the `libvirt` group by using the `newgrp` command.
```

* Activate the `libvirt` group by using the `newgrp` command:

```bash
sudo newgrp libvirt
```
* Enable and start the `libvirtd` service.
```

* Enable and start the `libvirtd` service:

```bash
sudo systemctl enable --now libvirtd
```

## Bridge Interface Setup for Direct Access to Virtual Machines
## Bridge interface setup for direct access to virtual machines

* Check the current interfaces in use and note down the main interface with an Internet connection.
```
* Check the current interfaces in use and note down the main interface with an Internet connection:

```bash
sudo nmcli connection show
```
* Delete the interface connected to the Internet and any virtual bridge connections currently present.
```

* Delete the interface connected to the Internet and any virtual bridge connections currently present:

```bash
sudo nmcli connection delete <CONNECTION_NAME>
```

!!! warning

Make sure you have direct access to the machine. If you are configuring the machine over SSH, the connection will be severed after deleting the main interface connection.

* Create the new bridge connection.
```
* Create the new bridge connection:

```bash
sudo nmcli connection add type bridge autoconnect yes con-name <VIRTUAL_BRIDGE_CON-NAME> ifname <VIRTUAL_BRIDGE_IFNAME>
```
* Assign a static IP address.
```

* Assign a static IP address:

```bash
sudo nmcli connection modify <VIRTUAL_BRIDGE_CON-NAME> ipv4.addresses <STATIC_IP/SUBNET_MASK> ipv4.method manual
```
* Assign a gateway address.
```

* Assign a gateway address:

```bash
sudo nmcli connection modify <VIRTUAL_BRIDGE_CON-NAME> ipv4.gateway <GATEWAY_IP>
```
* Assign a DNS address.
```

* Assign a DNS address:

```bash
sudo nmcli connection modify <VIRTUAL_BRIDGE_CON-NAME> ipv4.dns <DNS_IP>
```
* Add the bridge slave connection.
```

* Add the bridge slave connection:

```bash
sudo nmcli connection add type bridge-slave autoconnect yes con-name <MAIN_INTERFACE_WITH_INTERNET_ACCESS_CON-NAME> ifname <MAIN_INTERFACE_WITH_INTERNET_ACCESS_IFNAME> master <VIRTUAL_BRIDGE_CON-NAME>
```
* Bring up the bridge connection.
```

* Start the bridge connection:

```bash
sudo nmcli connection up <VIRTUAL_BRIDGE_CON-NAME>
```
* Add the `allow all` line to `bridge.conf`.
```

* Add the `allow all` line to `bridge.conf`:

```bash
sudo tee -a /etc/qemu-kvm/bridge.conf <<EOF
allow all
EOF
```
* Restart the `libvirtd` service.
```

* Restart the `libvirtd` service:

```bash
sudo systemctl restart libvirtd
```

## Virtual Machine Installation
## Virtual machine installation

* Set the ownership of the `/var/lib/libvirt` directory and its nested directories to your user.
```
* Set the ownership of the `/var/lib/libvirt` directory and its nested directories to your user:

```bash
sudo chown -R $USER:libvirt /var/lib/libvirt/
```
* Creating a virtual machine on the command line is done by using the `virt-install` command. For example, to create a Rocky linux 9.5 Minimal VM, you would run the following command:
```

* You can create a virtual machine on the command line by using the `virt-install` command. For example, to create a Rocky Linux 9.5 Minimal VM, you would run the following command:

```bash
virt-install --name Rocky-Linux-9 --ram 4096 --vcpus 4 --disk path=/var/lib/libvirt/images/rocky-linux-9.img,size=20 --os-variant rocky9 --network bridge=virbr0,model=virtio --graphics none --console pty,target_type=serial --extra-args 'console=ttyS0,115200n8' --location ~/isos/Rocky-9.5-x86_64-minimal.iso
```
* For those that want to manage their VM's via a GUI, `virt-manager` is the perfect tool.

## How to Shutdown a Virtual Machine
* For those that want to manage their VMs via a GUI, `virt-manager` is the perfect tool.

* This is performed by the `shutdown` command.
```
## How to shutdown a virtual machine

* The `shutdown` command accomplishes this:

```bash
virsh shutdown --domain <YOUR_VM_NAME>
```
* To force shutdown an unresponsive VM, use the `destroy` command.
```

* To force shutdown an unresponsive VM, use the `destroy` command:

```bash
virsh destroy --domain <YOUR_VM_NAME>
```

## How to Delete a Virtual Machine
## How to delete a virtual machine

* Use the `undefine` command.
```
* Use the `undefine` command:

```bash
virsh undefine --domain <YOUR_VM_NAME> --nvram
```

* For further `virsh` commands, please check the `virsh` `man` pages.
* For further `virsh` commands, check the `virsh` `man` pages.

## Conclusion

Expand Down

0 comments on commit 650929b

Please sign in to comment.