All of lore.kernel.org
 help / color / mirror / Atom feed
* Convert one .img disk created with sparse=true to no sparse
@ 2011-10-20 11:21 Gonzalo Marcote Peña
  2011-10-20 14:43 ` Stefan Hajnoczi
  2011-10-20 14:56 ` Stephane CHAZELAS
  0 siblings, 2 replies; 7+ messages in thread
From: Gonzalo Marcote Peña @ 2011-10-20 11:21 UTC (permalink / raw)
  To: kvm

Hi.
I have one guest that I created with virt-install comand option 'sparse=true'.
As i want to use now this guest for I/O tasks (DDBB) and i want to
improve performance, I want to convert the disk.img from sparse to no
sparse (obviusly without format it).
How can I do this task without loosinf the disk image data?.
Thank you.

Gonzalo

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 11:21 Convert one .img disk created with sparse=true to no sparse Gonzalo Marcote Peña
@ 2011-10-20 14:43 ` Stefan Hajnoczi
  2011-10-20 21:28   ` Simon Wilson
  2011-10-20 14:56 ` Stephane CHAZELAS
  1 sibling, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2011-10-20 14:43 UTC (permalink / raw)
  To: Gonzalo Marcote Peña; +Cc: kvm

On Thu, Oct 20, 2011 at 4:21 AM, Gonzalo Marcote Peña
<gonzalomarcote@gmail.com> wrote:
> Hi.
> I have one guest that I created with virt-install comand option 'sparse=true'.
> As i want to use now this guest for I/O tasks (DDBB) and i want to
> improve performance, I want to convert the disk.img from sparse to no
> sparse (obviusly without format it).
> How can I do this task without loosinf the disk image data?.

If you are using a raw image file:
$ cp --sparse=never old-sparse.img new-allocated.img

This copies the data into the new file and does not try to make zero
regions sparse.  You can then replace the old file with the new file.

Stefan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 11:21 Convert one .img disk created with sparse=true to no sparse Gonzalo Marcote Peña
  2011-10-20 14:43 ` Stefan Hajnoczi
@ 2011-10-20 14:56 ` Stephane CHAZELAS
  2011-10-20 15:57   ` Stephane CHAZELAS
  1 sibling, 1 reply; 7+ messages in thread
From: Stephane CHAZELAS @ 2011-10-20 14:56 UTC (permalink / raw)
  To: kvm

2011-10-20, 13:21(+02), Gonzalo Marcote Peña:
> I have one guest that I created with virt-install comand option 'sparse=true'.
> As i want to use now this guest for I/O tasks (DDBB) and i want to
> improve performance, I want to convert the disk.img from sparse to no
> sparse (obviusly without format it).
> How can I do this task without loosinf the disk image data?.
> Thank you.
[...]

You'll have to make a separate copy anyway as your aim is to
have all the data contiguous on disk.

If it's a raw image.

cat < old.img > new.img

cp --sparse=never old.img new.img

Or you can use qemu-img convert.

Or you could use a LVM volume instead of file. This way, you
have more control on which sectors are allocated and can force
them to be contiguous.

On extent based FS (ext4, btrfs...), there might be a way to
guarantee as few extents as possible, but I don't know it.

-- 
Stephane


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 14:56 ` Stephane CHAZELAS
@ 2011-10-20 15:57   ` Stephane CHAZELAS
  0 siblings, 0 replies; 7+ messages in thread
From: Stephane CHAZELAS @ 2011-10-20 15:57 UTC (permalink / raw)
  To: kvm

2011-10-20, 14:56(+00), Stephane CHAZELAS:
[...]
> On extent based FS (ext4, btrfs...), there might be a way to
> guarantee as few extents as possible, but I don't know it.

Actually, with both ext4 and btrfs, it is possible to defrag a
file in place. So you could un-sparse the file first:

 make sure it is not being used otherwise and:
cat < old.img 1<> old.img
or
pv < old.img 1<> old.img

to get a progress bar.

and defrag it:

e4defrag -v old.img
btrfs filesystem defragment -v old.img

(not tested).
-- 
Stephane


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 14:43 ` Stefan Hajnoczi
@ 2011-10-20 21:28   ` Simon Wilson
  2011-10-21 10:24     ` Stephane CHAZELAS
  2011-10-21 11:20     ` Gonzalo Marcote Peña
  0 siblings, 2 replies; 7+ messages in thread
From: Simon Wilson @ 2011-10-20 21:28 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Gonzalo Marcote Peña, kvm

----- Message from Stefan Hajnoczi <stefanha@gmail.com> ---------
    Date: Thu, 20 Oct 2011 07:43:45 -0700
    From: Stefan Hajnoczi <stefanha@gmail.com>
