15

Is it possible to install any virtual machine software as non-root user and run it ?

Which VM's are possible to be installed with out need of root access ?

If it is not possible what would be the most light weight virtual machine to use for a few VM's running windows xp sp3 ?

5

Any real virtualization needs low-level access to the CPU, and thus root must install it. Once installed you don't need to be root to run it. You could probably install and run an emulator as non-root, such as bochs, or an adapter such as wine. If you have a specific Windows app in mind you could just run it under wine (maybe).

  • possible could but I would have to request an application to be converted to mono in order for it to work as well which would be a lot of trouble actually not even know if they would actually do it, thanks for the answer. Would you happen to know what are the most light VM's to simple run window xp sp3 with 2 really small memory usage apps ? – Prix Jun 1 '11 at 19:48
  • Probably your best bet would be VMware player. It's free from VMware. – Keith Jun 1 '11 at 20:24
11

For KVM, you need access to the device /dev/kvm. If your user can read/write to this device, then you can run KVM-based virtual machines as your user.

In most distributions members of the kvm group has access to this device, so all you need to do is to add your user to the kvm group.

For most other accelerated technologies, you will need kernel modules loaded (this includes virtualbox and VMWare). This almost certainly requires root-level access.

You can run non-accelerated virtualisation technologies as any user. For example, qemu in non-accelerated mode. Be aware it will be very slow compared to accelerated virtualisation.

  • thaks the non-accelerated information was usefull ;) – Prix Jun 1 '11 at 19:49
7

User mode Linux is a Linux virtualization solution that runs entirely in userspace - no root privileges required.

However, it can only run a Linux guest within a Linux host, so it's not suitable if you want to run anything else.

4

A virtual machine needs quite low-level access to the processor (and other hardware) to be efficient. Therefore you won't see any well-performing VM software that can be installed non-root.

As for lightweight virtual machines, the lightness is achieved by only including needed features. This requires some knowledge about the OS that will be run, and so open-source lightweight VMs (Plex86, LilyVM) only support open-source operating systems. By this logic, it might be that Microsoft Virtual PC is more lightweight than VirtualBox/VMWare/etc. but I really don't know. VirtualBox is available in open-source, is quite usable and has always been sufficient for my purposes (but I've tried others).

2

Virtualbox 4.0.8 needs to be installed as root offcourse, but afterwards you can let users make there own VM's. You just have to be a member of the group vboxusers

usermod -G vboxusers USERNAME

Have a look at this link, nice article how to run it headless, straight from the shell. I also really dig that it supports the RDP protocol, meaning you can just use rdesktop to connect.

2

QEmu is able to do that. I've done it several times. Not extremely performant though

2

1) Three lines answer

To use my prebuilt images/compiled version of qemu, download it from here, and then uncompress it:

tar -xvzf qemu_packed.tar.gz

you can also download my debian 8 image (1.6G) from here:

tar -xvzf test01.qcow2.tar.gz

and finally run

./command.sh

You should have a working Debian 8, in text mode, with the ssh port opened in the host guest at port 22222. You can log using the user "root" and the password "root".

2) Longer answer, make these images by yourself

QEMU is indeed a solution that let me install my own linux image on a server on which I had no root access. It's very usefull, I use it for example to do reverse ssh without revealing my main user password, or for educational purpose. But indeed, because you cannot use KVM for real virtualisation without a root account, you will be able to do only emulation, which can be quite inefficient (but for command line operations, I never really saw the overhead).

2.1) Pack qemu

Here is the description of how I proceed. The first step is to make qemu "portable", i.e. usable on the server with no root access. To do so you have several methods, I will try to present them so that you can choose the one you prefer.

2.1.a) Method 1 : download the available .deb

This solution can be really quick to apply (basically if it works, in 1 command you get it), but because my script may be buggy/may forget some lib, it can be quite long to manually download all the binaries... The other advantage of this method is that you can run it in non root mode, directly on the server. The idea to get qemu binaries here is to get the .deb/.rpm file (from apt, or from the online websites that hosts .deb), extract it, check the libraries dependencies using ldd, and download all the .deb of the dependencies that are not already present on the computer in order to extract them (the .so files). Because it can be quite long and repetitive, I created a small script, but if you are brave, you can do all of that manually... It just take time. To use it, save this script in a file create_qemu_binaries.sh:

