Android with root Git for version control Lircd with Raspberry Pi for IR receiver and sender Tips for Windows Depolying your own password management tool -- KeeWeb Depoly your flask app into Heroku Fix shit IE code manually ISBN to Book Category by Scraping DangDang A Generic Makefile for C/C++ Program Configure Raspberry pi Remove watermark with PyPDF2 tips for docker Anaconda+TensorFlow+CUDA Snippets Configure Remote Mathematica Kernel Build your own ngrok server Access Array SSL VPN 使用Rstudio制作html5幻灯片 tips for Mac OS X system Tips for ipython notebook 配置Ubuntu server + Openbox (Obuntu) tips for Vimperator tips for Vim 安装CUDA My First Jekyll Blog rsync常见选项 在Linux中读取Ipod touch的文件 tip for texmacs 在VPS上建站的一些tip Gnuplot绘图札记 Samba系统和autofs自动挂载 Linux中alsamixer声卡无法录音 搭建自己的RSS订阅器——Tiny Tiny RSS Grub2引导安装Ubuntu awk tips 将Ubuntu系统装入U盘 The Great Rtorrent 编译GCC 再这样剁手!!!该死的libgd 使用ulimit进行资源限制 使用SSH代理上IPV6 使用RCurl抓取网页数据 修复Ubuntu Grub记 openbox中的文件关联 在Ubuntu 12.04下编译qtiplot 处理BCM4312网卡驱动纪实 配置我的Ubuntu Server记 Cygwin杂记 Linux 使普通用户具有以超级权限执行脚本 让firefox自定义地处理文件类型 WordPress优秀主题及插件 在phpcloud上搭建wordpress UBUNTU下用pptpd做VPN server ubuntu升级内核过后的一些问题 安装telnet服务 kubuntu札记 64位kubuntu札记 统计软件R Virtualbox stardict星际译王 Ubuntu重装windows系统后的grub引导修复 SSH服务及花生壳域名解析 采用cbp2make工具由code::blocks工程创建makefile文件 UBUNTU 札记

Virtualbox

2012年07月09日

We normally use VirtualBox to create virtual machine. You may also need install the corresponding extension pack to enable functionality like clipbord synchronzation, usb mount, etc.

CLI for managing the virtual machine

# set environment so that the VBox command can be found easily
set PATH="C:\Program Files\Oracle\VirtualBox";%PATH%

# create a virtual machine and registe it into VBoxManage
VBoxManage createvm --name "VMName" --ostype Ubuntu --register

# you can also create a virtual machine with GUI and following command to registe it
VBoxManage registervm "C:\path\to\your\virtual\machine\VMName.xml"

# then the machine can be list here
VBoxManage list vms

# finally start the VM headlessly
VBoxManage startvm VMName --type headless

Tips

  • Support Windows symlinks inside shared directory under Linux guest machine VBoxManage.exe setextradata VMName 'VBoxInternal2/SharedFoldersEnableSymlinksCreate/<shared_volumn_name>' 1

  • Setup the virtual remote desktop
      # set default RDP auth type with username/password
      VBoxManage setproperty vrdeauthlibrary "VBoxAuthSimple"
      # enable RDP and set the port
      VBoxManage modifyvm "VMNAME" --vrde on
      VBoxManage modifyvm "VMNAME" --vrdeport 5010
      # make RDP require authentication
      VBoxManage modifyvm "VMNAME" --vrdeauthtype external
      # hash your password for later use
      VBoxManage internalcommands passwordhash "<password>"
      # replace <hash> with the previous output
      VBoxManage setextradata "VMNAME" "VBoxAuthSimple/users/<user>" <hash>
    
  • Use Windows buildin RDP client mstsc.exe to log on the remote virtual machine. The third number of option winposstr in rdp configure file can be used to control the startup location of the window, quite useful when you have dual monitor. BTW, if you connect to a windows client with RDP on a windows host, buttons Ctrl+Alt+End can be used instead of Ctrl+Alt+Del inside the remote desktop.

    screen mode id:i:2 # 2 for fullscreen
    winposstr:s:0,1,1920,0,3480,1200 # last 4 digits for x,y position for the window
    
  • Another option: VNC inside the Ubuntu guest The Windows RDP have some problem with clipboard synchronization, replace it with a VNC server like tigervnc inside the guest OS.
      sudo tar xzf tigervnc-1.10.1.x86_64.tar.gz --strip 1 -C /
    
      cat > /lib/systemd/system/vncserver.service <<EOF
      [Unit]
      Description=VNC Server
      After=network.target
    
      [Service]
      User=nick
      Group=nick
      ExecStart=/usr/bin/vncserver :0 -depth 24 -geometry 1920x1200 -dpi 120 -fg
      ExecStop=/usr/bin/vncserver -kill :0
    
      [Install]
      WantedBy=multi-user.target
      EOF
    
      sudo systemctl enable vncserver.service
      sudo systemctl start vncserver.service
    
  • Fix clipboard between VM and windows
      # inside VM setup a server to listen to tcp port
      ncat --sh-exec "DISPLAY=:0 xclip -selection clipboard" --listen 8111 --keep-open
    
      # on the windows client send clipboard to tcp port with powershell
      powershell -command '
          $socket = new-object System.Net.Sockets.TcpClient("IP.YOUR.REMOTE.VM", 8111);
          $stream = $socket.GetStream(); 
          $weriter = new-object System.IO.StreamWriter $stream;
          foreach($l in Get-Clipboard){$writer.WriteLine($l);}
          $writeer.Flush();
          $writer.Close(); $stream.Close(); $socket.Close();'
    
    # Or use following alias if using Cygwin
    if [ "${PALTFORM:0:6}" = "CYGWIN" ]; then
      alias copy2vbox="powershell -command Get-Clipboard |ssh -T vbox 'DISPLAY=:0 xclip -selection clipboard'"
    fi