Subject: Re: Convert one .img disk created with sparse=true to no sparse
      To: Gonzalo Marcote Peña <gonzalomarcote@gmail.com>
      Cc: kvm@vger.kernel.org


> On Thu, Oct 20, 2011 at 4:21 AM, Gonzalo Marcote Peña
> <gonzalomarcote@gmail.com> wrote:
>> Hi.
>> I have one guest that I created with virt-install comand option  
>> 'sparse=true'.
>> As i want to use now this guest for I/O tasks (DDBB) and i want to
>> improve performance, I want to convert the disk.img from sparse to no
>> sparse (obviusly without format it).
>> How can I do this task without loosinf the disk image data?.
>
> If you are using a raw image file:
> $ cp --sparse=never old-sparse.img new-allocated.img
>
> This copies the data into the new file and does not try to make zero
> regions sparse.  You can then replace the old file with the new file.
>
> Stefan
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


----- End message from Stefan Hajnoczi <stefanha@gmail.com> -----

If working with a NON-sparse VM img (i.e. originally created with  
virt-install --nonsparse), does a cp without --sparse=never retain the  
non-sparse nature of the file, or does it have to be specified?

Simon


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 21:28   ` Simon Wilson
@ 2011-10-21 10:24     ` Stephane CHAZELAS
  2011-10-21 11:20     ` Gonzalo Marcote Peña
  1 sibling, 0 replies; 7+ messages in thread
From: Stephane CHAZELAS @ 2011-10-21 10:24 UTC (permalink / raw)
  To: kvm

2011-10-21, 07:28(+10), Simon Wilson:
[...]
> If working with a NON-sparse VM img (i.e. originally created with  
> virt-install --nonsparse), does a cp without --sparse=never retain the  
> non-sparse nature of the file, or does it have to be specified?
[...]

See the man page for your "cp" command. The GNU implementation
of "cp" tries to replicate the sparseness of the files by
default, so if the source file wasn't sparse, the destination
shouldn't be either.

If in doubt, you can always use dd/cat/pv to avoid the extra
fancy hole punching that cp might or might not do.

-- 
Stephane


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Convert one .img disk created with sparse=true to no sparse
  2011-10-20 21:28   ` Simon Wilson
  2011-10-21 10:24     ` Stephane CHAZELAS
@ 2011-10-21 11:20     ` Gonzalo Marcote Peña
  1 sibling, 0 replies; 7+ messages in thread
From: Gonzalo Marcote Peña @ 2011-10-21 11:20 UTC (permalink / raw)
  To: kvm

Thank you Stefan.
That's exactly what i needed.
I worked perfectly.


2011/10/20 Simon Wilson <simon@simonandkate.net>:
> ----- Message from Stefan Hajnoczi <stefanha@gmail.com> ---------
>   Date: Thu, 20 Oct 2011 07:43:45 -0700
>   From: Stefan Hajnoczi <stefanha@gmail.com>
> Subject: Re: Convert one .img disk created with sparse=true to no sparse
>     To: Gonzalo Marcote Peña <gonzalomarcote@gmail.com>
>     Cc: kvm@vger.kernel.org
>
>
>> On Thu, Oct 20, 2011 at 4:21 AM, Gonzalo Marcote Peña
>> <gonzalomarcote@gmail.com> wrote:
>>>
>>> Hi.
>>> I have one guest that I created with virt-install comand option
>>> 'sparse=true'.
>>> As i want to use now this guest for I/O tasks (DDBB) and i want to
>>> improve performance, I want to convert the disk.img from sparse to no
>>> sparse (obviusly without format it).
>>> How can I do this task without loosinf the disk image data?.
>>
>> If you are using a raw image file:
>> $ cp --sparse=never old-sparse.img new-allocated.img
>>
>> This copies the data into the new file and does not try to make zero
>> regions sparse.  You can then replace the old file with the new file.
>>
>> Stefan
>> --
>> To unsubscribe from this list: send the line "unsubscribe kvm" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
> ----- End message from Stefan Hajnoczi <stefanha@gmail.com> -----
>
> If working with a NON-sparse VM img (i.e. originally created with
> virt-install --nonsparse), does a cp without --sparse=never retain the
> non-sparse nature of the file, or does it have to be specified?
>
> Simon
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-10-21 11:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-20 11:21 Convert one .img disk created with sparse=true to no sparse Gonzalo Marcote Peña
2011-10-20 14:43 ` Stefan Hajnoczi
2011-10-20 21:28   ` Simon Wilson
2011-10-21 10:24     ` Stephane CHAZELAS
2011-10-21 11:20     ` Gonzalo Marcote Peña
2011-10-20 14:56 ` Stephane CHAZELAS
2011-10-20 15:57   ` Stephane CHAZELAS

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.