[Libguestfs] How to expand a partition (along with the filesystem on it) on a device?
Richard W.M. Jones
rjones at redhat.com
Mon May 12 20:11:04 UTC 2014
On Sun, May 11, 2014 at 09:40:34PM -0500, Peng Yu wrote:
> Hi,
>
> I want to expand /dev/sda5 so that it takes the remaining space in
> /dev/sda. But virt-resize does not work. Does anybody know how to make
> it work? Thanks.
Indeed, virt-resize ignores logical MBR partitions, and as you
discovered it gives an error if you try to use logical partition names
on the command line:
http://libguestfs.org/virt-resize.1.html#logical-partitions
(There is also a BZ open about this, but I can't find it right now)
So it's a bit tricky. All I can suggest (assuming you don't want to
submit patches to fix virt-resize) is this: Use the default behaviour
of virt-resize -- creating a new partition (/dev/sda3) at the end of
the disk -- and then you can expand your root LV over to this extra
partition.
Something like this perhaps:
# virt-resize saiph.qcow2 saiph_expand.qcow2 ## no other parameters
Inside the guest or using guestfish or virt-rescue:
# vgextend mintaka-vg /dev/sda2 /dev/sda3
# lvresize -L '100%FREE' /dev/mintaka-vg/root
Note there is currently no libguestfs binding for vgextend, but we
should add one and an RFE would be welcome.
HTH,
Rich.
> $ sudo virt-filesystems --long -h --all -a saiph.qcow2
> Name Type VFS Label MBR Size Parent
> /dev/sda1 filesystem ext2 - - 243M -
> /dev/sda2 filesystem unknown - - 1.0K -
> /dev/mintaka-vg/root filesystem ext4 - - 7.8G -
> /dev/mintaka-vg/root lv - - - 7.8G /dev/mintaka-vg
> /dev/mintaka-vg vg - - - 7.8G /dev/sda5
> /dev/sda5 pv - - - 7.8G -
> /dev/sda1 partition - - 83 243M /dev/sda
> /dev/sda2 partition - - 05 1.0K /dev/sda
> /dev/sda5 partition - - 8e 7.8G /dev/sda
> /dev/sda device - - - 50G -
> $ sudo virt-filesystems --long -h --all -a saiph_expand.qcow2
> Name Type VFS Label MBR Size Parent
> /dev/sda1 filesystem ext2 - - 243M -
> /dev/sda2 filesystem unknown - - 1.0K -
> /dev/mintaka-vg/root filesystem ext4 - - 7.8G -
> /dev/mintaka-vg/root lv - - - 7.8G /dev/mintaka-vg
> /dev/mintaka-vg vg - - - 7.8G /dev/sda5
> /dev/sda5 pv - - - 7.8G -
> /dev/sda1 partition - - 83 243M /dev/sda
> /dev/sda2 partition - - 05 1.0K /dev/sda
> /dev/sda5 partition - - 8e 7.8G /dev/sda
> /dev/sda device - - - 50G -
>
> $ sudo virt-resize -d --expand /dev/sda5 saiph.qcow2 saiph_expand.qcow2
> command line: virt-resize -d --expand /dev/sda5 saiph.qcow2 saiph_expand.qcow2
> Examining saiph.qcow2 ...
> libguestfs: trace: add_drive "saiph.qcow2" "readonly:true"
> libguestfs: trace: add_drive = 0
> libguestfs: trace: add_drive "saiph_expand.qcow2" "readonly:false"
> libguestfs: trace: add_drive = 0
> libguestfs: trace: launch
> libguestfs: trace: get_tmpdir
> libguestfs: trace: get_tmpdir = "/tmp"
> libguestfs: trace: get_cachedir
> libguestfs: trace: get_cachedir = "/var/tmp"
> libguestfs: trace: launch = 0
> libguestfs: trace: lvm_set_filter "/dev/sda"
> libguestfs: trace: lvm_set_filter = 0
> libguestfs: trace: feature_available "ntfsprogs ntfs3g"
> libguestfs: trace: feature_available = 1
> libguestfs: trace: feature_available "btrfs"
> libguestfs: trace: feature_available = 1
> libguestfs: trace: blockdev_getss "/dev/sdb"
> libguestfs: trace: blockdev_getss = 512
> libguestfs: trace: blockdev_getsize64 "/dev/sda"
> libguestfs: trace: blockdev_getsize64 = 53687091200
> libguestfs: trace: blockdev_getsize64 "/dev/sdb"
> libguestfs: trace: blockdev_getsize64 = 53687091200
> libguestfs: trace: part_get_parttype "/dev/sda"
> libguestfs: trace: part_get_parttype = "msdos"
> saiph.qcow2 size 53687091200 bytes
> saiph_expand.qcow2 size 53687091200 bytes
> partition table type: msdos
> libguestfs: trace: pvs_full
> libguestfs: trace: pvs_full = <struct guestfs_lvm_pv_list *>
> libguestfs: trace: part_list "/dev/sda"
> libguestfs: trace: part_list = <struct guestfs_partition_list *>
> libguestfs: trace: part_get_bootable "/dev/sda" 1
> libguestfs: trace: part_get_bootable = 1
> libguestfs: trace: part_get_mbr_id "/dev/sda" 1
> libguestfs: trace: part_get_mbr_id = 131
> libguestfs: trace: vfs_type "/dev/sda1"
> libguestfs: trace: vfs_type = "ext2"
> libguestfs: trace: mount_ro "/dev/sda1" "/"
> libguestfs: trace: mount_ro = 0
> libguestfs: trace: statvfs "/"
> libguestfs: trace: statvfs = <struct guestfs_statvfs *>
> libguestfs: trace: part_get_bootable "/dev/sda" 2
> libguestfs: trace: part_get_bootable = 0
> libguestfs: trace: part_get_mbr_id "/dev/sda" 2
> libguestfs: trace: part_get_mbr_id = 5
> libguestfs: trace: lvs
> libguestfs: trace: lvs = ["/dev/mintaka-vg/root"]
> libguestfs: trace: vfs_type "/dev/mintaka-vg/root"
> libguestfs: trace: vfs_type = "ext4"
> libguestfs: trace: mount_ro "/dev/mintaka-vg/root" "/"
> libguestfs: trace: mount_ro = 0
> libguestfs: trace: statvfs "/"
> libguestfs: trace: statvfs = <struct guestfs_statvfs *>
> 2 partitions found
> /dev/sda1:
> partition data: 1 1048576-255852543 (254803968 bytes)
> bootable: true
> partition ID: 0x83
> content: filesystem ext2 (246755328 bytes)
> /dev/sda2:
> partition data: 2 256900096-8588886015 (8331985920 bytes)
> bootable: false
> partition ID: 0x5
> content: extended partition
> 1 logical volumes found
> /dev/mintaka-vg/root:
> content: filesystem ext4 (8130584576 bytes)
> calculate surplus: outsize=53687091200 required=8586789888
> overhead=2326528 surplus=45097974784
> libguestfs: trace: canonical_device_name "/dev/sda5"
> libguestfs: trace: canonical_device_name = "/dev/sda5"
> surplus before --expand or --shrink: 45097974784
> virt-resize: error: /dev/sda5: partition not found in the source disk
> image (this error came from '--expand' option on the command line).
> Try running this command: virt-filesystems --partitions --long -a
> saiph.qcow2
>
> If reporting bugs, run virt-resize with the '-d' option and include the
> complete output.
> libguestfs: trace: close
> libguestfs: trace: internal_autosync
> libguestfs: trace: internal_autosync = 0
>
>
> --
> Regards,
> Peng
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list