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 optionwinposstr
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, buttonsCtrl+Alt+End
can be used instead ofCtrl+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