#!/usr/bin/env bash
mkdir qemu_extract
cd qemu_extract
echo "########## Downloading qemu... ##########"
apt-get download qemu-system-x86
echo "########## Extracting qemu... ##########"
dpkg -x qemu-system-*.deb .
mkdir -p qemu_packed/lib
cp usr/bin/qemu-system-x86_64 qemu_packed
echo "########## Copy libs... ##########"
ldd usr/bin/qemu-system-x86_64 | grep "=>" | grep -v "not found" | awk '{print "cp "$3" qemu_packed/lib/"}' | bash
mkdir not_found
cd not_found
echo "########## Get not found libs... ##########"
ldd ../usr/bin/qemu-system-x86_64 | grep "not found" | awk '{print $1}' > not_found.txt
echo "########## Download not found libs... ##########"
for lib in $(cat not_found.txt); do echo "=== Dealing with $lib ==="; apt-file search --regexp "/${lib}\$" | sed 's/:.*//' | xargs apt-get download; done
echo "########## Extracting not found libs... ##########"
ls *.deb | xargs -I{} dpkg -x "{}" .
echo "########## Copying not found libs... ##########"
find . | grep ".so" | xargs -I{} cp "{}" ../qemu_packed/lib
cd ..
echo "########## Getting pc-bios... ##########"
git clone https://github.com/qemu/qemu.git
cp -r qemu/pc-bios qemu_packed
echo "########## Finished !!! ##########"
echo "The output file should be in the folder qemu_extract/qemu_packed."
echo "Once you have a filesystem image, you can run it using:"
echo "$ LD_LIBRARY_PATH=$(pwd)/lib ./qemu-system-x86_64 -L pc-bios -no-kvm -m 256 -drive if=virtio,file=<your image>.qcow2,cache=none -display curses -k fr -redir tcp:22222::22"
echo "Don't forget to replace <your image>"

and run it using:

chmod +x create_qemu_binaries.sh 
./create_qemu_binaries.sh 

it everything works fine, at the end you should have in the folder ./qemu_extract/qemu_packed/ one file qemu-system-x86_64 (the main binary), one folder lib (the libs that need to be taken with qemu), and one folder pc-bios, a set of files that qemu needs to run. You can then run qemu by using (don't forget to replace with your filesystem image):

$ LD_LIBRARY_PATH=$(pwd)/lib ./qemu-system-x86_64 -L pc-bios -no-kvm -m 256 -drive if=virtio,file=<your image>.qcow2,cache=none -redir tcp:22222::22

Enjoy ! (if the script does not work for you, don't hesitate to ask me, I tested it only on two computers, and fill free to remove redir if you don't need ssh forwarding between the host and the guess)

2.1.b) Method 2 : if you access to a computer with root access

The first method needs a computer with root access (or qemu installed). First install qemu using something like

sudo apt install qemu-system-x86

and then locate the absolute path of qemu :

$ which qemu-system-x86_64 
/usr/bin/qemu-system-x86_64

Then, create a folder to put it:

mkdir -p qemu_packed/lib
cd qemu_packed
cp /usr/bin/qemu-system-x86_64 qemu_packed

and get the list of libraries linked with qemu:

ldd qemu_packed/qemu-system-x86_64 | awk '{print "cp "$3" qemu_packed/lib"}' | bash

now, we need to get the BIOS use by qemu. The file are available on your system, but I don't know why they are in different folders, so I think it's easier to get them from the sources:

git clone https://github.com/qemu/qemu.git
cp -r qemu/pc-bios qemu_packed
cd qemu_packed

Now, it should work, you can copy these files on the non root machine, and just run qemu using the following line (don't forget to replace the image):

$ LD_LIBRARY_PATH=$(pwd)/lib ./qemu-system-x86_64 -L pc-bios -no-kvm -m 256 -drive if=virtio,file=<your image>.qcow2,cache=none

2.1.c) Method 3 : from the sources

You can also compile the sources, but if you don't have all the libraries installed, it may be tricky to avoid to use a rooted computer to compile qemu. But I guess it's a bit more reliable if the above two methods does not work. Then, once it's compiled, get the executable file, and do the same trick as above to get the libraries (using ldd, all the libraries should be already on the computer) and the pc-bios file. And again, run it with the same command.

2.3) Create your own image

If you don't want to use a pre-made filesystem image, just follow the numerous tutorials using the commands above in place of qemu/qemu-system-x86_64 ! NB : if you also want to use qemu-img to create images as non root, then follow the same process as above !

Enjoy !

NB : if you want to use the curses display in order to run it on a server with no GUI, you should add in your image a line in the boot option so that it does not turn on frame buffer in /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="vga=normal nofb nomodeset bochs_drm.fbdev=off"

(the most important is the last , I'm not sure if it's needed). As well as

GRUB_TERMINAL=console
GRUB_GFXPAYLOAD_LINUX=text

so that grub stay in text mode. You may also want to enable text mode in systemd if it's not enough.

  • 1
    Please guy that put me -1, could you please explain me why ? – tobiasBora Oct 23 '17 at 10:21
  • I have no idea but this is great, thank you. – wbkang Apr 10 '18 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.