aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-04-02 15:14:29 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-04-02 15:14:29 -0300
commit3ff504c70b291d6c41fdd2acbc15c58982f0e847 (patch)
treebd366c2c55a340633e7f18ca4181670df98fa1a3
parentd888cd87a04162ff05b58a1adce9d07817f335ee (diff)
downloadkvmx-master.tar.gz
kvmx-master.tar.bz2
Feat: adds the commandHEADmaster
-rw-r--r--DOCS.md37
-rw-r--r--IDEAS.md32
-rwxr-xr-xkvmx79
3 files changed, 116 insertions, 32 deletions
diff --git a/DOCS.md b/DOCS.md
index e837f6b..0ca4c6a 100644
--- 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
diff --git a/IDEAS.md b/IDEAS.md
index 74ab66b..9cce9d1 100644
--- a/IDEAS.md
+++ b/IDEAS.md
@@ -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.
diff --git a/kvmx b/kvmx
index 3a2e666..ddd9498 100755
--- 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 $*