KVM之一: linux如何配置console

 


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/getty@.service file is responsible for the virtual terminals (/dev/tty[X]). /usr/lib/systemd/system/serial-getty@.service 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/serial-getty@.service

步骤:

 

1. First copy the template:

cp /usr/lib/systemd/system/serial-getty@.service /etc/systemd/system/serial-getty@ttyS0.service

 

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/serial-getty@ttyS0.service /etc/systemd/system/getty.target.wants/

 

4. Reload the daemon and start the service:

systemctl daemon-reload # systemctl start serial-getty@ttyS0.service # systemctl enable serial-getty@ttyS0.service

 


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 root@192.168.122.37'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/serial-getty@ttyS0.service → /lib/systemd/system/serial-getty@.service.

 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 
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,905评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,140评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,791评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,483评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,476评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,516评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,905评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,560评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,778评论 1 296
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,557评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,635评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,338评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,925评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,898评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,142评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,818评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,347评论 2 342

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,279评论 0 10
  • 人们问“你怎么还笑的出来” 我只回答“为什么不呢” 就算我生来没手没脚,并不代表我不能成就事业,我爱多彩的生命 ...
    镜中水滴阅读 432评论 0 0
  • 寂寞何处排解 忧伤淡淡 那年 你拉着我的手 说远方有我们追逐的明天 那天 我哭了 披着你送我的围巾 说好的永远不分...
    闲狐兔阅读 195评论 0 0
  • 以为坚持很难,但是每天跟着课程,跑步,已经坚持了15天了。每天一个半到两个小时的锻炼时间。以前想想多难啊,但是在挤...
    二宝糖包阅读 250评论 0 0
  • 从今天开始,我想每天写点工作心得,为成为一个优秀的前端工程师而努力!
    wanghq阅读 174评论 0 0