wiki:Xen_Lab8

Version 43 (modified by rock, 15 years ago) (diff)

--

Demo(二):VMGL 操作手冊


【前言】

  • 小叮嚀
    • 請使用 gcc-4.1 來編譯 VMGL,勿使用 gcc-4.3.
    • 必要時請切換 gcc 版本,可以使用 update-alternatives 或是重新建立 gcc 連結.
      $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.1 1
      $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 2
      $ sudo update-alternatives --config gcc
      
      提供“gcc”的替換項式共有 2。
      
        可使用的替換項目
      -----------------------------------------------------
                1    /usr/bin/gcc-4.1
      *+        2    /usr/bin/gcc-4.3
      
      按下 enter 來指定預設選項[*],或者輸入選擇的號碼:1
      Using '/usr/bin/gcc-4.1' to provide 'gcc'.
      

【Step 1: 在 pcXXX 上安裝 VMGL 】

  • @pcXXX - 安裝環境所需套件.
    $ sudo apt-get install build-essential firefox flashplugin-nonfree htop libao2 libasound2 libmikmod2 mesa-common-dev libglu1-mesa-dev mesa-utils libxmu-headers libxmu6 libxmu-dev zlib1g-dev libjpeg62 libjpeg62-dev xutils-dev libxext6 libxext-dev rxvt lwm tightvncserver xauth xvfb xfonts-100dpi xfonts-75dpi culmus xfonts-scalable xfonts-base
    
  • @pcXXX - 下載VMGL.
    $ wget http://www.cs.toronto.edu/~andreslc/software/vmgl-0.1.tar.bz2
    $ tar jxvf vmgl-0.1.tar.bz2
    $ cd ./vmgl.hg/tightvnc/
    
  • @pcXXX - Patch for AMD64_Machine.
    $ wget --no-check-certificate https://trac.nchc.org.tw/grid/raw-attachment/wiki/Xen_GPU_cluster/tightvnc-1.2.9-amd64support.patch
    $ patch -p0 < ../tightvnc/tightvnc-1.2.9-amd64support.patch
    
  • @pcXXX - 設定編譯器路徑.
    $ sudo ln -sf /usr/bin/make /usr/bin/gmake
    
  • @pcXXX - 編譯.
    $ cd ..
    ~/vmgl/vmgl.hg$ make
    
  • @pcXXX - 安裝於 Dom0(host) 端上.
    ~/vmgl/vmgl.hg$ sudo make install-host
    

【Step 2:在 pcXXX 上建構一台 VMGL VM (vg01) 】

  • @pcXXX - 設定你的虛擬機器.
    $ sudo gedit /etc/xen-tools/xen-tools.conf
    
    45  dir = /home
    128 size   = 4Gb      # Disk image size.
    129 memory = 256Mb    # Memory size
    130 swap   = 128Mb    # Swap size
    132 fs     = ext3     # use the EXT3 filesystem for the disk image.
    133 dist   = lenny    # Default distribution to install.
    134 image  = sparse   # Specify sparse vs. full disk images.
    163 gateway   = 192.168.100.254
    164 netmask   = 255.255.255.0
    165 broadcast = 192.168.100.255
    215 mirror = http://free.nchc.org.tw/debian
    
  • @pcXXX - 產生你的虛擬機器.
    $ sudo xen-create-image --hostname=vg01 --ip=192.168.100.X --mac=00:16:XX:XX:XX:XX --force
    

【Step 3: 確認虛擬機器(vg01)正確無誤】

$ sudo gedit /home/domains/vg01.cfg
9  kernel      = '/boot/vmlinuz-2.6.22.9'
10 ramdisk     = '/boot/initrd.img-2.6.22.9'
11 memory      = '256'
12 vcpus       = '4'

# 不需配置顯示卡
# pci         = ['01:00.0'] 

16 root        = '/dev/sda2 ro'
17 disk        = [
                  'file:/home/domains/nvidia/disk.img,sda2,w',
                  'file:/home/domains/nvidia/swap.img,sda1,w',
               ]
