]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Feat: adds the command
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 2 Apr 2024 18:14:29 +0000 (15:14 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 2 Apr 2024 18:14:29 +0000 (15:14 -0300)
DOCS.md
IDEAS.md
kvmx

diff --git a/DOCS.md b/DOCS.md
index e837f6bbfe216ffea9473408a7c08d3e0a34fea2..0ca4c6ad99c1a31f5fb35b4867afabeb9a85d242 100644 (file)
--- a/DOCS.md
+++ b/DOCS.md
@@ -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
index 74ab66b8e51b4ea574f2e7ee2d946ddc78951d43..9cce9d1684c23c2169cd1e827f6483ea65d6191a 100644 (file)
--- a/IDEAS.md
+++ b/IDEAS.md
   * 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.
diff --git a/kvmx b/kvmx
index 3a2e6664245cb52263f434f6792123448023c562..ddd949857b97d9c027c82ffdbbc1dfb3b811f33a 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -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 $*