From 15ded5c61b2176af95e506fdadbc383f53735b85 Mon Sep 17 00:00:00 2001 From: whiskerz007 <2713522+whiskerz007@users.noreply.github.com> Date: Fri, 10 Apr 2020 12:41:07 +0200 Subject: [PATCH] Add serial console to VM --- README.md | 11 +++++++++++ install.sh | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/README.md b/README.md index d14c171..b163902 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,17 @@ homeassistant login: - When you see the `hassio > ` prompt, type `login` - You should now see a `# ` prompt. +## Add a serial port + +By adding a serial port, you are able to use a different interface to interact with the VM. When you click on the down arrow next to `Console` you will be able to use `xterm.js` which enables you to `Right-Click` and get access to `Copy` and `Paste` functions. If the serial port was already added by the install script, no further actions are required to enable the functionality. +- Click on the VM in the list of containers at the left side panel +- Click `Hardware` tab located beside the list of containers +- Click `Add` located beside `Summary` tab, then click `Serial Port` +- `Serial Port` should be set to `0` in the input box, then click `Add` +- Start the VM, if it isn't already +- At the root prompt type `sed -i 's/$/ console=ttyS0/' /mnt/boot/cmdline.txt` +- A `Shutdown` and `Start` is required for the changes to take effect + ## Show Current IP Address To get the current IP address assigned to the VM from the Proxmox interface diff --git a/install.sh b/install.sh index be2454b..29a48f7 100644 --- a/install.sh +++ b/install.sh @@ -19,6 +19,11 @@ function error_exit() { [ ! -z ${VMID-} ] && cleanup_vmid exit $EXIT } +function warn() { + local REASON="\e[97m$1\e[39m" + local FLAG="\e[93m[WARNING]\e[39m" + msg "$FLAG $REASON" +} function info() { local REASON="$1" local FLAG="\e[36m[INFO]\e[39m" @@ -125,4 +130,35 @@ qm importdisk $VMID ${FILE%".gz"} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null qm set $VMID -bootdisk sata0 -efidisk0 ${DISK0_REF},size=128K \ -sata0 ${DISK1_REF},size=6G > /dev/null +# Add serial port and enable console output +set +o errtrace +( + msg "Adding serial port and configuring console..." + trap ' + warn "Unable to configure serial port. VM is still functional." + if [ "$(qm config $VMID | sed -n ''/serial0/p'')" != "" ]; then + qm set $VMID --delete serial0 >/dev/null + fi + exit + ' ERR + if [ "$(command -v kpartx)" = "" ]; then + msg "Installing 'kpartx'..." + apt-get update >/dev/null + apt-get -qqy install kpartx &>/dev/null + fi + DISK1_PATH="$(pvesm path $DISK1_REF)" + DISK1_PART1="$(kpartx -al $DISK1_PATH | awk 'NR==1 {print $1}')" + DISK1_PART1_PATH="/dev/mapper/$DISK1_PART1" + TEMP_MOUNT="${TEMP_DIR}/mnt" + trap ' + findmnt $TEMP_MOUNT >/dev/null && umount $TEMP_MOUNT + command -v kpartx >/dev/null && kpartx -d $DISK1_PATH + ' EXIT + kpartx -a $DISK1_PATH + mkdir $TEMP_MOUNT + mount $DISK1_PART1_PATH $TEMP_MOUNT + sed -i 's/$/ console=ttyS0/' ${TEMP_MOUNT}/cmdline.txt + qm set $VMID -serial0 socket >/dev/null +) + info "Completed Successfully! New VM ID is \e[1m$VMID\e[0m."