boot2docker: Add volume from windows host to the docker container

boot2docker is great. It allows us to develop using docker even on Windows PCs. One feature that is totally awesome is its ability to share folders on windows host with boot2docker virtual box image. This shared folder from windows can then be used as a volume in the docker containers.

The first part is available to you out of the box. boot2docker shares the c:\User directory with the boot2docker virtualbox image and mounts it under /c/. Yay!

You can add this folder or part of it to the docker container as you would with normal folders.

docker run -it -v /c/:/data/ : bash

This will add the whole C:\User under /data in the launched docker container.

Setting up VNC as Teamviewer alternative

Teamviewer is sometimes really annoying. It has a lot of bugs, crashes very often and doesn’t have a native application for Linux(uses wine…. yewww). Chrome Remote Desktop is nice but it doesn’t allow long term password based connections on Linux. So I resorted to VNC. There is a common conception that setting up VNC is very hard. In this post, I will try to make the process simple.

Setting up the server

Setting up reverse SSH

In most cases the Remote machine is behind a firewall or has dynamic IP address. This makes it impossible to connect the remote machine from the internet. So we will first setup a secure tunnel between Middle server and Remote server. Once this is setup, we can access the Remote machine through the Middle server. The Middle server will always have static IP and is accessible though the internet.

Reverse_ssh_diagram

Install SSH on Middle server

sudo apt-get install openssh-server openssh-client

We have to set a few configuration options in /etc/ssh/sshd_config. Add the following flags or modify them if they already exist in the config file:

ClientAliveInterval 30
ClientAliveCountMax 99999
GatewayPorts yes
AllowTcpForwarding yes
TCPKeepAlive yes

The SSH server has to be restarted for the configuration changes to take effect:

sudo service ssh restart

Install SSH on Remote machine

sudo apt-get install openssh-server openssh-client

From Remote machine establish a SSH reverse tunnel to Middle server,

ssh -nNT -R ssh_tunnel_port:localhost:22 middle_server_username@middle_server_ipaddress

Now you should be able to connect to Remote machine from your client machine using the command,

ssh remote_username@middle_server_ipaddress -p ssh_tunnel_port

Setting up x11vnc in Remote machine

On the Remote machine, install x11vnc and start vnc server on display :0

sudo apt-get install x11vnc
sudo x11vnc -forever -display :0 -auth /home/remote_username/.Xauthority

Setting up client

Tunnel VNC port to client machine

vnc_reverse_ssh

Linux & MacOS

ssh -t -L 5900:localhost:5900 remote_username@middle_server_ipaddress -p ssh_tunnel_port

Windows & Linux & MacOS

You can also use putty to tunnel ports. Download and install Putty from this link.

putty_tunnel_conf2

putty_tunnel_conf

View the remote desktop

You can use this cross-platform chrome extension to view the remote desktop. In the address field provide localhost:5900 and click Connect.

problem installing virtualbox on centos with xen enabled kernel

Today, I tried to install virtualbox 4.0.4 on centOS 5.4( unfortunately that was what I got from my company :( ). Installation went fine, But after i created a virtual machine and tried to start it, I got this error,

Running VirtualBox in a Xen environment is not supported

The problem was with centOS install. centOS installs xen enabled kernel by default. So I installed normal kernel from repository.

yum install kernel.x86_64 kernel-devel.x86_64 kernel-headers.x86_64

We have to configure grub to boot normal kernel by default and not the xen kernel. Set the parameter “default” to point to normal kernel. Now reboot!

After the kernel is up, execute the following command,

sudo /etc/init.d/vboxdrv setup

If everything goes fine, You can now start the virtual machine.

mount virtualbox image( vdi ) on linux

I was using windows on virtual box. Once i had to shutdown the system abruptly. The next time i booted, i got this famous “blue screen of death”. All my precious data were inside the virtual box image. Here is my journey to retrieve the data hidden in virtual box’s vdi format.

First, backup your vdi file. If virtual box is installed in your system, you must have a command called VBoxManage. Lets use it to convert our vdi image into raw image, which can later be mount.

VBoxManage internalcommands converttoraw your_backup_vdi.vdi recover.raw

Substitute the backup vdi file in the above command. The raw image created is recover.raw. Now we have to mount it in order to access the files in it. Execute the following command to mount your raw image,

losetup /dev/loop1 recover.raw

Now query the partition information from fdisk,

fdisk -lu /dev/loop1

Disk /dev/loop7: 44.1 GB, 44108349440 bytes
255 heads, 63 sectors/track, 5362 cylinders, total 86149120 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/loop7p1 * 16065 43070264 21527100 7 HPFS/NTFS
/dev/loop7p2 43070265 86140529 21535132+ 7 HPFS/NTFS

In my case, I had two partitions C and D. To mount one of these partitions, You need the exact address where the partition starts. You can get the exact address by multiplying start sector of the partition with 512(Since a partition is 512 bytes each). So in my case, the first partition starts at 16065 * 512. Now let us mount our partition,

losetup /dev/loop2 recover.raw -o $((16065 * 512))
mount /dev/loop2 /mnt
cd /mnt

Bingo! You have recovered your files.

Note:
If the filesystem type of your partition is ntfs, you have to install fuse and ntfs-3g tools to be able to mount your partition.

Alternative methods:
1) the easiest method is using nbd module and qemu-nbd program. But i couldn’t find those packages in my company’s rpm repository.