qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-discuss] Discard disk image holes for sparse shrink


From: Friedrich Oslage
Subject: Re: [Qemu-discuss] Discard disk image holes for sparse shrink
Date: Mon, 8 Apr 2019 22:03:01 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3

Yes.

You'll have to use the virtio-scsi driver, to my knowledge it's the only driver that supports block discards.

Quick example:

# create a new empty disk
$ qemu-img create -f qcow2 disk.qcow2 10G

# check size, should only be a few kilobytes
$ du -sh disk.qcow2

# add it to your vm
$ virtsh edit your-vm
  <disk type='block' device='disk'>
    <driver name='qemu' type='qcow2' discard='unmap' detect_zeroes='unmap'/>
    <source dev='/tmp/disk.qcow2'/>
    <target dev='sda' bus='scsi'/>
    <address type='drive' controller='0' bus='0' target='0' unit='0'/>
  </disk>
  <controller type='scsi' index='0' model='virtio-scsi'>
    <driver queues='4'/>
  </controller>

# in your vm, format and mount it
$ mkfs.ext4 /dev/sda
$ mount /dev/sda /mnt/discardtest

# put some data on it
$ dd if=/dev/urandom of=/mnt/discardtest/dummy.bin bs=1M count=1000
$ sync

# on host, check size...it should be about 1GB
$ du -sh disk.qcow2

# in vm, delete file and trim it
$ rm /mnt/discardtest/dummy.bin
$ sync
$ fstrim /mnt/discardtest

# on host, check size...should only be a few megabytes
$ du -sh disk.qcow2


It works with other guest OSes as well, for Windows you just use the Optimize-Volume cmdlets instead of fstrim.

You also don't have to use qcow2 for backing. Anything that can handle discards will do, including sparse files.


My advice, however, would be to use qcow2, since sparse files don't work particularly well. Executing the example above would leave you with about 300MB at the end instead of less than 10MB.

Regards
Friedrich

On 4/5/19 4:04 PM, Narcis Garcia wrote:
No; I want to study the possibility of recovering allocated blocs of
host filesystem when guest filesystem removes its files (unallocates its
blocks).
Host -> HD or SSD (independent) with sparse-mode image
Guest -> Virtual SSD (to signal discards)


El 5/4/19 a les 16:01, Pascal ha escrit:
hello,

if I understand correctly, you want to study the possibility of
recovering deleted files from an SSD disk: is that right ?

regards, lacsaP.

Le jeu. 4 avr. 2019 à 08:24, Narcis Garcia <address@hidden
<mailto:address@hidden>> a écrit :

     Is there a way to specify a disk to be detected as an SSD drive?

     Once reached this, I want to look for the possibility to recover host
     space when a guest discards disk image blocks, and this image is RAW
     format and sparse allocated file.

     Thank you.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]