How to shutdown a windows guest VM in VirtualBox

If you have a guest Windows VM running, you can shut it from the host command line like this:

# VBoxManage controlvm "windows server 2012" acpipowerbutton 

# vboxmanage guestcontrol "windows server 2012" run  --exe  "%SystemRoot%\system32\shutdown.exe" \ 
  --username Administrator  --password Abcd1234   -- shutdown.exe -s -f -t 0

acpibutton does not always work, but the second one appears to work every time.

 

Selective VPN Routing on Linux

If you want to route some ports to the VPN and not all, there is surprisingly little documentation on the Internet..

Here is one method that works. This is written in OORexx but can be converted to Bash easily. Assumption: The VPN IP range is within 10.8.x.x   — change it in the code if your VPN provider is different. This one is meant for the Kalfaoglu.net  VPN service.

Before you can use this, you need to disable the routes provided by the VPN provider. To do this, go into the Properties of your VPN configuration in the NetworkManager, and Select “Ignore automatically obtained routes.”

The following code ONLY routes http/https traffic over the VPN, and nothing else. Connect your VPN, then run the following script:

#!/bin/rexx
/* First enable VPN, then run this script */

/* learn VPN default gateway - it dynamically changes so we need to learn it */ 
'rxqueue /clear' 
'route -n|grep 10.8.|rxqueue' 
if queued()>0 then do 
  parse pull dest . 
end
say 'destination is' dest 
nonvpngateway = '192.168.1.60' /* This is your regular gateway - without VPN enabled*/'
'iptables -t nat -A POSTROUTING -o client -j SNAT --to-source' dest 
'ip route add default via' nonvpngateway ' table 4' 
'ip rule add priority 1000 dport 443 table 3' 
'ip rule add priority 1000 dport 80 table 3' 
'ip route add default via' dest ' table 3' 
'ip route flush cache' 
exit

How to copy from one disk to another, the best way

If you are migrating, say, your /home directory to a new drive, I found the following commands to be the most useful. We assume you went into gparted or a similar tool and formatted the new drive/partition to ext4.

Step 1: Remount the drive

First, remount the new drive with the most efficient parameters. Here the new drive is an SSD and it’s re-mounted in ‘as fast as possible’ parameters. We assume that /dev/sdc1 is your new drive’s partition and that you wanted to mount it to, say, /newhome

# mount -oremount,defaults,noiversion,auto_da_alloc,noatime,errors=remount-ro,inode_readahead_blks=32,discard /dev/sdc1 /newhome

Step 2: The actual copying of data

Here is the rsync command that I found that was the safest and most useful:

# rsync -axHAXWSv  --numeric-ids --info=progress   --delete-excluded  /home/turgut   /newhome  --delete --ignore-times  --exclude='/home/*/.gvfs'   --exclude='/home/*/.l
ocal/share/Trash'   --exclude='/var/run/*'   --exclude='/var/lock/*'   --exclude='/lib/modules/*/volatile/.mounted'   --exclude='/var/cache/apt/archives/*'   --exclude='/home/*/.mozilla/f
irefox/*/Cache'   --exclude='/home/*/.cache/chromium'

This excludes lots of temporary files, and does a checksum-based comparison of the copied files, should you have to re-run this command a second time — and you know you will 🙂   Because we excluded the access times with the remount command, we need the –checksum parameter. This keeps all symlinks, all access rights, dates, etc, all the same. Handles sparse files efficiently and more.

If the verbosity is too much, exclude the ‘v’ parameter and change the –info=progress to –info=progress2  which will give you an ‘animated’ progress line.