A Comprehensive Guide to Creating a Virtual Machine with Virt-Manager
This guide provides a new virtual machine (VM) using the virt-manager graphical interface. It covers connecting to a remote host, configuring the VM hardware for optimal performance, and walking through the OS installation.
1 Part 1: Prerequisites and Connection
Before creating a VM, you need to connect to your virtualization host and launch virt-manager. The host machine for this guide is running Gentoo Linux, and the client machine is a Mac.
1.1. For macOS Users: Install XQuartz
virt-manager is a graphical application. To run it from a remote Linux server and have the window appear on your Mac, you need an X server. XQuartz is the standard for this.
- Download and install XQuartz on your Mac.
- After installation, log out and log back in, or restart your computer to ensure it's running correctly.
1.2. For Windows Users: Install MobaXterm
Windows users can use MobaXterm, which includes both an SSH client and a built-in X11 server, requiring no extra configuration.
- Download and install the Home Edition of MobaXterm.
- Start a new session and enter the remote host details. X11 forwarding is enabled by default.
1.3. Connect to Your Host via SSH
Open your terminal (or MobaXterm on Windows) and connect to your Linux virtualization host. The -X flag is crucial for enabling X11 forwarding.
# Replace 'user' with your username and 'your-server-address' with the host's IP or hostname
ssh -X user@your-server-address
1.4. Launch Virt-Manager
Once you are logged into the server, launch virt-manager.
virt-manager
The Virtual Machine Manager window should appear on your desktop after a few moments.
If virt-manager becomes unresponsive, you may need to force-quit it on the server.
# 1. Find the process ID (PID) of virt-manager
pgrep virt-manager
# 2. Terminate the process gracefully
pkill virt-manager
# 3. If it's still stuck, force-kill it
pkill -9 virt-manager
2 Part 2: The "Create New VM" Wizard
With virt-manager open, begin the creation process.
2.1. Start the Wizard
Go to File → New Virtual Machine.
2.2. Step 1: Choose Installation Method
Select Local install media (ISO image or CDROM). Click Forward.
2.3. Step 2: Locate Installation Media
Click Browse... → Browse Local to select your Ubuntu-24.04-live-server-amd64.iso file. Click Forward.
2.4. Step 3 & 4: Configure CPU and Memory
Allocate resources (e.g., 4096 MiB Memory, 4 CPUs). Click Forward.
2.5. Step 5: Configure Storage
Create a virtual hard disk (e.g., 250 GiB). Click Forward.
2.6. Step 6: Final Configuration
- Name: cs181au
- Network selection: Choose Bridge device, Device name: br0.
Click Finish.
3 Part 3: Customizing Virtual Hardware
Fine-tune the settings for better performance and compatibility.
3.1. Overview Tab: Chipset and Firmware
- Chipset: i440FX
- Firmware: UEFI
3.2. Remove Unnecessary Devices
Select and remove the Tablet and Sound card.
3.3. Optimize Video Output
- Select the Video device.
- Change the Model to Virtio.
3.4. Final Review
Confirm your settings, then click Apply.
4 Part 4: Begin OS Installation
Click the Begin Installation button. A console window will open, and the VM will boot from the ISO.
5 Part 5: Ubuntu Server Installation Walkthrough
This section details the steps within the Ubuntu Server installer itself.
5.1. Network Configuration
- IPv4/IPv6 Configuration: Set up the static IP addresses as shown below.
- Network Interfaces: Once configured, you will see a summary. Select Done.
5.2. Storage Configuration
- Guided Storage: Choose "Use an entire disk" and ensure "Set up this disk as an LVM group" is selected. This provides flexibility for resizing partitions later.
- Storage Layout: Review the proposed partition layout.
- Editing Partitions (Optional):
- Final Storage Summary: Review the final layout and select Done.
- Confirm Destructive Action: Select Continue to format the disk.
5.3. Profile Setup
Enter User Details: Your name: Nicholas Dodds, Server's name: cs181au, Username: ndodds. Choose a password and select Done.
5.4. Ubuntu Pro & SSH
- Ubuntu Pro: Skip for now and select Continue.
- SSH Setup: Ensure Install OpenSSH server is checked.
5.5. Final Installation Steps
- Server Snaps: You can skip adding extra packages. Select Done.
- Installation Complete: Once finished, select Reboot Now.
6 Part 6: Post-Installation & Verification
After rebooting, perform these final steps to ensure the VM is correctly configured.
6.1. Eject the Installation Media
The VM may try to boot from the ISO again. In virt-manager, go to the VM's hardware details:
- Select the SATA CDROM 1 device.
- Click Disconnect, then Apply. You may need to force-reboot the VM.
6.2. Correct and Apply Network Configuration
Log into the newly installed server. The Ubuntu installer can sometimes fail to apply both IPv4 and IPv6 settings correctly. You must verify and fix the configuration file.
Use vim to edit the netplan configuration file:
sudo vim /etc/netplan/50-cloud-init.yaml
Verify the file contains the complete configuration for both IPv4 and IPv6. It should look exactly like this:
network:
version: 2
ethernets:
ens3:
addresses:
- "134.173.42.103/24"
- "2620:102:2001:902::103/64"
nameservers:
addresses:
- 134.173.42.2
- "2620:102:2001:902::2"
search:
- cs.hmc.edu
routes:
- to: default
via: "2620:102:2001:902::1"
- to: default
via: "134.173.42.1"
Apply the corrected configuration to make it active:
sudo netplan apply
6.3. Final Network Test
To confirm that the network is working correctly, ping the gateway from within the VM:
ping 134.173.42.1
If successful, your virtual machine is now fully installed, configured, and ready for use.