Linux KVM/Qemu Virt-Customize Tutorial – POFTUT

Linux KVM/Qemu Virt-Customize Tutorial

I am gonna show you today a practical and useful tool for managing Linux virtual machines and disks. With virtualization, people start to use a lot of VMS in their personal or corporate PC’s. But managing them is difficult. I faced these difficulties too. So I search for a tool helps me especially in updates. I came with virt-customize which is a tool in libguestfs-tools package. Here we start.

Install virt-customize

In order to use the virt-customize command, we will install libguestfs-tools package.

Install For Ubuntu, Debian, Mint, Kali

Install For Ubuntu, Debian, Mint, Kali

Install For Ubuntu, Debian, Mint, Kali

Install For Fedora, CentOS, Red Hat


Load Image

Update existing disk image Virt-customize opens the disk and then look for last update seed and then try to run update commands which are used this distro. Windows image are not supported yet but you can use the run command to update windows images. Here you can you URI for remote disk images. The disk format is automatically detected. While loading image we may get some errors which prevent to load the image. This is generally permission related error which can be solved with the sudo command.

Load Image

Load Image

Mount ISO to Image

We can also run the interactive shell by attaching an ISO image into the VM image. We will use --attach command by providing the ISO file.

Connect Libvirt or Hypervisor

To connect and hypervisor and run virt-customize there use -c option with hypervisor URI which is here local libvirtd and give domain name or UUID with -d option. In this example, we will connect the local hypervisor and open the VM named Debian disk image.

echo '

Run Operations in Test Mode

All actions done inside image will be persistent. But if we want to work on test or dry run mode we can use -n option where the action will not affect the image.

LEARN MORE  How To Use Virt-Manager, Libvirt With Normal User Without Root Privileges and Without Asking Password

Set RAM/Memory

You can specify memory usage with -m or –memory option. Default memory size can be seen with guesfish get-memsize command which is 500MB. In this example, we will set the memory size 512 MB with the -m option like below.

Start Without Network

By default, the started image will be connected to the default network which is generally the internet connection. We can prevent to connect to the network with the --no-network option like below.

Verbose or Debug Mode

If there is a problem to troubleshoot or we need more information about the start we can print detailed information with the -v verbose option.

Verbose or Debug Mode

Verbose or Debug Mode

We can see from the screenshot that all actions and configuration are printed to the terminal in a detailed way.

LEARN MORE  How To Mount VM Images with Guestmount?

Delete File

We can delete file and folders inside the VM image with the --delete option by providing the file or folder name. In this example, we will delete the folder /root/.ssh.

Set Hostname

We can set the hostname for the given system. We will use the --hostname option and provide the hostname which is poftut.fed1 in this example. poftut is the domain part where fed1 is the hostname.

Install Packages

We can also install packages into a domain image by using the --install option. With the –install option we will also provide the package names we want to install. In this example, we will install packages named httpd and vim.

Create Directory

To create directories on file system use --mkdir option. There is no border it acts like root you can create whatever you want

LEARN MORE  Linux VMware Workstation Not Enough Physical Memory Is Available Error and Solution

Run Command

Up to now, we call options related to standard Linux commands also we can run commands inside disk image with –run-command option.

Run Script

If we want to run script we can use –run command with the script path. In this example, we will run the script named which is stored under the directory named downloads

Upload File To The Image

We can upload a file from the host system to the image with the --upload option. We will provide the local file name and the destination path in the image we wanto upload to. In this example, we will upload the file named into the image /root/

Leave a Reply

Your email address will not be published. Required fields are marked *