[[PageOutline]]
{{{
#!html
實作七:Xen PCI Passthrough 操作
}}}
----
= 【Step 1: 連線到遠端主機】 =
'''# 以下兩種連線方式擇一使用.''' [[BR]]
rider@cloud:~$ ssh 140.xxx.xxx.xxx [[BR]]
rider@cloud:~$ vncviewer 140.xxx.xxx.xxx [[BR]]
----
= 【Step 2: 產生一台虛擬機器】 =
'''# 設定你想要怎樣規格的虛擬機器.''' [[BR]]
rider@cloud:~$ sudo vim /etc/xen-tools/xen-tools.conf [[BR]]
{{{
#!sh
dir = /home
install-method = debootstrap
size = 8Gb # Disk image size.
memory = 1024Mb # Memory size
swap = 128Mb # Swap size
fs = ext3 # use the EXT3 filesystem for the disk image.
dist = hardy # Default distribution to install. ---> For CUDA Support (Ubuntu 8.0.4)
image = sparse # Specify sparse vs. full disk images.
gateway = 140.XXX.XXX.XXX
netmask = 255.255.255.0
broadcast = 140.XXX.XXX.XXX
kernel = /boot/vmlinuz-`uname -r`
initrd = /boot/initrd.img-`uname -r`
mirror = http://gb.archive.ubuntu.com/ubuntu/
ext3_options = noatime,nodiratime,errors=remount-ro
ext2_options = noatime,nodiratime,errors=remount-ro
xfs_options = defaults
reiser_options = defaults
}}}
rider@cloud:~$ sudo xen-create-image --hostname nvidia --ip 140.XXX.XXX.XXX [[BR]]
----
= 【Step 3: 查看你的顯卡資訊】 =
rider@cloud:~$ lspci -vv
{{{
01:00.0 VGA compatible controller: nVidia Corporation GeForce 9800 GT (rev a2)
Subsystem: ASUSTeK Computer Inc. Device 82a0
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- SERR-
Kernel driver in use: pciback
Kernel modules: nvidia, nvidiafb
}}}
----
= 【Step 4: PCI Frontend Configuration 設定你的 DomU 】 =
rider@cloud:~$ sudo vim /etc/xen/nvidia.cfg [[BR]]
{{{
#!sh
kernel = '/boot/vmlinuz-2.6.22.9'
ramdisk = '/boot/initrd.img-2.6.22.9'
memory = '1024'
vcpus = '4'
# 配置你的 PCIE 顯示卡
pci = ['01:00.0']
root = '/dev/sda2 ro'
disk = [
'file:/home/domains/nvidia/disk.img,sda2,w',
'file:/home/domains/nvidia/swap.img,sda1,w',
]
name = 'nvidia'
#
# Networking
#
vif = [ 'ip=140.xxx.xxx.xxx,mac=00:16:3E:AA:70:5C' ]
#
# Behaviour
#
on_poweroff = 'destroy'
on_reboot = 'restart'
on_crash = 'restart'
}}}
----
= 【Step 5: PCI Backend Configuration 設定你的 Dom0 】 =
rider@cloud:~$ sudo su - [[BR]]
'''# Hide the device from dom0 so pciback can take control.''' [[BR]]
root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/nvidia/unbind [[BR]]
'''# Give the dev_ids to pciback, and give it a new slot then bind.''' [[BR]]
root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/pciback/new_slot [[BR]]
root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/pciback/bind [[BR]]
root@cloud:~$ cat /sys/bus/pci/drivers/pciback/slots [[BR]]
{{{
0000:01:00.0
}}}
'''# Caution: Make sure that the device is not controlled by any driver: there should be no driver symlink for nvidia.''' [[BR]]
{{{
PATH: /sys/bus/pci/devices/0000:01:00.0/
driver -> ../../../../bus/pci/drivers/nvidia ---> This symlink shouldn't exist.
}}}
----
= 【Step 6: 硬體直接存取設定】 =
==== Permissive Flag ====
rider@cloud:~$ sudo vim /etc/xen/xend-pci-permissive.sxp [[BR]]
{{{
#!sh
(unconstrained_dev_ids
#('0123:4567:89AB:CDEF')
('0000:01:00.0')
)
}}}
==== User-space Quirks ====
rider@cloud:~$ sudo vim /etc/xen/xend-pci-quirks.sxp [[BR]]
{{{
#!sh
(pci_ids
# Entries are formated as follows:
# :[::]
('10de:0605' # NVIDIA 9800GT
)
)
}}}
----
= 【Step 7: 啟動並登入你的虛擬機器 DomU 】 =
'''說明: 用 root 免密碼先登入,然後建立自己的帳號. 改用自己的帳號登入(亦可用 root 登入 , 不新建帳號 ):''' [[BR]]
@ Dom0 [[BR]]
rider@cloud:~$ sudo xm create -c nvidia.cfg [[BR]]
@ DomU [[BR]]
root@nvidia:~# adduser username [[BR]]
root@nvidia:~# vim /etc/sudoers [[BR]]
{{{
#!sh
username ALL=(ALL) ALL
}}}
----
= 【Step 8: 設定你的 DomU 基本環境】 =
'''# 設定 locales (系統語系)''' [[BR]]
rider@nvidia:~$ sudo vim /etc/profile [[BR]]
{{{
# Locale
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LANG="en_US.UTF-8"
}}}
rider@nvidia:~$ source /etc/profile [[BR]]
rider@nvidia:~$ sudo dpkg-reconfigure locales [[BR]]
'''# 更新 PCI ID Database''' [[BR]]
rider@nvidia:~$ sudo apt-get update [[BR]]
rider@nvidia:~$ sudo apt-get install wget [[BR]]
rider@nvidia:~$ sudo update-pciids [[BR]]
'''# 查看顯卡資訊有無正常顯示''' [[BR]]
rider@nvidia:~$ lspci [[BR]]
{{{
00:00.0 VGA compatible controller: nVidia Corporation GeForce 9800 GT (rev a2)
}}}
'''# 查看顯卡資源有無順利分配到 DomU''' [[BR]]
rider@nvidia:~$ dmesg | grep pci
{{{
pcifront pci-0: Installing PCI frontend
pcifront pci-0: Creating PCI Frontend Bus 0000:00
pciback 0000:00:00.0: probing...
pciback: pcistub_init_devices_late
}}}
----