My primary operating system is Linux but since I need to work with Powerpoint too, I installed Windows 7 in VirtualBox. Under Windows I prepare my presentations but I want them synchronized on all my machines. For the synchronization I was using Dropbox.
I had Dropbox on Linux (host machine) and on Windows (guest machine) too. When I edited a file under Windows, Dropbox synced it to the Linux host too (the Windows client uploads it to the cloud; the Linux client downloads it from the cloud). It worked fine, though it was not not optimal. If I didn’t use the Windows guest for a long time, then after a boot I had to wait some time till Dropbox synced everything and I could start working only after that.
However, something happened to the Windows Dropbox client recently. Maybe it’s a bug, I don’t know, but the Dropbox client in my Windows guest became terribly slow. It keeps syncing but it doesn’t upload the changes, or I need to wait an hour or so to upload a file 1 MB of size. This is ridiculous and unacceptable. Note that I dind’t experience similar issues with the Linux client.
How to have a synchronized folder between a Linux host and a Windows guest without a Dropbox client on the guest?
First I made sure that my Dropbox folders were synced between the host and the guest. After this I uninstalled Dropbox on Windows and removed the
C:\Dropbox folder entirely. Since it was synced with the Linux host, I had an exact copy of the
Dropbox folder on Linux. Then shut down the Windows guest.
Here (http://www.maketecheasier.com/share-files-in-virtualbox-between-vista-guest-ubuntu-host) you can find an excellent post on how to set up a shared folder between a Linux host and a Windows guest. On the Linux host I shared my Dropbox folder (
$HOME/Dropbox) that appears now as a new drive in the Windows guest (
G:\ in my case). Now, if I modify something under Windows, it will be visible immediately in the Linux file system that the Dropbox client on Linux will notice and sync.
With this I could solve two problems. First, when I boot up the Windows guest, I don’t need to wait for the Dropbox client to sync. Second, if I change something under Windows, it is still synced to the Dropbox cloud, though I have no Dropbox client on Windows anymore.
I have a laptop that I use for teaching. It is connected to a projector. Everything was fine until today. The next semester starts next Monday, so today I checked if the laptop still works well with some projectors. Nope. Of course not! I tried three classrooms. One projector was OK, but two others didn’t recognize my laptop (“no connection”).
In order to avoid problems with the nvidia driver, I used to keep an old driver on my machine that worked well. When the packages were updated, I always left out the nvidia packages. But something happened since December… So I decided to upgrade all the Nvidia packages too. By the way, I have Ubuntu 12.04 LTS on this laptop. The result almost made me cry: after the upgrade I couldn’t change the resolution on my laptop anymore. If I want to use a projector in clone mode, switching to resolution 1024×768 is mandatory. Damn!
This article saved my ass. It explains how to update your Nvidia driver with the newest one directly from Nvidia. The new driver, which came out in January 2014, works well. I can change the resolution and cloning works too. Phew…
Here I sum up the steps from the aforementioned article:
(1) Download the latest driver for your card from http://www.nvidia.com/Download/index.aspx .
(2) Blacklist the
nouveau driver. “
sudo vi /etc/modprobe.d/blacklist.conf” and add this line to the end:
(3) Switch to the virtual terminal (Ctrl+Alt+F1) and execute these steps:
$ sudo apt-get remove --purge nvidia* $ sudo service lightdm stop # locate the downloaded driver and run it # your version probably will be newer $ sudo sh ./NVIDIA-Linux-x86_64-295.33.run $ sudo reboot
If something went wrong and you encounter some problems during the reboot, here is how to revert the changes. Switch to the virtual terminal (Ctrl+Alt+F1) and execute these steps:
$ sudo sh ./NVIDIA-Linux-x86_64-295.33.run --uninstall $ sudo apt-get install nvidia-current $ sudo service lightdm restart
You have a Windows machine and you want to use Linux (e.g. Ubuntu) in it. That is, you want to install an Ubuntu VM (virtual machine) inside Windows. You want to use the command line only, thus you don’t need any graphical interface. Maybe you have a weak laptop where a graphical VM wouldn’t even run normally. In addition, you want to get it done quickly, you have no time to download an Ubuntu image and go through the installation process. What to do?
Use Vagrant. Vagrant is a tool for building complete development environments. We will use Vagrant with VirtualBox, so we need to install both.
Visit https://www.virtualbox.org/ and select Downloads on the left side. Download and install the latest version for Windows hosts. You can also install the Extension Pack. Make sure to install the version that matches with the previously installed VirtualBox version. We won’t work with VirtualBox directly, but Vagrant is built on top of it, so Vagrant will need it.
Visit http://www.vagrantup.com/downloads and install the Windows version. For the curious, Vagrant is written in Ruby. It is very likely that you will have to restart your computer after the installation. After the restart, you can use the command “
vagrant” in the shell, it is added to the
PATH by the installer.
Basic usage of Vagrant
As indicated in the official guide, using vagrant is very easy.
I suggest that you should create a dedicated directory for your first Ubuntu VM,
C:\vagrant for instance. Enter this directory, open a terminal (with the command “
cmd“) and execute the following commands:
c:\vagrant> vagrant init precise32 http://files.vagrantup.com/precise32.box c:\vagrant> vagrant up
The first command downloads a basic Ubuntu 12.04 LTS image. The second command starts the VM.
Now it’s time to log in to the running VM:
c:\vagrant> vagrant ssh # there is a chance that it won't work...
Well, if it doesn’t work for you under Windows, here is alternative solution: use Putty. Details: hostname: 127.0.0.1, port: 2222, username: vagrant, password: vagrant.
Some other useful commands:
c:\vagrant> vagrant status # Is the VM running? c:\vagrant> vagrant halt # stop the VM; counterpart of "vagrant up"
Use Bash as your shell
The default Windows shell “
cmd” is quite lame. If you want to use a better shell, install the Cygwin environment, which is a Unix compatibility layer for Windows. It’s enough to install the default packages, but don’t forget to add the “
openssh” package too. In my case, I installed the 64-bit version and added the “
c:\cygwin64\bin” directory to my
PATH. After this you can launch the command “
bash” and execute these commands:
$ cd /cygdrive/c/vagrant $ vagrant status # Is it running? $ vagrant up # if it was not running $ vagrant ssh # thanks to the openssh package, it works now ... # work with the VM $ vagrant halt # stop it if you don't need it anymore
Using Vagrant under Linux
Figure out the user agent of your browser. But! You are not allowed to visit http://whatsmyuseragent.com/ or any similar service :)
It’s time to discover netcat, the “Swiss-army knife for TCP/IP”. In a terminal launch
nc and start listening on a port:
$ nc -l 8080
http://localhost:8080 . Switch back to the terminal and you will see something similar:
GET / HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:26.0) Gecko/20100101 Firefox/26.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Connection: keep-alive
Docker extends a common container format called Linux Containers (LXC) with a high-level API providing a lightweight virtualization solution that runs processes in isolation. Docker utilizes LXC, cgroups, and the Linux kernel itself. Unlike traditional virtual machines, a Docker container does not include a separate operating system, instead it relies on the operating system’s functionality provided by the underlying infrastructure. (via wikipedia)
In the following, I want to concentrate on how to install Docker and how to make it run on Ubuntu. To learn more about Docker (what is it good for, what can it do for you, etc.), you will have to do some research on your own. But I also plan to make more blog posts on Docker where I want to write about its use cases.
This entry is based on this post, written by Csaba Okrona. For more info check out his excellent post.
At the time of writing docker was not supported on 32 bit machines. Installing the prerequisites and docker on
$ sudo apt-get install linux-image-extra-$(uname -r) software-properties-common $ sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -" $ sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" $ sudo apt-get update $ sudo apt-get install lxc-docker
Let’s try it. Pull down an ubuntu base image:
$ sudo docker pull ubuntu Pulling repository ubuntu ...
Let’s execute a command inside docker:
$ sudo docker run ubuntu /bin/echo hello from docker hello from docker
echo command was executed in the docker container, it produced an output, and this output was returned to the host (your machine).
Execute docker as non-root
As you noticed,
docker must be executed with
sudo. If you want to execute it with your non-root account, here is what to do:
# create the 'docker' group $ sudo groupadd docker # probably it already exists # add your user to the 'docker' group $ sudo gpasswd -a USER docker # replace USER with your user name # restart the service $ sudo service docker restart
You will have to log out and log back in to make the group settings active on your account. After that you can launch
$ docker images REPOSITORY TAG ID CREATED SIZE ubuntu 12.04 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB) ubuntu 12.10 b750fe79269d 5 months ago 24.65 kB (virtual 180.1 MB) ubuntu latest 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB) ubuntu precise 8dbd9e392a96 4 months ago 131.5 MB (virtual 131.5 MB) ubuntu quantal b750fe79269d 5 months ago 24.65 kB (virtual 180.1 MB)
Connect to a container
# start a container (and save its ID in an env. variable) $ DOCK=$(docker run -d -i -t ubuntu /bin/bash) # it's in the list $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fe650a3d214f ubuntu:12.04 /bin/bash 2 minutes ago Up 2 minutes sharp_archimede # attach to the container $ docker attach $DOCK root@fe650a3d214f:/#
Install some packages in the container
In order to install arbitrary packages, let’s enable the multiverse repos:
root@fe650a3d214f:/# cat > /etc/apt/sources.list deb http://archive.ubuntu.com/ubuntu precise main universe multiverse root@fe650a3d214f:/# apt-get update root@fe650a3d214f:/# apt-get install python-pip root@fe650a3d214f:/# pip install virtualenv root@fe650a3d214f:/# apt-get install libpq-dev python-dev root@fe650a3d214f:/# apt-get install vim ...
However! Any changes you do in your container, they are not permanent! That is, if you log out and you attach to it again, all your changes will be lost and you get back the same vanilla container that you saw upon your first connect. But don’t worry! Changes can be committed, i.e. changes can be made permanent.
This behaviour is actually useful. You can do anything in the container, you can try anything inside, you can’t f* it up. Just log out and log back in, and everything is back. Imagine the possibilities: you can build a secure sandboxed environment easily where you can run any untrusted code.
You made some changes in your vanilla ‘ubuntu’ container and you want to commit them, i.e. you want to see these changes after a relogin. Let’s commit the changes to a new container called ‘pyenv’ for instance.
You are connected to ‘ubuntu’ in a terminal. Don’t logout, otherwise you lose your changes. Open a new terminal and execute these commands:
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES fe650a3d214f ubuntu:12.04 /bin/bash 22 minutes ago Up 22 minutes sharp_archimede $ docker commit fe650a3d214f pyenv f538ae2eb2562bf2ab669d7e04cf9fa49b66814d871bcbc0662deedfdcce73ab
Now you can log out of ‘ubuntu’ and you can log in to ‘pyenv’. From now on you can commit new changes to ‘pyenv’. If you need a new vanilla container, just fork ‘ubuntu’ again.
When you commit changes, docker stores just the diffs, and when you connect to a container, it puts the necessary diffs together.
Sharing a folder between the host and the container
If you want to copy files from the host to the container, the easiest way is to create a shared folder:
$ DOCK=$(docker run -d -i -t -v /tmp/shared.folder:/shared.folder ubuntu /bin/bash) $ docker attach $DOCK
/tmp/shared.folder on the host will be mounted in the container as
/shared.folder . The shared folder must exist on the host.
Yesterday at my workplace I got +4 GB RAM; now I have 8 GB RAM in my machine. The difference? It’s huge! I was suffering with 4 GB, it was damn slow. When I launched VirtualBox it simply bacame unusable. And now? It’s fast :) I can run Firefox, VirtualBox, PyCharm, etc. at the same time without any problem.
Conclusion: 4 GB sucks, 8 GB rulz.
I want to grab a part of the screen by selecting a rectangle. I wanto to be able to refine the selection (resize the rectangle) like in Gimp. Then upload the selected image to imgur.
I found a great tool for this task called Nanoshot.
Read more about Nanoshot in this thread.
Download Nanoshot from here.
Note that I had to install the package
python-wnck (via apt-get) to make it run.
You want to take a screenshot of a selected area of the screen.
gnome-screenshot and choose “Select area to grab”.
I used to take a screenshot of the whole screen (under Ubuntu just press the PrtScn button), then crop it with Gimp. You can also copy the screenshot to the clipboard and paste it to Gimp.
Read more here.