OpenVZ Console: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
(archive)
 
(2 intermediate revisions by one other user not shown)
Line 52: Line 52:
=== Ubuntu 10.04, 12.04, 14.04 ===
=== Ubuntu 10.04, 12.04, 14.04 ===
[[Image:Screen-Ubuntu-12.04-OpenVZ-console.png|thumb]]  
[[Image:Screen-Ubuntu-12.04-OpenVZ-console.png|thumb]]  
Works for Ubuntu 16.04 if [http://without-systemd.org/wiki/index.php/How_to_remove_systemd_from_an_Ubuntu_Xenial_installation ''systemd'' is replaced with ''SysV init''].
Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:
Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:


Line 198: Line 201:
Feb  6 17:51:54 test daemon.info init: starting pid 1022, tty '/dev/1': '/sbin/getty 38400 console'
Feb  6 17:51:54 test daemon.info init: starting pid 1022, tty '/dev/1': '/sbin/getty 38400 console'
</pre>
</pre>
The above assumes that the last line of <tt>/etc/vx/dists/[https://src.openvz.org/projects/OVZL/repos/vzctl/browse/etc/dists/alpine.conf?at=vzctl-4.9 alpine.conf]</tt> is:
The above assumes that the last line of <tt>/etc/vz/dists/[https://src.openvz.org/projects/OVZL/repos/vzctl/browse/etc/dists/alpine.conf?at=vzctl-4.9 alpine.conf]</tt> is:
<pre>SET_CONSOLE=set_console.sh</pre>
<pre>SET_CONSOLE=set_console.sh</pre>
where the <tt>/etc/vz/dists/scripts/[http://code.metager.de/source/xref/openvz/vzctl/etc/dists/scripts/set_console.sh set_console.sh]</tt> has:
where the <tt>/etc/vz/dists/scripts/[http://code.metager.de/source/xref/openvz/vzctl/etc/dists/scripts/set_console.sh set_console.sh]</tt> has:
Line 437: Line 440:
rmdir -p etc/init</pre>
rmdir -p etc/init</pre>


[[Category:Proxmox VE 3.x]] | [[Category:HOWTO]]
[[Category:Proxmox VE 3.x]] | [[Category: Archive]]

Latest revision as of 15:28, 18 July 2019

Yellowpin.svg Note: Article about old Proxmox VE releases up to 3.x

Introduction

Beginning with Proxmox VE 2.2, we introduced a new console view (with login capability). Especially for beginners it is not that easy to understand and manage containers but with the new console this is big step forward. OpenVZ and KVM console now look quite similar.

But as most OpenVZ templates have disabled terminals, you need to enable it first. This article describes the changes needed for an already running OpenVZ container.

Note:

All Debian templates created with latest Debian Appliance Builder have already got this set of changes, just download them via GUI to your Proxmox VE storage (Debian 6 and 7 templates are up2date, 32 and 64 bit)

Debian 5,6,7

This will also work in debian8 if you use sysv-init instead of systemd

Editing the config file via the host

You can do this on the host without entering CT (but the CT must be running). Just log in to the Proxmox VE host and:

edit all inittabs under /var/lib/vz/root/ :

 nano /var/lib/vz/root/*/etc/inittab

 # add this
 1:2345:respawn:/sbin/getty 38400 tty1

Editing the configuration file inside the container

Screen-Debian-5-OpenVZ-console.png

Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:

List all running container:

proxmox-ve:~# vzlist
     CTID      NPROC STATUS    IP_ADDR         HOSTNAME
      108         23 running   192.168.9.20    ubuntu-1204.proxmox.com
      109         18 running   192.168.9.21    centos63-64.proxmox.com
      111         15 running   192.168.9.23    centos5-64.proxmox.com
      114         14 running   192.168.9.30    deb6-32.proxmox.com
      115         15 running   192.168.9.31    deb7-32.proxmox.com
      122         14 running   192.168.9.36    deb5.proxmox.com

Enter the container:

proxmox-ve:~# vzctl enter 122
root@debian:/# nano /etc/inittab

On the bottom of /etc/inittab just add the following line:

1:2345:respawn:/sbin/getty 38400 tty1

Save the changes and shutdown/start the container via Console.

Ubuntu

Ubuntu 10.04, 12.04, 14.04

Screen-Ubuntu-12.04-OpenVZ-console.png

Works for Ubuntu 16.04 if systemd is replaced with SysV init.

Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:

List all running container:

proxmox-ve:~# vzlist
     CTID      NPROC STATUS    IP_ADDR         HOSTNAME
      108         23 running   192.168.9.20    ubuntu-1404.proxmox.com
      109         18 running   192.168.9.21    centos63-64.proxmox.com
      111         15 running   192.168.9.23    centos5-64.proxmox.com
      114         14 running   192.168.9.30    deb6-32.proxmox.com
      115         15 running   192.168.9.31    deb7-32.proxmox.com
      122         14 running   192.168.9.36    deb5.proxmox.com

Enter the container:

proxmox-ve:~# vzctl enter 108
root@ubuntu-1404:/# nano /etc/init/tty1.conf

Change/Create the file that it looks exactly like this:

# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]

stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 tty1

Save the changes and shutdown/start the container via Console.

Centos

Centos 5 / 7

Screen-Centos-5-OpenVZ-console.png

Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:

List all running container:

proxmox-ve:~# vzlist
     CTID      NPROC STATUS    IP_ADDR         HOSTNAME
      108         23 running   192.168.9.20    ubuntu-1204.proxmox.com
      109         18 running   192.168.9.21    centos63-64.proxmox.com
      111         15 running   192.168.9.23    centos5-64.proxmox.com
      114         14 running   192.168.9.30    deb6-32.proxmox.com
      115         15 running   192.168.9.31    deb7-32.proxmox.com
      122         14 running   192.168.9.36    deb5.proxmox.com

Enter the container:

proxmox-ve:~# vzctl enter 111
root@centos5-64:/# nano /etc/inittab

On the bottom of /etc/inittab just add the following line:

1:2345:respawn:/sbin/agetty tty1 38400 linux

Save the changes and shutdown/start the container via Console.

Centos 6

Screen-Centos-6-OpenVZ-console.png

Login via SSH (or use the VNC "Shell") to your Proxmox VE host and 'vzctl enter CTID' the container:

List all running container:

proxmox-ve:~# vzlist
     CTID      NPROC STATUS    IP_ADDR         HOSTNAME
      108         23 running   192.168.9.20    ubuntu-1204.proxmox.com
      109         18 running   192.168.9.21    centos63-64.proxmox.com
      111         15 running   192.168.9.23    centos5-64.proxmox.com
      114         14 running   192.168.9.30    deb6-32.proxmox.com
      115         15 running   192.168.9.31    deb7-32.proxmox.com
      122         14 running   192.168.9.36    deb5.proxmox.com

Enter the container:

proxmox-ve:~# vzctl enter 109
root@centos63-64:/# nano /etc/init/tty.conf

Change/Create the file that it looks exactly like this:

# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]

stop on runlevel [!2345]

respawn
exec /sbin/agetty -8 tty1 38400

Either run "start tty" without rebooting the container, or save the changes and shutdown/start the container via Console.

Alpine Linux

Alpine v3.5.1

Screen-AlpineLinux-3.5.1-OpenVZ-console.png

The /etc/inittab should have:

# START -------------------------------------
::sysinit:/sbin/openrc sysinit
::sysinit:/sbin/openrc boot
::wait:/sbin/openrc default

# Set up a couple of getty's
#tty1::respawn:/sbin/getty 38400 tty1
#tty2::respawn:/sbin/getty 38400 tty2
#tty3::respawn:/sbin/getty 38400 tty3
#tty4::respawn:/sbin/getty 38400 tty4
#tty5::respawn:/sbin/getty 38400 tty5
#tty6::respawn:/sbin/getty 38400 tty6

# Put a getty on the serial port
#ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100

# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot

# Stuff to do before rebooting
::shutdown:/sbin/openrc shutdown

1:2345:respawn:/sbin/getty 38400 console
2:2345:respawn:/sbin/getty 38400 tty2
# END ---------------------------------------

Note that the last 2 lines are not commented out. On reboot, this will bloat the file /var/log/messages with errors like:

Feb  6 17:47:38 test daemon.info init: can't open /dev/1: No such file or directory
Feb  6 17:47:38 test daemon.info init: can't open /dev/2: No such file or directory
Feb  6 17:47:39 test daemon.info init: process '/sbin/getty 38400 console' (pid 770) exited. Scheduling for restart.
Feb  6 17:47:39 test daemon.info init: process '/sbin/getty 38400 tty2' (pid 771) exited. Scheduling for restart.

This is remedied with:

mknod /dev/1 c 4 1
mknod /dev/2 c 4 2
mknod /dev/tty2 c 4 2
rm /dev/tty1
> /var/log/messages

On reboot, and a NoVNC login and logout will populate the /var/log/messages with just:

Feb  6 17:47:39 test daemon.info init: starting pid 774, tty '/dev/1': '/sbin/getty 38400 console'
Feb  6 17:47:50 test daemon.info init: starting pid 797, tty '/dev/2': '/sbin/getty 38400 tty2'
Feb  6 17:51:50 test auth.info login[1016]: root login on 'console'
Feb  6 17:51:54 test daemon.info init: process '/sbin/getty 38400 console' (pid 774) exited. Scheduling for restart.
Feb  6 17:51:54 test daemon.info init: starting pid 1022, tty '/dev/1': '/sbin/getty 38400 console'

The above assumes that the last line of /etc/vz/dists/alpine.conf is:

SET_CONSOLE=set_console.sh

where the /etc/vz/dists/scripts/set_console.sh has:

#!/bin/sh
#  Copyright (C) 2012-2014, Parallels, Inc. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Configures getty in a container on /dev/tty1 (aka /dev/console)
# and /dev/tty2. Invoked during vzctl start. Needed for vzctl console.

if [ -x /lib/systemd/systemd ]; then
	SYSTEMD_DIR=/lib/systemd/system
else
	SYSTEMD_DIR=/usr/lib/systemd/system
fi
ETC_SYSTEMD_DIR="/etc/systemd/system"

SYSTEMD_GETTY_SERVICE=$SYSTEMD_DIR/getty@.service

create_dev()
{
	local dev=$1
	local major=$2
	local minor=$3

	if [ ! -c /dev/$dev -o -L /dev/$dev ]; then
		rm -f /dev/$dev 2>/dev/null
		mknod /dev/$dev c $major $minor
	fi
}

fix_shell_console()
{
	[ -f $SYSTEMD_DIR/console-getty.service ] &&
		return 0

	echo '#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

[Unit]
Description=Console Shell
After=systemd-user-sessions.service plymouth-quit-wait.service
Before=getty.target

[Service]
Environment=HOME=/root
WorkingDirectory=/root
ExecStart=-/sbin/agetty --noclear -s console 115200,38400,9600
Restart=always
RestartSec=0
UtmpIdentifier=cons
TTYPath=/dev/console
TTYReset=yes
TTYVHangup=yes
StandardInput=tty-force
StandardOutput=inherit
StandardError=inherit
KillMode=process

# Bash ignores SIGTERM, so we send SIGHUP instead, to ensure that bash
# terminates cleanly.
KillSignal=SIGHUP

[Install]
WantedBy=getty.target' > $SYSTEMD_DIR/console-getty.service


	rm -f $SYSTEMD_DIR/console-shell.service
}

setup_systemd_console()
{
	if grep -q -e 'ConditionPathExists=!/run/openvz' \
			-e 'ConditionPathExists=!/proc/vz' $SYSTEMD_GETTY_SERVICE 2>/dev/null; then
		sed -i -e '/ConditionPathExists=!\/run\/openvz/d' \
			-e '/ConditionPathExists=!\/proc\/vz/d' $SYSTEMD_GETTY_SERVICE
	fi

	[ -L  $SYSTEMD_DIR/getty.target.wants/getty@tty1.service ] && \
		rm -f $SYSTEMD_DIR/getty.target.wants/getty@tty1.service
	[ -L  $ETC_SYSTEMD_DIR/getty.target.wants/getty@tty1.service ] && \
		rm -f $ETC_SYSTEMD_DIR/getty.target.wants/getty@tty1.service
	[ -L  $SYSTEMD_DIR/getty.target.wants/getty@tty2.service ] || \
		ln -sf $SYSTEMD_DIR/getty@.service $ETC_SYSTEMD_DIR/getty.target.wants/getty@tty2.service

	[ -f $SYSTEMD_DIR/console-shell.service ] &&
		fix_shell_console
}

setup_upstart_console()
{
	local file=/etc/init/$1.conf
	local getty

	if [ -x /sbin/mingetty ]; then
		getty='exec /sbin/mingetty'
	elif [ -x /sbin/getty ]; then
		getty='exec /sbin/getty 38400'
	else
		echo "Unable to find suitable getty, console setup is skipped"
		return 0
	fi

	echo "start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]
respawn
$getty $1" > $file

}

setup_upstart_event_console()
{
	local file=/etc/init.d/$1
	local getty

	if [ -x /sbin/mingetty ]; then
		getty='exec /sbin/mingetty'
	elif [ -x /sbin/getty ]; then
		getty='exec /sbin/getty 38400'
	else
		echo "Unable to find suitable getty console setup is skipped"
		return 0
	fi

	echo "start on stopped rc2
start on stopped rc3
start on stopped rc4
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
$getty $1" > $file
}

setup_inittab()
{
	local line
	local getty1
	local getty2

	if [ -x /sbin/mingetty ]; then
		getty1='/sbin/mingetty console'
		getty2='/sbin/mingetty tty2'
	elif [ -x /sbin/getty ]; then
		getty1='/sbin/getty 38400 console'
		getty2='/sbin/getty 38400 tty2'
	elif [ -x /sbin/agetty ]; then
		getty1='/sbin/agetty console 38400'
		getty2='/sbin/agetty tty2 38400'
	else
		echo "Unable to find suitable getty, console setup is skipped"
		return 0
	fi
	line="1:2345:respawn:$getty1"
	if ! grep -q "$line" /etc/inittab; then
		echo $line >> /etc/inittab
	fi
	line="2:2345:respawn:$getty2"
	if ! grep -q "$line" /etc/inittab; then
		echo $line >> /etc/inittab
	fi

}

setup_console()
{
	if [ -f "$SYSTEMD_GETTY_SERVICE" ]; then
		setup_systemd_console
	elif [ -d '/etc/init' ]; then
		setup_upstart_console console
		setup_upstart_console tty2
	elif [ -d "/etc/event.d" ]; then
		setup_upstart_event_console console
		setup_upstart_event_console tty2
	elif [ -f "/etc/inittab" ]; then
		setup_inittab
	fi

	create_dev console 5 1
	create_dev tty2 4 2
}

setup_console

exit 0

Troubleshooting

If you still want to use the previous method (vzctl enter CTID) you can open the host Shell and just type vzctl enter CTID to manage your containers.

Java browser plugin

The console is using a Java applet, therefore you need latest Oracle (Sun) Java browser plugin installed and enabled in your browser (Google Chrome and Firefox preferred). If you are on Windows desktop, just go to java.com, if you run a Linux desktop you need to make sure that you run Oracle (Sun) Java plugin instead of the default openjdk. For Debian/Ubuntu based desktops, see Java_Console_(Ubuntu)

Modifying your templates

If you don't want to commit the changes above for every single CT you create, you can simply update the templates accordingly. For this, simply place the file you want to insert into your template (like etc/inittab for debian containers) into your template folder and update the template. The following is specific to CentOS 6, just replace filename/path and contents with the appropriate contents found above.

cd [TEMPLATE LOCATION] #Modify this

mkdir -p etc/init

cat <<EOF >etc/init/tty.conf
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]

stop on runlevel [!2345]

respawn
exec /sbin/agetty -8 tty1 38400
EOF

gunzip centos-6-standard_6.3-1_amd64.tar.gz
tar -rf centos-6-standard_6.3-1_amd64.tar etc
gzip centos-6-standard_6.3-1_amd64.tar

rm etc/init/tty.conf
rmdir -p etc/init

|