| | 1 | [[PageOutline]] |
| | 2 | {{{ |
| | 3 | #!html |
| | 4 | <h1 style="text-align: center; color: blue">實作七:Xen PCI Passthrough 操作</h1> |
| | 5 | }}} |
| | 6 | ---- |
| | 7 | = 【Step 1: 連線到遠端主機】 = |
| | 8 | '''# 以下兩種連線方式擇一使用.''' [[BR]] |
| | 9 | rider@cloud:~$ ssh 140.xxx.xxx.xxx [[BR]] |
| | 10 | rider@cloud:~$ vncviewer 140.xxx.xxx.xxx [[BR]] |
| | 11 | ---- |
| | 12 | = 【Step 2: 產生一台虛擬機器】 = |
| | 13 | '''# 設定你想要怎樣規格的虛擬機器.''' [[BR]] |
| | 14 | rider@cloud:~$ sudo vim /etc/xen-tools/xen-tools.conf [[BR]] |
| | 15 | {{{ |
| | 16 | #!sh |
| | 17 | dir = /home |
| | 18 | install-method = debootstrap |
| | 19 | size = 8Gb # Disk image size. |
| | 20 | memory = 1024Mb # Memory size |
| | 21 | swap = 128Mb # Swap size |
| | 22 | fs = ext3 # use the EXT3 filesystem for the disk image. |
| | 23 | dist = hardy # Default distribution to install. ---> For CUDA Support (Ubuntu 8.0.4) |
| | 24 | image = sparse # Specify sparse vs. full disk images. |
| | 25 | gateway = 140.XXX.XXX.XXX |
| | 26 | netmask = 255.255.255.0 |
| | 27 | broadcast = 140.XXX.XXX.XXX |
| | 28 | kernel = /boot/vmlinuz-`uname -r` |
| | 29 | initrd = /boot/initrd.img-`uname -r` |
| | 30 | mirror = http://gb.archive.ubuntu.com/ubuntu/ |
| | 31 | ext3_options = noatime,nodiratime,errors=remount-ro |
| | 32 | ext2_options = noatime,nodiratime,errors=remount-ro |
| | 33 | xfs_options = defaults |
| | 34 | reiser_options = defaults |
| | 35 | }}} |
| | 36 | rider@cloud:~$ sudo xen-create-image --hostname nvidia --ip 140.XXX.XXX.XXX [[BR]] |
| | 37 | ---- |
| | 38 | = 【Step 3: 查看你的顯卡資訊】 = |
| | 39 | rider@cloud:~$ lspci -vv |
| | 40 | {{{ |
| | 41 | 01:00.0 VGA compatible controller: nVidia Corporation GeForce 9800 GT (rev a2) |
| | 42 | Subsystem: ASUSTeK Computer Inc. Device 82a0 |
| | 43 | Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- |
| | 44 | Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx- |
| | 45 | Latency: 0 |
| | 46 | Interrupt: pin A routed to IRQ 16 |
| | 47 | Region 0: Memory at fd000000 (32-bit, non-prefetchable) [size=16M] |
| | 48 | Region 1: Memory at d0000000 (64-bit, prefetchable) [size=256M] |
| | 49 | Region 3: Memory at fa000000 (64-bit, non-prefetchable) [size=32M] |
| | 50 | Region 5: I/O ports at dc80 [size=128] |
| | 51 | [virtual] Expansion ROM at fea00000 [disabled] [size=128K] |
| | 52 | Capabilities: <access denied> |
| | 53 | Kernel driver in use: pciback |
| | 54 | Kernel modules: nvidia, nvidiafb |
| | 55 | }}} |
| | 56 | ---- |
| | 57 | = 【Step 4: PCI Frontend Configuration 設定你的 DomU 】 = |
| | 58 | rider@cloud:~$ sudo vim /etc/xen/nvidia.cfg [[BR]] |
| | 59 | {{{ |
| | 60 | #!sh |
| | 61 | kernel = '/boot/vmlinuz-2.6.22.9' |
| | 62 | ramdisk = '/boot/initrd.img-2.6.22.9' |
| | 63 | |
| | 64 | memory = '1024' |
| | 65 | vcpus = '4' |
| | 66 | |
| | 67 | # 配置你的 PCIE 顯示卡 |
| | 68 | pci = ['01:00.0'] |
| | 69 | |
| | 70 | root = '/dev/sda2 ro' |
| | 71 | disk = [ |
| | 72 | 'file:/home/domains/nvidia/disk.img,sda2,w', |
| | 73 | 'file:/home/domains/nvidia/swap.img,sda1,w', |
| | 74 | ] |
| | 75 | name = 'nvidia' |
| | 76 | |
| | 77 | # |
| | 78 | # Networking |
| | 79 | # |
| | 80 | vif = [ 'ip=140.xxx.xxx.xxx,mac=00:16:3E:AA:70:5C' ] |
| | 81 | |
| | 82 | # |
| | 83 | # Behaviour |
| | 84 | # |
| | 85 | on_poweroff = 'destroy' |
| | 86 | on_reboot = 'restart' |
| | 87 | on_crash = 'restart' |
| | 88 | }}} |
| | 89 | ---- |
| | 90 | = 【Step 5: PCI Backend Configuration 設定你的 Dom0 】 = |
| | 91 | rider@cloud:~$ sudo su - [[BR]] |
| | 92 | '''# Hide the device from dom0 so pciback can take control.''' [[BR]] |
| | 93 | root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/nvidia/unbind [[BR]] |
| | 94 | |
| | 95 | '''# Give the dev_ids to pciback, and give it a new slot then bind.''' [[BR]] |
| | 96 | root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/pciback/new_slot [[BR]] |
| | 97 | root@cloud:~$ echo -n "0000:01:00.0" > /sys/bus/pci/drivers/pciback/bind [[BR]] |
| | 98 | |
| | 99 | root@cloud:~$ cat /sys/bus/pci/drivers/pciback/slots [[BR]] |
| | 100 | {{{ |
| | 101 | 0000:01:00.0 |
| | 102 | }}} |
| | 103 | |
| | 104 | '''# Caution: Make sure that the device is not controlled by any driver: there should be no driver symlink for nvidia.''' [[BR]] |
| | 105 | {{{ |
| | 106 | PATH: /sys/bus/pci/devices/0000:01:00.0/ |
| | 107 | driver -> ../../../../bus/pci/drivers/nvidia ---> This symlink shouldn't exist. |
| | 108 | }}} |
| | 109 | ---- |
| | 110 | = 【Step 6: 硬體直接存取設定】 = |
| | 111 | |
| | 112 | ==== Permissive Flag ==== |
| | 113 | |
| | 114 | rider@cloud:~$ sudo vim /etc/xen/xend-pci-permissive.sxp [[BR]] |
| | 115 | {{{ |
| | 116 | #!sh |
| | 117 | (unconstrained_dev_ids |
| | 118 | #('0123:4567:89AB:CDEF') |
| | 119 | ('0000:01:00.0') |
| | 120 | ) |
| | 121 | }}} |
| | 122 | |
| | 123 | ==== User-space Quirks ==== |
| | 124 | |
| | 125 | rider@cloud:~$ sudo vim /etc/xen/xend-pci-quirks.sxp [[BR]] |
| | 126 | {{{ |
| | 127 | #!sh |
| | 128 | (pci_ids |
| | 129 | # Entries are formated as follows: |
| | 130 | # <vendor>:<device>[:<subvendor>:<subdevice>] |
| | 131 | |
| | 132 | ('10de:0605' # NVIDIA 9800GT |
| | 133 | ) |
| | 134 | ) |
| | 135 | }}} |
| | 136 | ---- |
| | 137 | = 【Step 7: 啟動並登入你的虛擬機器 DomU 】 = |
| | 138 | '''說明: 用 root 免密碼先登入,然後建立自己的帳號. 改用自己的帳號登入(亦可用 root 登入 , 不新建帳號 ):''' [[BR]] |
| | 139 | @ Dom0 [[BR]] |
| | 140 | rider@cloud:~$ sudo xm create -c nvidia.cfg [[BR]] |
| | 141 | |
| | 142 | @ DomU [[BR]] |
| | 143 | root@nvidia:~# adduser username [[BR]] |
| | 144 | root@nvidia:~# vim /etc/sudoers [[BR]] |
| | 145 | {{{ |
| | 146 | #!sh |
| | 147 | username ALL=(ALL) ALL |
| | 148 | }}} |
| | 149 | ---- |
| | 150 | = 【Step 8: 設定你的 DomU 基本環境】 = |
| | 151 | '''# 設定 locales (系統語系)''' [[BR]] |
| | 152 | rider@nvidia:~$ sudo vim /etc/profile [[BR]] |
| | 153 | {{{ |
| | 154 | # Locale |
| | 155 | export LANGUAGE="en_US.UTF-8" |
| | 156 | export LC_ALL="en_US.UTF-8" |
| | 157 | export LANG="en_US.UTF-8" |
| | 158 | }}} |
| | 159 | rider@nvidia:~$ source /etc/profile [[BR]] |
| | 160 | rider@nvidia:~$ sudo dpkg-reconfigure locales [[BR]] |
| | 161 | '''# 更新 PCI ID Database''' [[BR]] |
| | 162 | rider@nvidia:~$ sudo apt-get update [[BR]] |
| | 163 | rider@nvidia:~$ sudo apt-get install wget [[BR]] |
| | 164 | rider@nvidia:~$ sudo update-pciids [[BR]] |
| | 165 | '''# 查看顯卡資訊有無正常顯示''' [[BR]] |
| | 166 | rider@nvidia:~$ lspci [[BR]] |
| | 167 | {{{ |
| | 168 | 00:00.0 VGA compatible controller: nVidia Corporation GeForce 9800 GT (rev a2) |
| | 169 | }}} |
| | 170 | '''# 查看顯卡資源有無順利分配到 DomU''' [[BR]] |
| | 171 | rider@nvidia:~$ dmesg | grep pci |
| | 172 | {{{ |
| | 173 | pcifront pci-0: Installing PCI frontend |
| | 174 | pcifront pci-0: Creating PCI Frontend Bus 0000:00 |
| | 175 | pciback 0000:00:00.0: probing... |
| | 176 | pciback: pcistub_init_devices_late |
| | 177 | }}} |
| | 178 | ---- |