Thursday, 28 August 2014

Recovering a deleted file that is still held open

I accidentally deleted the disk image file for a running virtual machine. oopsy!

Luckily, there is an easy way to undo that using the lsof command!

lsof | grep /home/qemu/images/my-disk-image.qcow2

This produces output like this;

qemu-kvm  24816      root    9u      REG              253,2 214781394944   21102665 /home/qemu/images/my-disk-image.qcow2 (deleted)

Take note of the first two numbers, which in my case are 24816 and 9 (Note: you must strip the trailing char from the second number)

Pause the VM  (don't stop it!) so that the disk is not being written to while we do the next step.

Now you just need to copy the deleted file back to somewhere safe;

[root@devkvm03 images]# cp /proc/24816/fd/9 my-disk-image.qcow2





Tuesday, 22 July 2014

Using docker on Linux Mint Debian Edition


Installing Docker on LMDE takes a few steps and will require that we add a third-party repository.

Note: We will be logged in as root to issue these commands. Also, I am by no means an expert on this, I am learning this as I go on.

So, with that out of the way let's add the key for the get.docker.io repository;

# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

Next add the repository to your apt sources;

# echo "deb http://get.docker.io/ubuntu docker main" > /etc/apt/sources.list.d/docker.list

Update apt;

# apt-get update

Install docker;

# apt-get install lxc-docker

Verify that it has worked by downloading and running the ubuntu container;

# docker run -i -t ubuntu /bin/bash
Unable to find image 'ubuntu' locally
Pulling repository ubuntu
e54ca5efa2e9: Download complete
511136ea3c5a: Download complete
d7ac5e4f1812: Download complete
2f4b4d6a4a06: Download complete
83ff768040a0: Download complete
6c37f792ddac: Download complete
root@46ec4b13f756:/#

Congratulations you are sitting in bash inside your ubuntu container. Type 'exit' or use ctrl-d to exit.

Note: It is important to understand that once you exit a container it ceases to run unless you specifically tell it not to (see below). It is not like a normal virtual machine that keeps on running in the background until you shut it down. To exit a container and have it remain running, use ctrl-p followed by crtl-q.

You probably dont want to be the root user every time you use docker. In that case simply add your user to the docker group;

# usermod -a -G docker myusername

You can list all the running containers with the 'docker ps' command. Add '-a to see the stopped ones as well.

Note: The containers that you create are kept in '/var/lib/docker/containers'

That's the basics of docker. The next thing to learn more about is using docker files to build containers.

Wednesday, 2 July 2014

Libvirt/qemu/kvm as non-root user

Prerequisites:

A server with KVM

I'm going to use the qemu user that is created when you install KVM but you could use any user you like.

First, your user should belong to the kvm group:

grep kvm /etc/group kvm:x:36:qemu

Create a libvirtd group and add your user to it

groupadd libvirt
usermod -a -G libvirt qemu


Create a new policykit config to allow access to libvirtd using your user account via ssh

vi /etc/polkit-1/localauthority/50-local.d/50-libvirt-remote-access.pkla

Add the following content:

[Remote libvirt SSH access]
Identity=unix-group:libvirt
Identity=unix-user:qemu
Action=org.libvirt.unix.manage
ResultAny=yes
ResultInactive=yes
ResultActive=yes


Restart libvirt

service libvirtd restart

Tuesday, 1 July 2014

Configuring a Printer With CUPS Web Admin

I couldn't get the printer admin applet in Mint to add a new printer. It just kept saying "Failed to add printer" every time.

Then I discovered that CUPS has a web admin page:

http://localhost:631

When it ask for a username & password just enter any user with sudo privileges and you are in.

Sunday, 29 June 2014

FIX: Black screen at login for LMDE/Cinnamon

So, I installed a fresh copy of LMDE on a machine. Obviously, that will include doing an apt-get dist-upgrade to ensure every thing is all up to date.

After doing that, I restarted the box and got the Mint login screen, entered my password and got . . . . . a black screen with a mouse pointer and nothing else.

I couldn't find an answer on the Internet so eventually I took a punt and entered:

apt-get install cinnamon

and what would you know, Cinnamon wasn't installed at all. For some, the distribution upgrade had decided to remove Cinnamon altogether. After the install finished I rebooted and all was good again.

Wednesday, 25 June 2014

"Permission denied" using libvirt and kvm on CentOS

If you are trying to create a VM using virt-manager on a KVM/QEMU host and you are getting "permission denied" then you need to either disable selinux or configure it to allow access.

To disable it edit /etc/selinux/config and change it from "enforcing" to "disabled" and then use  this command to make it take effect without rebooting.

setenforce 0