Skip to content

Commit

Permalink
Add serial console to VM
Browse files Browse the repository at this point in the history
  • Loading branch information
whiskerz007 committed Apr 10, 2020
1 parent 8e7de73 commit 15ded5c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."

0 comments on commit 15ded5c

Please sign in to comment.