[Libguestfs] [PATCH] resize: fix 'No space left on device' problem when copying to an extended partition (RHBZ#1169015)

Richard W.M. Jones rjones at redhat.com
Mon Dec 8 11:01:40 UTC 2014


On Mon, Dec 08, 2014 at 11:20:54AM +0800, Hu Tao wrote:
> Because of the size of an extended partition reported by Linux is always 1024
> bytes, so it will always fail to copy to an extended partition.
> 
> This patch fixes this problem by copying to the offset of an extended
> partition in the destination disk.
> 
> Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
> ---
>  resize/resize.ml | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/resize/resize.ml b/resize/resize.ml
> index 363e2b6..ca5f87d 100644
> --- a/resize/resize.ml
> +++ b/resize/resize.ml
> @@ -1139,9 +1139,15 @@ read the man page virt-resize(1).
>              * source = "/dev/sda2", because the device name only covers
>              * the first 1K of the partition.  Instead, copy the
>              * source bytes from the parent disk (/dev/sda).
> +            *
> +            * You can't write directly to the extended partition,
> +            * because the size of it reported by Linux is always 1024
> +            * bytes. Instead, write to the offset of the extended
> +            * partition in the destination disk (/dev/sdb).
>              *)
>             let srcoffset = p.p_part.G.part_start in
> -           g#copy_device_to_device ~srcoffset ~size:copysize "/dev/sda" target
> +           let destoffset = p.p_target_start *^ 512L in
> +           g#copy_device_to_device ~srcoffset ~destoffset ~size:copysize "/dev/sda" "/dev/sdb"
>          )
>        | OpIgnore | OpDelete -> ()
>    in

Seems reasonable, but I'm still testing it ...

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list