Add serial console to VM

This commit is contained in:
whiskerz007 2020-04-10 12:41:07 +02:00
parent 8e7de734f4
commit 15ded5c61b
No known key found for this signature in database
GPG Key ID: A7EEAB6E1F1A6805
2 changed files with 47 additions and 0 deletions

View File

@ -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

View File

@ -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."