Resizing libvirt disks. Sharing dirs from host <-> guest
Posted by valqk on
1. Resize
Source: https://doc.opensuse.org/documentation/leap/virtualization/html/book-virtualization/cha-libvirt-storage.html
Inside the guest system, check the current size of the disk (for example /dev/vda).
On the host, resize the logical volume holding the /dev/vda disk of the guest to the required size, for example 200 GB.
On the host, resize the block device related to the disk /dev/mapper/vg00-home of the guest. Note that you can find the DOMAIN_ID with virsh list.
Check that the new disk size is accepted by the guest.
2. Share directory from host to guest
1. enable shared memory
<memoryBacking>
<source type='memfd'/>
<access mode='shared'/>
</memoryBacking>
2. Share the directory
<filesystem type='mount' accessmode='passthrough'>
<driver type='virtiofs'/>
<binary xattr='on'>
<lock posix='on' flock='on'/>
</binary>
<source dir='/mnt/shared_files'/>
<target dir='mount_shared_files'/>
</filesystem>
3. Start/Restart the vm and mount the dir
FSTAB:
mount_shared_files /mnt/host/ virtiofs ro,defaults 0 0
or CLI
mount -t virtiofs mount_shared_files /mnt/host
Source: https://doc.opensuse.org/documentation/leap/virtualization/html/book-virtualization/cha-libvirt-storage.html
Inside the guest system, check the current size of the disk (for example /dev/vda).
fdisk -l /dev/vda
Disk /dev/sda: 160.0 GB, 160041885696 bytes, 312581808 sectors
Units = sectors of 1 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
On the host, resize the logical volume holding the /dev/vda disk of the guest to the required size, for example 200 GB.
lvresize -L 200G /dev/mapper/vg00-home
Extending logical volume home to 200 GiB
Logical volume home successfully resized
On the host, resize the block device related to the disk /dev/mapper/vg00-home of the guest. Note that you can find the DOMAIN_ID with virsh list.
virsh blockresize --path /dev/vg00/home --size 200G DOMAIN_ID
Block device '/dev/vg00/home' is resized
Check that the new disk size is accepted by the guest.
fdisk -l /dev/vda
Disk /dev/sda: 200.0 GB, 200052357120 bytes, 390727260 sectors
Units = sectors of 1 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
2. Share directory from host to guest
1. enable shared memory
<memoryBacking>
<source type='memfd'/>
<access mode='shared'/>
</memoryBacking>
2. Share the directory
<filesystem type='mount' accessmode='passthrough'>
<driver type='virtiofs'/>
<binary xattr='on'>
<lock posix='on' flock='on'/>
</binary>
<source dir='/mnt/shared_files'/>
<target dir='mount_shared_files'/>
</filesystem>
3. Start/Restart the vm and mount the dir
FSTAB:
mount_shared_files /mnt/host/ virtiofs ro,defaults 0 0
or CLI
mount -t virtiofs mount_shared_files /mnt/host
Trackbacks
Trackback specific URI for this entryThis link is not meant to be clicked. It contains the trackback URI for this entry. You can use this URI to send ping- & trackbacks from your own blog to this entry. To copy the link, right click and select "Copy Shortcut" in Internet Explorer or "Copy Link Location" in Mozilla.
No Trackbacks
Comments
Display comments as Linear | ThreadedNo comments