CentOS / RHEL 7 : How to configure serial getty with systemd
With SysV init, by default, getty processes are started on the first six virtual consoles. They can be accessed with the Ctrl+Alt+F1 to Ctrl+Alt+F6 key combination. systemd starts the getty processes only when needed. That means, only after you change to, for instance, the second virtual terminal by pressing Ctrl+Alt+F2 is the getty process started in that terminal.
The /usr/lib/systemd/system/[email protected] file is responsible for the virtual terminals (/dev/tty[X]). /usr/lib/systemd/system/[email protected] is responsible for all other terminals, such as a serial terminal on /dev/ttyS0.
Systemd provides a template unit file for serial getty. Template file can be found here /lib/systemd/system/[email protected]
步骤:
1. First copy the template:
cp /usr/lib/systemd/system/[email protected] /etc/systemd/system/[email protected]
2. Then edit the file and modify the agetty line:
[Service] ExecStart=-/sbin/agetty --keep-baud 115200,38400,9600 %I $TERM <-- Change this parameter Type=idle
3. Create a symlink:
ln -s /etc/systemd/system/[email protected] /etc/systemd/system/getty.target.wants/
4. Reload the daemon and start the service:
systemctl daemon-reload # systemctl start [email protected] # systemctl enable [email protected]
Ubuntu16: How to enable KVM virsh console access for Ubuntu Linux VM
KVM is great tool for virtualisation on Linux machines, it provide complete control over Virtual machine and provide reliable alternative in terms of any third-party tools in market.
There are many cloud platforms which are working in Linux virtualisation on back-end. In terms of connectivity we have better option in KVM, which connect it through serial console.
In this post we would see how we could connect Ubuntu17.04 KVM Virtual machine through serial console. I remember in earlier version and distributions, it need to configure serial console in grub file, but in Ubuntu its very easy and reliable as most of configurations and settings are already configured in OS.
let’s see how things happened here …
步骤:
For this post, we are using Ubuntu-17.04 Guest Machine on Ubuntu-16.04 Host machine.
virsh list Id Name State ---------------------------------------------------- 23 ubuntu-17.04 running
How to setup serial console, for same we have to connect machine and login on as root user.
Login through SSH
We could connect on KVM Guest machine through SSH from Host Machine.
ssh 192.168.122.37 [email protected]'s password: Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-19-generic x86_64) ....... ...... ...... ....... Last login: Sun Aug 6 04:16:38 2017 root@srvu:~# hostname srvu
Connect through VNC
We could connect Guest machine through VNC Viewer and could setup Serial console from there. Configuring and connecting VNC viewer posted here. This could be best option to connect Guest machine in any troubleshooting because it could configure without any network connectivity, this also make it same control which we have in serial console with Graphical User Interface from remote host.
Connect with virt-manager
This is Graphical User interface on Host Machine. For this we should have access to Host Machine or Graphical desktop from remote through SSH or VNC.
apt-file search bin/virt-manager virt-manager: /usr/bin/virt-manager
Above package should installed for this command. Like in below image we could connect KVM Guest machine.
Configure a serial console in the Ubuntu guest
After getting login console we need to start serial console and enable it with below two commands.
systemctl start serial-getty@ttyS0 # systemctl enable serial-getty@ttyS0 Created symlink /etc/systemd/system/getty.target.wants/[email protected] → /lib/systemd/system/[email protected].
Now we could connect serial console in easy way with virsh console command.
virsh console ubuntu-17.04
Connected to domain ubuntu-17.04 Escape character is ^]
Ubuntu 17.04 srvu ttyS0 star login: root
Password:
Last login: Sun Aug 6 04:44:22 IST 2017 from 192.168.122.1 on pts/0
Welcome to Ubuntu 17.04 (GNU/Linux 4.10.0-19-generic x86_64)
root@star:~# hostname star
Ubuntu12\14: How to enable KVM virsh console access for Ubuntu Linux VM
以下方法: 在centos6.5也适用
步骤
1. 添加ttyS0启动项
vi /etc/init/ttyS0.conf
#“”内容如下“”
# ttyS0 - getty
#
# This service maintains a getty on ttyS0 from the point the system is
# started until it is shut down again.
start on stopped rc RUNLEVEL=[2345] and (
not-container or
container CONTAINER=lxc or
container CONTAINER=lxc-libvirt)
stop on runlevel [!2345]
respawn
exec /sbin/getty -L 115200 ttyS0 vt102
start ttyS0
2. 选择start命令
root@ecloud:~# which start
/sbin/start
3. 添加ttyS0启动项vi /etc/rc.local
/sbin/start ttyS0