To add a virtual disk with a source path using virsh on Debian 13 (or any system using libvirt), you typically need to:
Here’s how you can do it:
If the VM is running, shut it down first:
bashvirsh shutdown <vm-name> virsh destroy <vm-name> # Force stop if needed
Use virsh edit to modify the VM's configuration:
bashvirsh edit <vm-name>
In the XML editor, locate the <devices> section and add a new <disk> entry. For example, to add a raw disk image (e.g., /path/to/disk.img), use:
xml<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/path/to/disk.img'/> <target dev='vdb' bus='virtio'/> </disk>
type='file': Specifies the disk is a file (use type='block' for physical devices like /dev/sdX).device='disk': Treats the disk as a storage device (other options: cdrom, floppy).<source file='...'>: Path to the disk image or block device.<target dev='vdb' bus='virtio'>:
dev='vdb': The device name (e.g., vda, vdb, sda, etc.).bus='virtio': The bus type (recommended for performance; alternatives: ide, scsi, sata).Save the changes in the editor. The VM's configuration will update automatically.
bashvirsh start <vm-name>
If the VM is running and supports hotplugging, you can attach a disk without editing the XML:
bashvirsh attach-disk <vm-name> /path/to/disk.img vdb --type disk --mode shareable --persistent
--persistent: Ensures the disk remains attached after a reboot.--mode shareable: Allows the disk to be shared (optional).Check if the disk is attached:
bashvirsh domblklist <vm-name>
<vm-name> with your VM's name.type='raw' to type='qcow2'./dev/sdX), use:
xml<disk type='block' device='disk'> <driver name='qemu' type='raw'/> <source dev='/dev/sdX'/> <target dev='vdb' bus='virtio'/> </disk>
Vibe can make mistakes. Check answers. Learn more