26 name        = 'vg01'
 
#
#  Networking
#
31 vif         = [ 'ip=192.168.100.X ,mac=00:16:XX:XX:XX:XX' ]
 
#
#  Behaviour
#
36 on_poweroff = 'destroy'
37 on_reboot   = 'restart'
38 on_crash    = 'restart'

【Step 4: 在 DomU(vg01) 上安裝 VMGL 】

  • @Dom0 - 在 Dom0 上啟動虛擬機器 vg01 並登入.
    $ cd /home/domains
    $ sudo xm create -c vg01.cfg
    
  • @vg01 - 先用 root 免密碼登入 vg01, 然後新增使用者 clouder.
    $ adduser clouder
    
    Adding user `clouder' ...
    Adding new group `clouder' (1000) ...
    Adding new user `clouder' (1000) with group `clouder' ...
    Creating home directory `/home/clouder' ...
    Copying files from `/etc/skel' ...
    Enter new UNIX password:
    Retype new UNIX password:
    passwd: password updated successfully
    Changing the user information for clouder
    Enter the new value, or press ENTER for the default
      Full Name []:
      Room Number []: 
      Work Phone []: 
      Home Phone []: 
      Other []: 
    Is the information correct? [Y/n] y
    
  • @vg01 - 先登出 "root" 並且改用使用者 "clouder" 登入,接著安裝環境所需套件.
    $ logout
    $ sudo apt-get install build-essential gcc-4.1 htop mozilla-plugin-vlc libao2 libasound2 libmikmod2 mesa-common-dev libglu1-mesa-dev mesa-utils libxmu-headers libxmu6 libxmu-dev zlib1g-dev libjpeg62 libjpeg62-dev xutils-dev libxaw7 libxaw7-dev libxext6 libxext-dev rxvt lwm vlc vlc-plugin-alsa tightvncserver udev ntpdate xauth xvfb xfonts-100dpi xfonts-75dpi culmus xfonts-scalable xfonts-base lxde openbox-themes gnome-settings-daemon gnome-settings-daemon-dev gnome-icon-theme wget
    
  • @vg01 - 重新啟動虛擬機器.
    $ sudo reboot
    
  • 說明:輕量級桌面環境相關套件.
    # Designed for lightweight X desktop support.
    
    xfonts-base xfonts-100dpi xfonts-75dpi -> fonts support
    rxvt -> x-terminal-emulator for VNC
    lwm  -> x-window-manager for VNC
    openbox -> X-window-manager for VNC
    lxde -> Lightweight X11 Desktop Environment
    
  • @vg01 - 下載VMGL.
    $ mkdir vmgl
    $ cd ./vmgl
    ~/vmgl$ wget http://www.cs.toronto.edu/~andreslc/software/vmgl-0.1.tar.bz2
    ~/vmgl$ wget http://trac.nchc.org.tw/grid/raw-attachment/wiki/Xen_GPU_cluster/tightvnc-1.2.9-amd64support.patch
    ~/vmgl$ tar jxvf vmgl-0.1.tar.bz2
    ~/vmgl$ cd ./vmgl.hg/tightvnc/
    
  • @vg01 - Patch for AMD64_Machine.
    ~/vmgl/vmgl.hg/tightvnc$ patch -p0 < ../../tightvnc-1.2.9-amd64support.patch
    ~/vmgl$ cd ..
    
  • @vg01 - 設定編譯器路徑.
    ~/vmgl$ sudo ln -sf /usr/bin/make /usr/bin/gmake
    
  • @vg01 - 先檢查 gcc 編譯器版本,並且選擇以下兩種變更方法.
    $ gcc -v
    
  • 方法一: @vg01 - 建立 gcc 連結.
    $ sudo ln -sf /usr/bin/gcc-4.1 /usr/bin/gcc
    
  • 方法二: @vg01 - 更換預設 gcc 版本,從 gcc-4.3 換成 gcc-4.1.
    $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.1 1
    $ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.3 2
    $ sudo update-alternatives --config gcc
    
    提供“gcc”的替換項式共有 2。
    
      可使用的替換項目
    -----------------------------------------------------
              1    /usr/bin/gcc-4.1
    *+        2    /usr/bin/gcc-4.2
    
    按下 enter 來指定預設選項[*],或者輸入選擇的號碼:1
    Using '/usr/bin/gcc-4.1' to provide 'gcc'.
    
  • @vg01 - 確認 gcc 編譯器 版本.
    $ gcc -v
    
    Using built-in specs.
    Target: x86_64-linux-gnu
    Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-checking=release x86_64-linux-gnu
    Thread model: posix
    gcc version 4.1.3 20080308 (prerelease) (Ubuntu 4.1.2-21ubuntu1)
    
  • @vg01 - 建立安裝所需基本目錄.
    ~/vmgl/vmgl.hg$ sudo mkdir -p /usr/lib/xorg/modules/extensions
    
  • @vg01 - 編譯.
    ~/vmgl/vmgl.hg$ make
    
  • @vg01 - 安裝於 DomU(vg01) 端上.
    ~/vmgl/vmgl.hg$ sudo make install-guest
    

