[virt-tools-list] Enabling fstrim within VM client

Richard W.M. Jones rjones at redhat.com
Sat Jan 24 11:39:04 UTC 2015


On Sat, Jan 17, 2015 at 12:11:28AM +0100, Richard Taubo wrote:
> On 16 Jan 2015, at 17:49, Cole Robinson <crobinso at redhat.com> wrote:
> > 
> > On 01/15/2015 04:29 PM, Richard Taubo wrote:
> >> Hi!
> >> 
> >> As mentioned in an earlier mail I have installed 
> >> KVM on a logical volume like this (CentOS 7):
> >> [#] lvcreate -L 300G -n lv_vm1 VolGroup
> >> [#] virt-install --name=vm1.mydomain.com \ 
> >> 	--disk path=/dev/VolGroup/lv_vm1 \ 
> >> 	--ram=8192 --os-type=linux --os-variant=rhel7 \ 
> >> 	--vcpus=8 --check-cpu \ 
> >> 	--network bridge:br0 --nographics \
> >> 	--location=/usr/local/src/linux_isos/CENTOS7/CentOS-7.0-1406-x86_64-Minimal.iso \ 
> >> 	--extra-args 'ks=http://www.mydomain.com/anaconda-ks.cfg ksdevice=eth0 \ 
> >> 	ip=192.168.19.2 netmask=255.255.255.192 dns=8.8.8.8 gateway=192.168.19.1 console=ttyS0,115200n8 serial’
> >> 
> >> I would like to run fstrim from within the VM client (I have fstrim working on the VM host machine).
> >> Running fstrim from within the VM gives me errors like this:
> >> 	"fstrim: /usr: FITRIM ioctl failed: Operation not supported"
> >> 
> >> Is it possible to run fstrim on the VM client with the setup described above?
> >> 
> >> Thanks for any feedback!
> > 
> > There's some details here:
> > 
> > http://dustymabe.com/2013/06/11/recover-space-from-vm-disk-images-by-using-discardfstrim/
> > 
> > I think it boils down to using a scsi disk, and using discard=unmap. The blog
> > post doesn't say it but modern virt-install supports the --disk discard
> > option, so you don't need to edit the XML separately.
> 
> 
> Thanks for the link!
> 
> In the comment section there are some comments on using fstrim vs mounting the filesystem with “discard” on the guest.
> I assume that either fstrim or “discard” on the guest will REQUIRE virt-install with --disk discard on the host, correct?

There's a bunch of things that need to happen:

(1) Host RHEL >= 7 -- you've got this.

(2) Guest RHEL also >= 7.

(3) Using virtio-scsi disks.

(4) <driver name="qemu" [...] discard="unmap"> in the libvirt XML.

(5) Inside the guest, mount the filesystem with -o discard.

Try dumping the libvirt XML of the guest and posting it.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the virt-tools-list mailing list