diff options
| author | Silvio Rhatto <rhatto@riseup.net> | 2024-04-02 15:14:29 -0300 | 
|---|---|---|
| committer | Silvio Rhatto <rhatto@riseup.net> | 2024-04-02 15:14:29 -0300 | 
| commit | 3ff504c70b291d6c41fdd2acbc15c58982f0e847 (patch) | |
| tree | bd366c2c55a340633e7f18ca4181670df98fa1a3 | |
| parent | d888cd87a04162ff05b58a1adce9d07817f335ee (diff) | |
| download | kvmx-3ff504c70b291d6c41fdd2acbc15c58982f0e847.tar.gz kvmx-3ff504c70b291d6c41fdd2acbc15c58982f0e847.tar.bz2 | |
Feat: adds the command
| -rw-r--r-- | DOCS.md | 37 | ||||
| -rw-r--r-- | IDEAS.md | 32 | ||||
| -rwxr-xr-x | kvmx | 79 | 
3 files changed, 116 insertions, 32 deletions
| @@ -40,3 +40,40 @@ Misc documentation on kvmx and qemu.    * https://bugs.launchpad.net/qemu/+bug/1810000      qemu system emulator crashed when using xhci usb controller + +## Manually resizing an image + +Nowadays this can be done with `kvmx growpart <device> <partition> <additional_size>`, but +here goes some manual procedures if needed. + +* Image resize action, doing something like this, thanks to +  https://ahelpme.com/linux/online-resize-of-a-root-ext4-file-system-increase-the-space/ + +    # poweroff +    kvmx poweroff $guest + +    # resize image +    qemu-img resize `kvmx list_image $guest` +5G + +    # power up +    kvmx up $guest + +    # ensure parted is installed +    #sudo apt-get install -y parted +    kvmx ssh $guest sudo apt-get install -y cloud-guest-utils + +    # resize virtual machine root fs - while the partition is mounted! +    # this parted command currently need to be done manually +    #echo resizepart 2 -1 | kvmx ssh $guest sudo parted /dev/vda + +    # See https://unix.stackexchange.com/questions/373063/auto-expand-last-partition-to-use-all-unallocated-space-using-parted-in-batch-m +    #     https://unix.stackexchange.com/questions/190317/gnu-parted-resizepart-in-script#202872 +    #     https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203 +    #     https://techtitbits.com/2018/12/using-parteds-resizepart-non-interactively-on-a-busy-partition/ +    #     https://serverfault.com/questions/870594/resize-partition-to-maximum-using-parted-in-non-interactive-mode +    #kvmx ssh $guest sudo parted /dev/vda resizepart 2 -1 Yes +    kvmx ssh $guest sudo growpart /dev/vda 2 + +    kvmx ssh $guest sudo resize2fs /dev/vda2 +    kvmx ssh $guest sudo touch /forcefsck +    kvmx restart $guest @@ -120,38 +120,6 @@    * http://linux-kernel-driver.blogspot.com.br/2009/06/linux-kernel-development-using.html    * https://bbs.archlinux.org/viewtopic.php?id=177299 -* Image resize action, doing something like this, thanks to -  https://ahelpme.com/linux/online-resize-of-a-root-ext4-file-system-increase-the-space/ - -    # poweroff -    kvmx poweroff $guest - -    # resize image -    qemu-img resize `kvmx list_image $guest` +5G - -    # power up -    kvmx up $guest - -    # ensure parted is installed -    #sudo apt-get install -y parted -    kvmx ssh $guest sudo apt-get install -y cloud-guest-utils - -    # resize virtual machine root fs - while the partition is mounted! -    # this parted command currently need to be done manually -    #echo resizepart 2 -1 | kvmx ssh $guest sudo parted /dev/vda - -    # See https://unix.stackexchange.com/questions/373063/auto-expand-last-partition-to-use-all-unallocated-space-using-parted-in-batch-m -    #     https://unix.stackexchange.com/questions/190317/gnu-parted-resizepart-in-script#202872 -    #     https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203 -    #     https://techtitbits.com/2018/12/using-parteds-resizepart-non-interactively-on-a-busy-partition/ -    #     https://serverfault.com/questions/870594/resize-partition-to-maximum-using-parted-in-non-interactive-mode -    #kvmx ssh $guest sudo parted /dev/vda resizepart 2 -1 Yes -    kvmx ssh $guest sudo growpart /dev/vda 2 - -    kvmx ssh $guest sudo resize2fs /dev/vda2 -    kvmx ssh $guest sudo touch /forcefsck -    kvmx restart $guest -  ## Audio fixes to avoid crackling on input  Implement an option to reduce crackling on sound input. @@ -2457,6 +2457,85 @@ function kvmx_usb_detach {    sudo chown root /dev/bus/usb/$bus/$device  } +# Grow a partition +# This will restart the guest a few times +# Inspired by  https://ahelpme.com/linux/online-resize-of-a-root-ext4-file-system-increase-the-space/ +function kvmx_growpart { +  local device="$1" +  local partition="$2" +  local size="$3" + +  # Syntax check +  if [ -z "$size" ]; then +    echo "usage: $BASENAME growpart $VM <device> <partition> <additional_size>" +    echo "example: $BASENAME growpart test /dev/vda 2 5G" +    exit 1 +  fi + +  # Ensure the guest is running +  if ! kvmx_running; then +    echo "Powering up guest..." +    kvmx_up +  fi + +  # Check for $partition +  echo "Checking for partition ${device}${partition}..." +  echo /bin/test -e ${device}${partition} | kvmx_ssh +  if [ "$?" != "0" ]; then +    echo "Could not determine ${device}${partition} existence, aborting." +    exit 1 +  fi + +  # Ensure cloud-guest-utils is installed +  echo "Checking for cloud-guest-utils availability..." +  echo which growpart | kvmx_ssh &> /dev/null +  if [ "$?" != "0" ]; then + +    echo which apt-get | kvmx_ssh &> /dev/null +    if [ "$?" == "0" ]; then +      kvmx_ssh sudo apt-get install -y cloud-guest-utils +    else +      echo "Please install cloud-guest-utils in the guest first" +      exit 1 +    fi +  fi + +  # Now make sure the guest is off +  echo "Powering off guest" +  kvmx_poweroff + +  # Resize the image +  echo "Resizing the image to an additional ${size}" +  qemu-img resize $image +${size} + +  # Power up +  echo "Powering up the guest again" +  kvmx_up + +  # Resize virtual machine root partition - while the filesystem is mounted! +  # this parted command currently need to be done manually +  # +  # Check https://unix.stackexchange.com/questions/373063/auto-expand-last-partition-to-use-all-unallocated-space-using-parted-in-batch-m +  #       https://unix.stackexchange.com/questions/190317/gnu-parted-resizepart-in-script#202872 +  #       https://bugs.launchpad.net/ubuntu/+source/parted/+bug/1270203 +  #       https://techtitbits.com/2018/12/using-parteds-resizepart-non-interactively-on-a-busy-partition/ +  #       https://serverfault.com/questions/870594/resize-partition-to-maximum-using-parted-in-non-interactive-mode +  # +  #echo resizepart 2 -1 | kvmx ssh $guest sudo parted /dev/vda +  #kvmx_ssh sudo parted /dev/vda resizepart 2 -1 Yes +  echo "Growing ${device}${partition}..." +  kvmx_ssh sudo growpart ${device} ${partition} + +  # Resize the file system and schedule a fsck for the next reboot +  echo "Resizing the ${device}${partition} filesystem..." +  kvmx_ssh sudo resize2fs ${device}${partition} +  kvmx_ssh sudo touch /forcefsck + +  # Restart +  echo "Restarting the guest..." +  kvmx_restart +} +  # Dispatch  if type kvmx_$ACTION 2> /dev/null | grep -q "kvmx_$ACTION ()"; then    __kvmx_initialize $* | 
