Virt-Manager, the gift that just keeps giving. You may get stuck on an installation or perhaps would like to work with your VM (virtual machine) differently. We are here to help you keep you from needlessly reinstalling an uncooperative VM. We will help you learn to change all the variable that control your VM. Furthermore, we are here to make your experience that much better. Now if you have never used Virt-Manager, then you may want to see our blog about how to install Virt-Manager here. If you are just new to Virt-Manager, and you’re already using it, this is the blog for you.
Today we will go over how to re-size an already existing VM storage container. Next we will go over how to SSH into a VM to make it feel like working on a native terminal on your workstation. We will go over how to add an installation media disk to your VM boot sequence to rescue a VM. Then cover how to move storage locations. Then we will go over how to add CPU cores and RAM post installation. Finally, we will go over the importance of cloning, and how to use them to save time. Now let’s get into the that next-level VM of management.
Expanding a Virtual Disk
Have you ever started a project only to need more virtual disk space to get the job done? We are in luck. Inside the UI itself, Virt-Manager has numerous options. But VM drive sizing is not very straightforward. So, we will use a quick shortcut built into QEMU. First you will need to determine how much space you have on your actual drive, so you don’t over shoot and disrupt your host machine’s operations.
Here you will see all of your drives connected. You will need to look at your root partition or if you have a home partition, then that is where you will look. You should also take note of how much space you need for normal operation of your host computer. Let’s make our virtual drive bigger from our host machine.
sudo qemu-img resize /var/lib/libvirt/images/your-vm-name.qcow2 +10G
Here we are using sudo to use QEMU properly. Then we are using the qemu-img command with resize to get the job done. Next we are pointed at our VM drive container, a .qcow2 file. You may have made your own location if you have a home partition. Just point your path to that location instead. We also have the size to add to our drive which we added 10 gigabytes. You would need to reopen Virt-Manager to see the effect. You can always change the size to what you would like it to be 2 GB or 100 GB. To fully use this space, you will have to expand your partition from your guest os machine.
sudo resize2fs /dev/vda2
Now to be sure we have the space available, we will check the virtual machine drive space.
So, you want to SSH into a VM to streamline your workflow on your workstation. This way you can add configurations straight from your host machine all in terminal. First thing we need to do is enable the service that will allow us to gain console access to our VM. In preparation, you will want to be logged
into our VM to run this command.
sudo systemctl start --now getty@ttyS0
Now from our host machine we will want to see if we were successful by trying to connect.
sudo virsh console vm-name
Press Enter then you should see the command prompt from your VM. Giving you efficiency above all. You can make it run on boot every time or just do this when you need to. All you would need to do is run the first command on the VM with a slight change like this.
sudo systemctl enable getty@ttyS0
After running this you will have console access to this VM whenever you need. Making copy and paste work for VMs like servers with no GUI.
Boot an ISO
To recover a VM is as easy as on a regular machine. In numerous cases you might just say, “I will just start over and try again!” This is great when you are trying to get past a problem you cannot solve any other way. But, let’s say you’re trying to learn how to install Arch for the first time, and you want to do this on Virt-Manager, you may be starting over a lot. Instead of this, assuming you are past the pacstrap command you will have a chance to recover your VM by using the installation media to arch-chroot into your installation thus picking up where you left off or reconfiguring your boot. Giving you a chance to fix your installation like a true Arch Linux user. The first thing we need to do is get into the VM management panel. Open your VM user interface then click on the icon with a lower case i in it.
This will bring you to your VM overview tab. Make sure to apply the changes per tab, or they will not be saved. We will want to click on the boot options tab.
Now we will check the box for boot menu option and for SATA CDROM 1. Again, do not forget to save the changes per tab. Next, we need to navigate to SATA CDROM tab and add the path from your Arch Linux installation media.
Again, do not forget to save the changes per tab. You could add any distribution installation media to fix said installation with this method. Now we will proceed to boot into our Arch installation media.
You can see that we need to make a boot option choice once it boots up. Go ahead and press Esc during boot to get the CDROM option. You should be able to just type the number 2 in to get the desired result. Which will bring us to the Arch Linux media boot screen. Just boot in like you’re going to install Arch and then mount your drives and proceed to arch-chroot into your installation to fix it.
Moving Guest Location
Now if you have a home partition, or are thinking of creating one, you will need to know this information if you ever forget to make a custom VM location. The reason you will need one is to make sure that you have enough space for both your system files and your VM respectively. If you have a home partition you know that often you then give your root partition perhaps 40 GB. Just enough to store your system files a few times over in case you test a lot of stuff. Well, If you use Virt-Manager default storage location, you will soon find that your root partition will be bloated and possibly cause some function loss. To fix this after the fact all we need to do is create a dot file location like this.
This will then have to be added to your volumes in the Virt-Manager panel. To get there click on the QEMU/KVM text. Then right click to get a dropdown.
Select details, then find the storage tab and click on it.
At the far left bottom click the plus sign to create a storage pool. Then add the directory we crated to make our custom storage location. While naming the location something that you will remember. Now we need to copy the original that we already made in the default location to our new location.
sudo cp /var/lib/libvirt/images/VM-name.qcow2 ~/.VM/VM-name.qcow2
Next we will have to make sure we can edit the XML by enabling it in the Virt-Manager preferences under the edit tab.
Now that we have a copy of the VM in our new location we will change the XML for the VM in the Virt-Manager panel. We will navigate to the VirtIO disk tab and switch over to XML view.
You will then want to edit the path for the location of your VM to the new location. Now you can test your VM and see if it starts as normal. Then you can delete your old VirtIO storage like this.
sudo rm -r /var/lib/libvirt/images/VM-name.qcow2
Then you should have freed up some much-needed root storage. Now that we have gone through all of these options you can see that Virt-Manager is built on tech that you can access at times to help you adjust things around. You can also rely on the versatility and usability of Virt-Manager for all your VM
task. Making Virt-Manager a tool that you cannot go without. So keep your VMs well managed and control them like they are on a bare-metal installation. Until next time, thanks for reading.