diff options
-rw-r--r-- | ChangeLog.md | 22 | ||||
-rw-r--r-- | TODO.md | 3 | ||||
-rwxr-xr-x | kvmx | 94 | ||||
-rwxr-xr-x | kvmx-spice-copy | 2 | ||||
-rwxr-xr-x | share/provision/debian/basic | 5 |
5 files changed, 113 insertions, 13 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index 68b066e..b99c8cf 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,26 @@ # ChangeLog -## 0.3.0 - unreleased +## 0.4.0 - Unreleased + +* Adds `kvmx sshdir` action, which SSH's to the guest and changes to a given + folder. If no arguments are given, it tries to change to the equivalent + folder in the guest, so it can be a way to "cd" to the same directory but + inside the guest. + + If the folder in the host is also mounted in the guest in a similar + mountpoint, it's a handy way to move to the same folder, but inside the + guest. + + For folders inside $HOME, user name conversion is automatically done since + the user inside the guest might not match the user in the host. + +## 0.3.0 - 2024-09-19 + +* Increase the maximum number of shared folders to avoid error in when KVMX + attempts to setup too many 9p folder shares: + + kvm: -drive file=/var/cache/qemu/$guest/box.img,if=virtio,discard=unmap: + PCI: no slot/function available for virtio-blk-pci, all in use or reserved` * Per-mountpoint mode option (ro, rw). @@ -51,6 +51,9 @@ ## Folder sharing +* [ ] Dynamically add PCI bridges depending on the number of shared folders, + avoiding PCI slot exhaustion. + * [ ] Mount/umount/remount commands to manage shared folders. * [ ] Try to umount all sshfs volumes in the host when powering off. @@ -19,7 +19,7 @@ # # Basic parameters -VERSION="0.2.0" +VERSION="0.3.0" BASENAME="`basename $0`" DIRNAME="`dirname $0`" ACTION="$1" @@ -897,8 +897,8 @@ function kvmx_hostname { # Remove old hostname from hosts file if [ "\$OLD_HOST" != "$hostname.$domain" ]; then - if grep -q \$OLD_HOST /etc/hosts; then - sudo sed -i -e "/\$OLD_HOST/d" /etc/hosts 2> /dev/null + if grep -q " \$OLD_HOST "/etc/hosts; then + sudo sed -i -e "/ \$OLD_HOST /d" /etc/hosts 2> /dev/null fi fi ##### END REMOTE SCRIPT ####### @@ -965,6 +965,78 @@ function kvmx_ssh { $ssh_env $SSH_COMMAND -p $SSH 127.0.0.1 $* } +# Log into the guest using SSH and cd to a given folder +# +# If no arguments are given, it tries to change to the equivalent folder in the +# guest, so it can be a way to "cd" to the corresponding directory but inside +# the guest. +# +# If the folder in the host is also mounted in the guest in a similar +# mountpoint, it's a handy way to move to the same folder, but inside the +# guest. +# +# For folders inside $HOME, user name conversion is automatically done since +# the user inside the guest might not match the user in the host. +# +# There are a number of ways this can be done: +# +# 1. Trying to move to a folder, and then exec a login shell, which don't +# always work. +# +# 2. Setting a special environment variable which is interpreted by the shell +# startup script and then changes to the requested folder upon login. +# Variable passing can happen directly through command invocation in +# the remote host, or using SSH's SendEnv and AcceptEnv, but this last +# method involves server-side configuration. +# +# Ideally, all approaches should be implemented, and KVMX could choose the +# best one opportunistially, or could have a configuration option to choose, +# defaulting to the one which could work for most cases. +# +function kvmx_sshdir { + if [ "$ssh_support" != "y" ]; then + echo "$BASENAME: SSH support for $VM is disabled" + exit 1 + fi + + if ! kvmx_running || kvmx_suspended; then + echo "$BASENAME: $VM not running, trying to start it..." + kvmx up $VM || exit 1 + #kvmx_up || exit 1 + #echo "$BASENAME: guest $VM is not running" + #exit 1 + fi + + DEST="$*" + + # Defaults to the current folder + if [ -z "$DEST" ]; then + DEST="`pwd`" + + # Fix ~/ path + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + fi + fi + + # Get the SSH configuration + SSH="`cat $SSHFILE`" + + # Implementation using approach 1: change to folder and invoke the login shell + # + # References and discussion: + # + # * https://serverfault.com/questions/167416/how-can-i-automatically-change-directory-on-ssh-login + # * https://stackoverflow.com/questions/626533/how-can-i-ssh-directly-to-a-particular-directory#626670 + # * https://unix.stackexchange.com/questions/86941/how-to-ssh-into-a-specific-directory + # + $ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "cd $DEST && exec \$SHELL --login" + + # Implementation using approach 2, with a special environment variable + # STARTUP_FOLDER, which needs to be supported by the shell startup scripts + #$ssh_env $SSH_COMMAND -t -p $SSH 127.0.0.1 "export STARTUP_FOLDER=$DEST && exec \$SHELL --login" +} + # Enhanced SSH login into the guest function kvmx_login { # This allows the usage of a custom login command @@ -1333,8 +1405,8 @@ function kvmx_rsync_to { fi # Fix ~/ path - if echo $DEST | grep -q -e "^$HOME"; then - DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1370,8 +1442,8 @@ function kvmx_rsync_from { fi # Fix ~/ path - if echo $ORIG | grep -q -e "^$HOME"; then - ORIG="$(echo $ORIG | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$ORIG" | grep -q -e "^$HOME"; then + ORIG="$(echo "$ORIG" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1402,8 +1474,8 @@ function kvmx_scp_from { fi # Fix ~/ path - if echo $ORIG | grep -q -e "^$HOME"; then - ORIG="$(echo $ORIG | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$ORIG" | grep -q -e "^$HOME"; then + ORIG="$(echo "$ORIG" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" @@ -1434,8 +1506,8 @@ function kvmx_scp_to { fi # Fix ~/ path - if echo $DEST | grep -q -e "^$HOME"; then - DEST="$(echo $DEST | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" + if echo "$DEST" | grep -q -e "^$HOME"; then + DEST="$(echo "$DEST" | sed -e "s|^$HOME|/home/$SSH_LOGIN|")" fi SSH="`cat $SSHFILE`" diff --git a/kvmx-spice-copy b/kvmx-spice-copy index 3d87e4f..2b77a35 100755 --- a/kvmx-spice-copy +++ b/kvmx-spice-copy @@ -40,7 +40,7 @@ if [ "$BASENAME" == "kvmx-spice-copy" ]; then echo "naughty.notify({title = \"KVMX Clipboard:\", text =\"Set orig to active window's system\", timeout = 2})" | awesome-client fi - # Optional logging to ~/.xsession-erros + # Optional logging to ~/.xsession-errors #echo "[kvmx-copy] [`date '+%Y%m%d %H:%M:%S'`] set ORIG to $DEST" else if [ -f "$SPOOL" ]; then diff --git a/share/provision/debian/basic b/share/provision/debian/basic index 5344df3..cfd2122 100755 --- a/share/provision/debian/basic +++ b/share/provision/debian/basic @@ -61,6 +61,11 @@ sudo apps/trashman/trashman install grub-serial-console sudo sysctl kernel.unprivileged_bpf_disabled=1 echo "kernel.unprivileged_bpf_disabled=1" | sudo tee /etc/sysctl.d/kernel.unprivileged_bpf_disabled.conf > /dev/null +# Swappiness +# Decrease system swappiness (default is 60), since this is a virtual machine +sudo sysctl vm.swappiness=10 +echo "vm.swappiness = 10" | sudo tee /etc/sysctl.d/vm.swappiness.conf > /dev/null + # Configuring APT sudo apt-get update $APT_INSTALL apt-transport-https || exit 1 |