How to add disk image to KVM virtual machine with virsh command

How to add disk image to KVM virtual machine with virsh command

To add a disk image to a KVM virtual machine with the virsh command, you can use the attach-disk command.

Here are the steps to follow to add a disk image to a KVM virtual machine with virsh:

  1. Make sure that the disk image file is available on the host system, and that the virtual machine is powered off.

  2. Determine the name of the virtual machine that you want to attach the disk image to. You can list the available virtual machines with the following command:

refe‮ot r‬:lautturi.com
virsh list --all
  1. Use the attach-disk command to attach the disk image to the virtual machine. For example, to attach the disk image file disk.img to the virtual machine "vm1" as the first virtual disk, you can use the following command:
virsh attach-disk vm1 disk.img vda --cache none --persistent

This will attach the disk image file to the virtual machine as the first virtual disk (vda). The --cache none option disables write caching for the disk, which can improve performance for some workloads. The --persistent option makes the change permanent, so that it will persist across reboots of the virtual machine.

  1. Start the virtual machine with the start command. For example:
virsh start vm1

The disk image will now be available to the virtual machine as a new virtual disk. You can access it and use it as you would any other disk in the virtual machine.

Note: The virsh command has many options and features available for managing KVM virtual machines. Consult the documentation and online resources for more information on the various options and features available with virsh. It is recommended to use virsh with caution, as improper use can cause data loss or disrupt the operation of the virtual machine.

Created Time:2017-10-28 21:38:57  Author:lautturi