【Step 5: VMGL 使用說明: 在Dom0 上的設定】

  • @pcXXX - 將 X-Windows 桌面 export 出來.
    $ export DISPLAY=:0
    
  • @pcXXX - 啟動 VLGL stub-daemon.
    $ stub-daemon
    
  • @pcXXX - 檢查 stub-daemon 所對應的 port(7000) 有無開啟.
    $ netstat -tunlp
    
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
    tcp        0      0 0.0.0.0:8002            0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
    tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
    tcp        0      0 0.0.0.0:7000            0.0.0.0:*               LISTEN      29082/stub-daemon ---> VMGL stub-daemon
    udp        0      0 0.0.0.0:32769           0.0.0.0:*                           -               
    udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -               
    

【Step 6: VMGL 使用說明: 在DomU 上的設定】

  • @vg01 - 設定 DomU 上的字型路徑對應.
    $ sudo mkdir -p /usr/X11R6/lib/X11/
    $ sudo ln -sf /usr/share/fonts/X11/ /usr/X11R6/lib/X11/fonts
    
    # FontPath:
    
    /usr/X11R6/lib/X11/fonts (新路徑)
            or
    /usr/share/fonts/X11     (系統預設路徑)
    
  • @vg01 - 確認 rgb.txt 存在於相對應路徑.
    $ sudo ln -sf /usr/share/X11/rgb.txt /usr/X11R6/lib/X11/rgb.txt
    $ cat /usr/X11R6/lib/X11/rgb.txt
    
  • @vg01 - 切換為超級使用者.
    $ sudo su -
    
  • @vg01 - 設定 vg01 上的 VMGL 環境變數.
    $ cat >> /etc/profile << EOF
    
  • @vg01 - 逐一貼上以下設定.
    GLSTUB=140.XXX.XXX.XXX:7000
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/vmgl
    LD_PRELOAD=/usr/local/lib/vmgl/libGL.so
    export GLSTUB LD_LIBRARY_PATH LD_PRELOAD
    EOF
    
  • @vg01 - 設定 DomU 上的 X forwarding.
    $ echo "X11Forwarding yes" >> /etc/ssh/sshd_config
    
    $ cat >> /etc/ssh/ssh_config << EOF
    
  • @vg01 - 逐一貼上以下設定.
        ForwardX11 yes
        ForwardX11Trusted yes
        EOF
    
  • @vg01 -返回使用者 "clouder".
    $ exit
    
  • @vg01 - 使環境變數生效.
    $ source /etc/profile
    
  • @vg01 - 重新啟動 DomU 上的 SSH Service.
    $ sudo /etc/init.d/ssh restart
    

