]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Adds qcow2_compression config, use https://deb.debian.org/debian/ mirror when possible
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 3 Jan 2018 00:04:07 +0000 (22:04 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 3 Jan 2018 00:04:07 +0000 (22:04 -0200)
kvmx
kvmx-create
kvmxfile
share/provision/development
share/provision/messenger

diff --git a/kvmx b/kvmx
index 80fbcffc17cf79f506f2205826ebcf10492c27a2..e4fedb816df6be53e4ab88b17eed880335998dcb 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -1312,6 +1312,11 @@ function kvmx_restart {
     echo "Guest $VM was not running, so starting it anyway..."
     kvmx_start
   else
+    #if [ "$ssh_support" != "y" ]; then
+    #  echo sudo reboot | kvmx_ssh
+    #  exit
+    #fi
+
     echo "Powering off guest $VM..."
     kvmx_poweroff
 
@@ -1616,11 +1621,15 @@ function kvmx_compress {
     exit 1
   fi
 
+  if [ "$qcow2_compression" != "0" ]; then
+    $compression = "-c"
+  fi
+
   # Size before compression
   local size_before_bytes="`du    $image | awk '{ print $1 }'`"
   local size_before_human="`du -h $image | awk '{ print $1 }'`"
 
-  qemu-img convert -O qcow2 -p -c $image $image.new && mv $image.new $image || exit 1
+  qemu-img convert -O qcow2 -p $compression $image $image.new && mv $image.new $image || exit 1
 
   # Size after compression
   local size_after_bytes="`du    $image | awk '{ print $1 }'`"
index cdf3278e30c1e282f50b082f2ba6de8fba278b27..3071346a295d7eebff01f2bfbd81c3d803113bf0 100755 (executable)
@@ -109,7 +109,7 @@ function kvmx_config {
   kvmx_user_config   domain            example.org                      "Domain"
   kvmx_user_config   arch              amd64                            "System arch"
   kvmx_user_config   version           stretch                          "Distro version"
-  kvmx_user_config   mirror            http://http.debian.net/debian/   "Debian mirror"
+  kvmx_user_config   mirror            https://deb.debian.org/debian/   "Debian mirror"
   kvmx_user_config   ssh_support       y                                "Administration using passwordless SSH (y/n)"
   kvmx_user_config   ssh_custom        y                                "Setup a custom SSH keypair (y/n)"
   kvmx_user_config   user              user                             "Initial user name"
@@ -124,6 +124,11 @@ function kvmx_config {
 
   kvmx_user_config   size              3G                               "Image size"
   kvmx_user_config   format            qcow2                            "Image format: raw or qcow2"
+
+  if [ "$format" == "qcow2" ]; then
+    kvmx_user_config qcow2_compression y                                "Image compression (y/n)"
+  fi
+
   kvmx_user_config   method            custom                           "Bootstrap method: custom or vmdeboostrap"
   kvmx_user_config   bootloader        grub                             "Bootloader: grub or extlinux"
 }
@@ -155,6 +160,10 @@ function kvmx_create_vmdebootstrap {
   # Image format
   if [ "$format" == "qcow2" ]; then
     format="--convert-qcow2"
+
+    if [ "$qcow2_compression" == "y" ]; then
+      compression="-c"
+    fi
   fi
 
   if [ "$booloader" == "grub" ]; then
@@ -208,6 +217,7 @@ function kvmx_create_custom {
   fi
 
   # Check for requirements.
+  #for req in debootstrap parted apt-transport-https; do
   for req in debootstrap parted; do
     kvmx_install_package $req
   done
@@ -232,7 +242,7 @@ function kvmx_create_custom {
   # Initial system install.
   echo "Installing base system..."
   kvmx_sudo_run LC_ALL=C DEBIAN_FRONTEND=noninteractive debootstrap \
-    --arch=$arch $version $WORK/ $mirror
+    --force-check-gpg --arch=$arch $version $WORK/ $mirror
 
   # Initial configuration.
   echo "Applying initial configuration..."
@@ -288,11 +298,11 @@ function kvmx_create_custom {
     $APT_INSTALL grub-pc
 
     # Serial console support
-    echo ''                                            >> $WORK/etc/default/grub
-    echo '# Custom configuration'                      >> $WORK/etc/default/grub
-    echo 'GRUB_TERMINAL=serial'                        >> $WORK/etc/default/grub
-    echo 'GRUB_SERIAL_COMMAND="serial --speed=115200"' >> $WORK/etc/default/grub
-    echo 'GRUB_CMDLINE_LINUX="console=ttyS0,115200n8"' >> $WORK/etc/default/grub
+    echo ''                                            | $SUDO tee -a $WORK/etc/default/grub > /dev/null
+    echo '# Custom configuration'                      | $SUDO tee -a $WORK/etc/default/grub > /dev/null
+    echo 'GRUB_TERMINAL=serial'                        | $SUDO tee -a $WORK/etc/default/grub > /dev/null
+    echo 'GRUB_SERIAL_COMMAND="serial --speed=115200"' | $SUDO tee -a $WORK/etc/default/grub > /dev/null
+    echo 'GRUB_CMDLINE_LINUX="console=ttyS0,115200n8"' | $SUDO tee -a $WORK/etc/default/grub > /dev/null
 
     kvmx_sudo_run chroot $WORK/ update-grub
     kvmx_sudo_run chroot $WORK/ grub-install $device
@@ -336,7 +346,7 @@ EOF
   if [ "$format" == "qcow2" ]; then
     echo "Converting raw image to qcow2..."
     kvmx_sudo_run mv $image $image.raw
-    kvmx_sudo_run qemu-img convert -O qcow2 ${image}.raw $image
+    kvmx_sudo_run qemu-img convert -O qcow2 -p $compression ${image}.raw $image
     kvmx_sudo_run rm ${image}.raw
   fi
 
index 9f2310a88bd5d10cf3bbf3b17b3c749245a3aa96..5701f0d8fc6d528c43b9e6f0a11a613e04708939 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -105,6 +105,9 @@ size="10G"
 # Image format: raw or qcow2
 format="qcow2"
 
+# Image compression (qcow2 only)
+qcow2_compression="1"
+
 # Bootstrap method: custom or vmdeboostrap
 method="custom"
 
@@ -121,7 +124,7 @@ arch="amd64"
 version="stretch"
 
 # Debian mirror
-mirror="http://http.debian.net/debian/"
+mirror="https://deb.debian.org/debian/"
 
 # Memory
 memory="2048"
index 0f44c07e6ea55ccfe9e9c5431b452f087bf16ddf..0b477df9e3c5bcdc9e2034f741b2e62a1917b388 100755 (executable)
@@ -30,7 +30,10 @@ APT_INSTALL="sudo LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y"
 cd
 
 # Configuring APT
-sudo sed -i -e "s|main$|main contrib non-free|g" /etc/apt/sources.list || exit 1
+$APT_INSTALL apt-transport-https || exit 1
+sudo sed -i -e "s|http://http.debian.net|https://deb.debian.org|g" /etc/apt/sources.list || exit 1
+sudo sed -i -e "s|http://deb.debian.org|https://deb.debian.org|g"  /etc/apt/sources.list || exit 1
+sudo sed -i -e "s|main$|main contrib non-free|g"                   /etc/apt/sources.list || exit 1
 
 # Upgrade
 if which hydractl &> /dev/null; then
index 895b325e5649f36140ef5c671df8a326eb554823..ceb178c3a19c9df3fa573e6ddc8ebffdb6fdb9e9 100755 (executable)
@@ -35,7 +35,7 @@ $APT_INSTALL curl apt-transport-https
 # Setup Signal repository
 #curl -s https://updates.signal.org/desktop/apt/keys.asc | sudo apt-key add -
 sudo cp $DIRNAME/files/messenger/etc/apt/trusted.gpg.d/signal.org.gpg /etc/apt/trusted.gpg.d/
-echo "deb [arch=amd64] https://updates.signal.org/desktop/apt xenial main" | sudo tee /etc/apt/sources.list.d/signal-xenial.list
+echo "deb [arch=amd64] https://updates.signal.org/desktop/apt xenial main" | sudo tee /etc/apt/sources.list.d/signal-xenial.list > /dev/null
 
 # Install Signal
 sudo apt update && $APT_INSTALL signal-desktop