Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ซอฟต์แวร์ >> เครื่องเสมือน

เปิดใช้งาน Xen Guest Console Access: คู่มือขั้นตอนต่อขั้นตอน

ปกติ เมื่อคุณ run VMs เป็น domU guests ใน Xen คุณจะ view console ผ่าน virt-manager หรือ virt-viewer สำหรับ all practical purposes (ทุกจุดประสงค์ทางปฏิบัติ) console buffer จะเป็น animated image ที่คุณไม่สามารถ interact (โต้ตอบ) โดยตรง ได้อย่างน้อยจนกว่าจะ boot เข้า graphical interface หากมี

ดังนั้นทำไงหากคุณ願意ให้ console output available at all times (ตลอดเวลา)? คุณสามารถ redirect console output ไปที่ host และทำให้เป็น usable, parsable text ได้ไหม? คำตอบคือ yes (ได้) นี่สามารถทำได้ แต่ไม่ได้ trivial (ง่าย/จริงจัง) มาให้ผมแสดงวิธี achieve (บรรลุ) สำหรับ fully virtualized และ paravirtualized guests ทั้งคู่

Paravirtualized guests (Guests แบบ Para-virtualized)

โดย default console ควร work โดยไม่ต้อง special configurations หรือ tweaks บน your end (ฝั่งคุณ) Unfortunately (น่าเสียดาย) life rarely that fair (ชีวิตหายากที่ fair) ดังนั้นคุณอาจต้อง tweak และ hack เล็กน้อย มี several possible workarounds available

แก้ไข Configuration file

เพิ่ม variations ต่อไปนี้ไปยัง VM configuration file:

extra="console=hvc0 xencons=tty"

คุณอาจระบุ xvc0 แทน hvc0 และใช้ either of the two extra options (ตัวเลือกเพิ่มเติมสองตัว) one key value pair at a time (คู่คีย์-ค่าแต่ละคู่ทีละอัน) คุณอาจต้องทำ several changes และ test ก่อนจะหาว่าอะไร work best หากมี

แก้ไข inittab บน guest ของคุณ

คุณต้องเพิ่ม new console นี้เข้า guest ทำได้โดย edit /etc/inittab ประมาณนี้:

x0:12345:respawn:/sbin/agetty -L 9600 xvc0 xterm

โปรด adjust (ปรับ) console name ตามที่คุณระบุใน VM configuration คุณอาจต้องเปลี่ยน /etc/securetty ให้ include new console นี้ด้วย แค่เปิดไฟล์และเพิ่ม x0 โปรดทำ necessary backups ก่อนทำ changes ทางเลือก คุณอาจต้อง pass extra parameters ไป kernel command line หรือ edit GRUB menu เราจะเห็นอีกตัวอย่างด้านล่าง นี่ควร work แต่แล้วมันอาจไม่ work คุณอาจเห็น sequence of errors ต่อไปนี้ใน /var/log/messages:

init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes
init: Id "x0" respawning too fast: disabled for 5 minutes

หากเกิดขึ้นนี้ guest OS udev อาจไม่ creating device ดังนั้นคุณต้อง create มัน manually ภายใต้ /dev นี่ไม่ใช่ ideal workaround แต่ could help (อาจช่วย) คุณ gain console หาก all the rest of the tweaks ไม่ work for you

สุดท้าย คุณสามารถลอง:

virsh console <domain id>

คุณสามารถ obtain domain id โดยรัน xm list

Fully virtualized guests (Guests แบบ Fully Virtualized)

ตาม man pages xm console not available สำหรับ fully virtualized guests แต่คุณสามารถ resolve ด้วย workaround มี two things ที่ต้องทำ บน host (dom0) ใน relevant configuration file สำหรับ guest เพิ่ม directive ต่อไปนี้:

serial="pty"

ใน guest edit /boot/grub/menu.lst หรือ /boot/grub/grub.conf ด้วย lines ต่อไปนี้ เพิ่มที่นั่น somewhere above first kernel entry (รายการเคอร์เนลแรก) น่าจะ just below (เพียงใต้) default และ timeout directives

serial --unit=0 --speed=9600
terminal --timeout=5 serial console

จากนั้นใน relevant GRUB entry เพิ่มไปที่ kernel line:

console=ttyS0

Reboot guest และคุณควรจะมี console ตอนนี้เพื่อ check คุณต้อง attach console ไปที่ guest จาก dom0 ของคุณ ทำได้ดังนี้:

#xm console <domain name>

บรรทัดจะ drop (ตก/หลุด) และ supposedly (ดูเหมือน/คาดว่า) terminal จะ appear hung (ปรากฏว่า hang) ตอนนี้ หากคุณ reboot guest คุณจะเห็น shutdown/startup messages coming up เพื่อ exit กด Ctrl + ] นี่คือ handful of examples (ตัวอย่างไม่กี่ตัว) แสดง boot และ shutdown รวมถึง kernel crash triggered (กระตุ้น) ด้วย Magic Keys:

#xm console test1
INIT: Switching to runlevel: 6
INIT: Sending processes the TERM signal
INIT: Sending processes the KILL signal
Boot logging started on /dev/ttyS0(/dev/console) at Thu Dec 1 2011
Master Resource Control: previous runlevel: 3, switching to runlevel: 6
Shutting down service at daemon done
Shutting down auditd done
Shutting down automount (force) done

Some images:

Do note that (โปรดสังเกตว่า) console ถูก redirected (เปลี่ยนทิศทาง) ตอนนี้ และจะไม่ show ใน guest คุณจะต้องเพิ่ม console=tty1 ไปที่ GRUB menu เพื่อดู console messages ใน guest ด้วย

อ่านเพิ่มเติม (More reading)

คุณอาจอยาก check เหล่านี้:

Xen troubleshooting

More Xen troubleshooting

Installing SLES11 under Xen

Xen guest console hangs at boot

สรุป

That is all (นั่นคือทั้งหมด) A fairly not-trivial topic (หัวข้อที่ไม่ได้ trivial ค่อนข้าง) แต่ perhaps useful (อาจมีประโยชน์) At the very least (อย่างน้อยที่สุด) คุณเรียนรู้ tad more (นิดหน่อยเพิ่ม) เกี่ยวกับ how to work with Xen command line, how to invoke various commands และ check different parameters, how to edit system configuration files รวมถึง boot menu Last but not the least (สำคัญไม่แพ้กัน) several solutions และ workarounds presented สำหรับ both paravirtualized และ fully virtualized guests Much ado about Xen console (เรื่องราวมากมายเกี่ยวกับ Xen console)

All right (แล้วกัน) Enough for today (พอสำหรับวันนี้) Stay sweet (อยู่ที่น่ารัก/ดีต่อไป)

ขอแสดงความนับถือ