【Step 7: 在 Dom0 上 透過 X forwarding 登入 DomU 】

  • 使用 X forwarding 的方式登入 DomU.
  • @pcXXX - Using X forwarding.
    $ ssh -X vg01
    
  • @vg01 - 檢查 direct rendering 有無起來.
    $ glxinfo
    
    name of display: localhost:10.0
    display: localhost:10  screen: 0
    direct rendering: Yes
    server glx vendor string: VMGL
    server glx version string: 1.2 VMGL
    server glx extensions:
    client glx vendor string: VMGL
    client glx version string: 1.2 VMGL
    client glx extensions:
    GLX version: 1.3
    GLX extensions:
    OpenGL extensions:
        GL_ARB_depth_texture, GL_ARB_fragment_program, GL_ARB_multisample,
        GL_ARB_multitexture, GL_ARB_occlusion_query, GL_ARB_point_parameters,
        GL_ARB_point_sprite, GL_ARB_shadow, GL_ARB_texture_border_clamp,
        GL_ARB_texture_compression, GL_ARB_texture_cube_map,
        GL_ARB_texture_env_add, GL_ARB_texture_env_combine,
        GL_EXT_texture_env_combine, GL_ARB_texture_env_dot3,
        GL_EXT_texture_env_dot3, GL_ARB_texture_mirrored_repeat,
        GL_ARB_texture_non_power_of_two, GL_ARB_transpose_matrix,
        GL_ARB_vertex_buffer_object, GL_ARB_vertex_program, GL_ARB_window_pos,
        GL_EXT_blend_color, GL_EXT_blend_minmax, GL_EXT_blend_func_separate,
        GL_EXT_blend_subtract, GL_EXT_texture_env_add, GL_EXT_fog_coord,
        GL_EXT_multi_draw_arrays, GL_EXT_secondary_color, GL_EXT_shadow_funcs,
        GL_EXT_stencil_wrap, GL_EXT_texture_cube_map, GL_EXT_texture_edge_clamp,
        GL_EXT_texture_filter_anisotropic, GL_EXT_texture_lod_bias,
        GL_EXT_texture_object, GL_EXT_texture3D, GL_EXT_bgra,
        GL_IBM_rasterpos_clip, GL_NV_fog_distance, GL_NV_fragment_program,
        GL_NV_register_combiners, GL_NV_register_combiners2,
        GL_NV_texgen_reflection, GL_NV_texture_rectangle, GL_NV_vertex_program,
        GL_NV_vertex_program1_1, GL_NV_vertex_program2, GL_SGIS_generate_mipmap,
        GL_CR_state_parameter, GL_CR_cursor_position, GL_CR_bounding_box,
        GL_CR_print_string, GL_CR_tilesort_info, GL_CR_synchronization,
        GL_CR_head_spu_name, GL_CR_performance_info, GL_CR_window_size,
        GL_CR_tile_info, GL_CR_saveframe, GL_CR_readback_barrier_size,
        GL_CR_server_id_sharing, GL_CR_server_matrix
        GLX_ARB_multisample
    OpenGL vendor string: H. Andres Lagar-Cavilla
    OpenGL renderer string: VMGL
    OpenGL version string: 1.5 VMGL 1.9
    0x52 24 dc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  2 1 None
    0x53 24 dc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  2 1 None
    0x54 24 dc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  4 1 None
    0x55 24 dc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  4 1 None
    0x56 24 dc  0 32  0 r  .  .  8  8  8  0  4 24  8 16 16 16 16  2 1 None
    0x57 24 dc  0 32  0 r  .  .  8  8  8  8  4 24  8 16 16 16 16  2 1 None
    0x58 24 dc  0 32  0 r  .  .  8  8  8  0  4 24  8 16 16 16 16  4 1 None
    0x59 24 dc  0 32  0 r  .  .  8  8  8  8  4 24  8 16 16 16 16  4 1 None
    0x23 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  0 0 None
    0x5a 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  0 0 None
    0x5b 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  8 16 16 16 16  0 0 None
    0x5c 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  8 16 16 16 16  0 0 None
    0x5d 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  0 0 None
    0x5e 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  0 0 None
    0x5f 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  0 16 16 16 16  0 0 None
    0x60 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  0 16 16 16 16  0 0 None
    0x61 32 tc  0 32  0 r  y  .  8  8  8  0  4  0  0 16 16 16 16  0 0 None
    0x62 32 tc  0 32  0 r  y  .  8  8  8  8  4  0  0 16 16 16 16  0 0 None
    0x63 32 tc  0 32  0 r  .  .  8  8  8  0  4  0  0 16 16 16 16  0 0 None
    0x64 32 tc  0 32  0 r  .  .  8  8  8  8  4  0  0 16 16 16 16  0 0 None
    0x65 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  2 1 None
    0x66 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  2 1 None
    0x67 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  0 16 16 16 16  4 1 None
    0x68 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  0 16 16 16 16  4 1 None
    0x69 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  0 16 16 16 16  2 1 None
    0x6a 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  0 16 16 16 16  2 1 None
    0x6b 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  0 16 16 16 16  4 1 None
    0x6c 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  0 16 16 16 16  4 1 None
    0x6d 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  2 1 None
    0x6e 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  2 1 None
    0x6f 32 tc  0 32  0 r  y  .  8  8  8  0  4 24  8 16 16 16 16  4 1 None
    0x70 32 tc  0 32  0 r  y  .  8  8  8  8  4 24  8 16 16 16 16  4 1 None
    0x71 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  8 16 16 16 16  2 1 None
    0x72 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  8 16 16 16 16  2 1 None
    0x73 32 tc  0 32  0 r  .  .  8  8  8  0  4 24  8 16 16 16 16  4 1 None
    0x74 32 tc  0 32  0 r  .  .  8  8  8  8  4 24  8 16 16 16 16  4 1 None
    
    # Note: please do not run stub-daemon with "root"
    
  • @vg01 - 上的 glxgears 效能測試.
    $ glxgears
    
    47819 frames in 5.0 seconds = 9563.678 FPS
    46064 frames in 5.0 seconds = 9212.566 FPS
    44584 frames in 5.0 seconds = 8916.581 FPS
    44256 frames in 5.0 seconds = 8850.974 FPS
    44688 frames in 5.0 seconds = 8937.528 FPS
    

