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

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

บทความที่ 3 เกี่ยว Virtualization และน่าจะยากที่สุด จนตอนนี้เรามี DirectX Support ใน VMware Products และ OpenGL Support ใน VirtualBox ทั้งคู่สำหรับ Windows Guests เท่านั้น Host Platform ไม่สำคัญ แต่ Linux Guests ไง?

ผมคิดว่าไม่เป็นไปได้ แต่อ่านบทความบน linux.com แสดง 3D บน Linux Guests ได้ด้วย App ชื่อ VMGL ดูมั่นใจและยอดเยี่ยม แต่วุ่นวาย ไม่ใช่แค่ Hack 5-10 นาที Task ใหญ่ ผมตัดสินใจลองดูจริง

คำตอบคือ...

คำตอบ: เวลาเห็น Article/Tutorial/Guide/How-to ที่ใช้วลี "it should work" และ "all you have to do is..." - ระวัง! คุณจะเจอปัญหาเยอะ

บทความต้นฉบับและ Documentation ของ Author ไม่คำนึงถึง ~90% ของ "Dirty Work" ที่ต้องทำเพื่อเข้าใกล้เป้าหมาย ใน Tutorial นี้ผมจะแสดงรายละเอียดน่าขยี้ขยาเกี่ยวกับการ (อาจจะ) ทำ 3D ให้ทำงานใน Linux VMs P.S. อ่าน 2 บทความแรก:

VMGL: OpenGL 3D Acceleration - Uncut Version

เริ่มจาก VMware Server แล้วลอง VirtualBox

Installation

Download และ Install Packages ง่าย มาเป็น RPM Format ถ้ารัน Debian-based (Ubuntu) ต้องติดตั้ง Alien ก่อน Convert RPM เป็น DEB:

sudo apt-get install alien
alien -k package.rpm package.deb
rpm -i package.rpm
# หรือ
dpkg -i package.deb

แทนชื่อ Package จริงของ VMGL ติดตั้งบน Host และ Guest

Note: ติดตั้ง RPMs/DEBs ไม่เห็น Errors แต่อย่างน่าประหลาด Compile จาก Source = Complete Mess ต้อง Satisfy Dependencies เยอะ: build-essential (gcc, make, kernel source, kernel headers) + อื่นๆ (imake, python, opengl headers) Author ไม่ให้ Dependency List ครบ ต้อง Guess Trial-and-Error

และ Source ดู Broken เลย:

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

คุณน่าจะ Give Up ตอนนี้ แต่ถ้าใช้ RPM/DEB อาจคิดว่า OK แล้วดำเนินต่อ...

Load Module

Edit xorg.conf เพิ่ม Section:

Section "Module"
Load "vmglext"
EndSection

Restart Guest X Windows (Ctrl+Alt+Backspace)

Start Xvnc Server

ใน Guest เริ่ม Modified Xvnc Server ที่ควรทำ OpenGL Tunneling แต่นี่คือส่วนวุ่นวาย: Author ใช้ Xvnc Version เก่า (ปี 2003) เหตุผลไม่ชัดเจน Fail บน Modern Distros เพราะ Assume File/Folder Locations ที่ไม่มี

บน SUSE 11.0 และ Ubuntu 8.10 ผม Hack พอสมควรให้ Server รันไม่ Error Errors เยอะ:

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

Fix "Simple":

Download rgb.txt

Error แรก หาไฟล์บน Net (Google) Download วางที่ Package คาดหวัง ลบ Empty Lines ในไฟล์ (Syntax Errors) วางที่ /etc/X11/rgb.txt สร้าง Symlinks:

cd /usr/X11R6/lib/X11
sudo ln -s /usr/share/X11/rgb.txt
cd /usr/share/X11
sudo ln -s /etc/X11/rgb.txt

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

ดู醜陋 และมันจริง! ต่อไป Symlinks Fonts ที่หาย:

cd /usr/X11R6/lib/X11/fonts
sudo ln -s /usr/share/fonts/X11/100dpi
sudo ln -s /usr/share/fonts/X11/75dpi
sudo ln -s /usr/share/fonts/X11/encodings
sudo ln -s /usr/share/fonts/X11/misc
sudo ln -s /usr/share/fonts/X11/Type1
sudo ln -s /usr/share/fonts/X11/util

เปิด 3D Acceleration ใน Linux VMs: Deep Dive กับ VMGL

