To add a virtual disk with a source path using virsh on Debian 13 (or any system using libvirt), you typically need to:
virsh
Here’s how you can do it:
If the VM is running, shut it down first:
virsh shutdown <vm-name> virsh destroy <vm-name> # Force stop if needed
Use virsh edit to modify the VM's configuration:
virsh edit
virsh 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:
<devices>
<disk>
/path/to/disk.img
<disk type='file' device='disk'> <driver name='qemu' type='raw'/> <source file='/path/to/disk.img'/> <target dev='vdb' bus='virtio'/> </disk>
type='file'
type='block'
/dev/sdX
device='disk'
cdrom
floppy
<source file='...'>
<target dev='vdb' bus='virtio'>
dev='vdb'
vda
vdb
sda
bus='virtio'
ide
scsi
sata
Save the changes in the editor. The VM's configuration will update automatically.
virsh start <vm-name>
If the VM is running and supports hotplugging, you can attach a disk without editing the XML:
virsh attach-disk <vm-name> /path/to/disk.img vdb --type disk --mode shareable --persistent
--persistent
--mode shareable
Check if the disk is attached:
virsh domblklist <vm-name>
<vm-name>
type='raw'
type='qcow2'
<disk type='block' device='disk'> <driver name='qemu' type='raw'/> <source dev='/dev/sdX'/> <target dev='vdb' bus='virtio'/> </disk>
This is a shared conversation and may include unverified content that doesn't reflect Mistral AI's views. Login to resume chatting.
Vibe can make mistakes. Check answers. Learn more