【Step 8: 相關應用案例: VNC為例 】

  • @vg01 - 設定VNC passwd.
    $ vncpasswd
    
    VNC directory /home/clouder/.vnc does not exist, creating.
    Password:
    Verify:
    Would you like to enter a view-only password (y/n)? n
    
  • @vg01 - 先啟動一次 VNC server 來產生 vnc 相關設定檔.
    $ vncserver
    
    New 'X' desktop is vg01:1
    
    Creating default startup script /home/clouder/.vnc/xstartup
    Starting applications specified in /home/clouder/.vnc/xstartup
    Log file is /home/clouder/.vnc/vg01:1.log
    
  • @vg01 - VNC 設定檔產生完成後即可先關閉該 VNC server.
    $ vncserver -kill :1
    
  • @vg01 - 修改 VNC 設定檔 xstartup,使得虛擬機器預設桌面使用 LXDE 來啟動.
    $ cd
    $ echo "startlxde &" >> .vnc/xstartup
    
  • @vg01 - 啟動一台 VNC server 並設定解析度.
    $ vncserver -geometry 1024x768 -depth 24 :1
    
  • @pcXXX - 安裝 VNC viewer.
    $ sudo apt-get install xtightvncviewer
    
  • @pcXXX - 執行 VNC viewer,來連結到由 DomU 所產生的虛擬桌面.
    $ vncviewer vg01:1
    
  • @vg01 - Kill 掉 VNC server 的方法.
    $ vncserver -kill :1
    

【課後檢討與討論】

  • 課程全部結束,感謝各位全程的參與!