ตอน Start Xvnc Server ยัง Error แต่คราวนี้รันได้!

บน Host รัน vncviewer Guest ต้องมี IP ป้อนได้จาก Host (Bridged หรือ NAT Networking)

vncviewer guest-ip-address:1

บน Guest Export GLSTUB:

export GLSTUB=guest-ip-address:port

กรณีผม GLSTUB ชี้ Port 7001 Guest IP 192.168.34.129:

export GLSTUB=192.168.34.129:7001

Magic! ควรทำงาน แต่... ไม่ทำงาน glxinfo ไม่見 vmglext driver glxgears เหมือนเดิม ไม่แปลกเพราะ Packages Broken

ลองใหม่ทั้งหมดใน VirtualBox

ผมคิด VMware Server NAT + Proprietary Code เป็นปัญหา ลอง Ubuntu Host, VirtualBox OSE, Ubuntu Guest Config Bridged Networking

Bridged Networking Setup (อาจไม่ตรง Config ของคุณ):

1. Install Bridge Utilities บน Host

sudo apt-get install bridge-utils

2. Declare Bridge ใน Network Scripts

Debian-based: Config ใน /etc/network/interfaces RedHat-based: Scripts แยกต่อ Adapter

sudo gedit /etc/network/interfaces
# เพิ่ม:
auto br0
iface br0 inet static
address 192.168.3.100
netmask 255.255.255.0
gateway 192.168.3.1
bridge_ports eth0 vbox0

3. Declare Virtual Network Adapter สำหรับ VirtualBox

sudo gedit /etc/vbox/interfaces
# เพิ่ม:
vbox0 <your user name> br0

4. Restart Network และ VirtualBox Drivers

sudo service networking restart
sudo /etc/init.d/virtualbox-ose restart

5. Hack Permissions

sudo chown root:vboxusers /dev/net/tun
sudo chmod 666 /dev/net/tun

6. Config Guest ใช้ vbox0 Adapter

ตั้งค่าใน Host ผ่าน Settings Menu ของ VM

7. Power Up Guest ตั้ง Static IP

Subnet เดียวกับ Bridge Increment Last Octet:

sudo ifconfig <device> <ip address> up
# ตัวอย่าง:
sudo ifconfig eth3 192.168.3.101 up

8. ทำซ้ำทุกขั้นตอนก่อนหน้า

กลับไปต้น Uncut Version ทำซ้ำทั้งหมด และ... ไม่ทำงานอีกครั้ง Magic?

สรุป

สรุปคือ: 3D Acceleration บน Linux VMs ไกลเกิน 99.999995% ของ Users รวม Geeks อย่างผม โปรเจกต์นี้ดูเหมือน PhD Work: ครึ่งเสร็จ ไม่ใช้งานได้โดยคนทั่วไป

ทำให้ผมงงว่า ทำไม Claim ว่า "you should all be set" หลัง Hack เล็กน้อย 5 นาทีกลาย 3-4 ชั่วโมงทรมาน ทำไมใช้ Xvnc 6 ปีเก่า?

แต่น่าหงุดหงิดสุดคือ Release Product ในสภาพ Shabby Shame ไม่ใช่ทั้งหมด Lost 2/3 ทำงาน: VMware DirectX Windows Guests, VirtualBox OpenGL Windows Guests = Gems

VMware และ Sun ใหญ่ใน Virtualization Industry เวลาจะทำให้ 3D Acceleration เป็นจริงสำหรับ Linux Users รัน Linux Guests

พิจารณาทุกอย่าง: Linux Host/Linux Guest 3D Acceleration อาจไม่ Priority สำหรับคนส่วนใหญ่ Windows Users ใช้ Windows ถ้าต้องการ Linux จะ Dual-boot Linux Users อยาก Windows Guests สำหรับ Legacy Apps - มี Solution แล้ว (VMware/VirtualBox) Linux-in-Linux Virtualization แนวคิด Wicked แต่ไม่ Priority จะเกิดขึ้น Mark my words

Review สิ่งที่เรียนรู้: ใช้ VMware Server และ VirtualBox 3D Acceleration ใน Windows Guests เรียนรู้ Cool Hacks สำคัญที่สุด: Desktop Virtualization กำลัง Evolve ต่อเนื่อง นำเราไปสู่เป้าหมาย

Cheers.