Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Resize KVM VPS
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Resize KVM VPS

Hello guys,

I'm trying to resize a KVM VPS but unsure what is the correct procedure. I increased the hard disk from within SolusVMS from 40GB to 45GB and rebooted the VPS however what is the next step in order to expand the partition of the VPS?

Granted there is data on the VPS that I don't want to loose.

Comments

  • tehdantehdan Member
    edited November 2015

    step 1 - back it up,

    step 2 - sudo resize2fs /
    (if using whole disk vda as a FS, if its partitioned then try parted)

  • perennateperennate Member, Host Rep
    edited November 2015

    If the disk is resized, then you can increase the partition size with fdisk, followed by increasing the filesystem size with resize2fs.

    For online resize, see e.g. https://wiki.lunanode.com/index.php/Frequently_asked_questions#My_disk_space_is_smaller_than_the_plan_disk for the fdisk step; then reboot VM after fdisk step is done, and run resize2fs on the partition

    For offline resize, where you boot to ISO and do resize via live CD, it's easier, you can use something like parted; but pretty much the same thing. Offline resize for the partition is also safer (for filesystem, resize2fs is pretty reliable either way).

    Warning: if you do fdisk step incorrectly then you could lose data.

  • @tehdan said:
    step 1 - back it up,

    step 2 - sudo resize2fs /
    (if using whole disk vda as a FS, if its partitioned then try parted)

    Would I do this from within the host node or within the actual VPS?

  • Better than online resize is booting in either rescue (via VNC) or loading a GRML ISO and do it from there.

  • perennateperennate Member, Host Rep
    edited November 2015

    zafouhar said: Would I do this from within the host node or within the actual VPS?

    Ideally you would do from host node (or use ISO, point is to avoid online resize), but both are possible. If you have a raw disk image, you would register it as block device (see http://dgc.uchicago.edu/20130530/mounting-a-kvm-disk-image-without-kvm/) and then run fdisk on the block device to resize partition. Then you should be able to detect partitions in the block device on host node, and then resize2fs on the partition containing the filesystem.

    Note: if you have qcow2 disk image, then you can use qemu-nbd to register it as block device:

    modprobe nbd
    qemu-nbd --connect=/dev/nbd0 disk.qcow2

    And then disconnect it:

    nbd-client -d /dev/nbd0

    Note: also always good idea to copy the disk image to make a backup before you resize. Also obviously if you have LVM partition the steps are going to be different than if you have disk image.

  • Cool, thanks to both - I managed to resize it fine.

  • KihiKihi Member
    edited November 2015

    Another way (if you're using straight up libvirt / qemu) would be this

    Examine what file systems are on there first.

    virt-filesystems -a image.qcow2
    

    Expand an image and resize it.

    qemu-img create -f qcow2 outfile.qcow2 150G
    virt-resize --expand /dev/sda1 original.qcow2 outfile.qcow2
    
  • elgselgs Member
    edited November 2015

    If you are not using LVM:

    qemu-nbd -c /dev/nbd0 disk.qcow2
    
    echo -e "d\nn\np\n\n\n\nw\n" | fdisk /dev/nbd0
    e2fsck -fy /dev/nbd0p1
    resize2fs /dev/nbd0p1
    
    qemu-nbd -d /dev/nbd0
    

    Do backup before you do anything like this.

Sign In or Register to comment.