Difference between revisions of "User-mode Linux"

From ArchWiki
Jump to: navigation, search
m
m (Marionnet: Remove personal reference (who is "me" anyway?))
 
(19 intermediate revisions by 11 users not shown)
Line 1: Line 1:
[[zh-CN:User-mode Linux]]
 
 
[[Category:Virtualization]]
 
[[Category:Virtualization]]
User-mode-linux (UML) is a method to run linux inside linux as a normal process. Please check [http://user-mode-linux.sourceforge.net/] for in detail information what uml is and how it works.
+
[[zh-CN:User-mode Linux]]
 +
{{Out of date|Dead project (last activity in 2007), [[Talk:User-mode Linux|inaccurate information]]|section=Needs work}}
 +
 
 +
User-mode-Linux (UML) is a method to run Linux inside Linux as a normal process. Please check [http://user-mode-linux.sourceforge.net/] for in-depth information what UML is and how it works.
  
 
== Why use UML? ==
 
== Why use UML? ==
Running UML is a safe way to run multiple instances of (arch-)linux at the same time. The single processes are seperated from each other, which makes it secure to run for example a testing instance and a productive one on the same machine. If something goes wrong inside the testing instance, it does not interfere with the host linux or the productive instance.
+
Running UML is a safe way to run multiple instances of (Arch-)Linux at the same time. The single processes are separated from each other, which makes it secure to run, for example, a testing instance and a production instance on the same machine. If something goes wrong inside the testing instance, it does not interfere with the host Linux or the productive instance.
  
 
== HOWTO ==
 
== HOWTO ==
There are two methods:
+
There are three methods:
  
 
* Use hostfs with vde2 network (all UMLs use same file system)
 
* Use hostfs with vde2 network (all UMLs use same file system)
 
* Use rootfs with tap network (require build image)
 
* Use rootfs with tap network (require build image)
 +
* Use [https://www.marionnet.org/ Marionnet]
 +
Both methods are workable on Linux 3.4.4-3 (Jul 3 2012)
  
Both methods are workable on linux 3.4.4-3(Jul 3 2012)
+
=== Setup by hostfs + vde2 ===
 +
Hostfs means use the host's file system in read-only mode.
  
=== setup by hostfs + vde2 ===
+
==== Required packages ====
Hostfs means use host's file system in read-only mode.
+
* {{AUR|linux-usermode}}
 +
* Utility packages: {{pkg|vde2}} {{pkg|screen}} {{AUR|start-stop-daemon}} {{pkg|rsyslog}}
  
==== required packages ====
+
==== Launch script ====
* AUR package: [https://aur.archlinux.org/packages.php?ID=51051 linux-usermode]
+
* Utility packages: vde2 screen start-stop-daemon rsyslog
+
 
+
==== launch script ====
+
 
* download http://pastebin.com/qDE0D7Lk script as 2vm.bash
 
* download http://pastebin.com/qDE0D7Lk script as 2vm.bash
* use normal user to launch 2vm.bash (there are two VM named as 'C1' & 'C2')
+
* use normal user to launch 2vm.bash (there are two VMs named as 'C1' & 'C2')
* modify the 2vm.bash to fit your requirement
+
* modify the 2vm.bash to fit your requirements
  
 
=== Setup by rootfs + tap ===
 
=== Setup by rootfs + tap ===
==== required packages ====
+
==== Required packages ====
* AUR package: linux-usermode
+
* {{AUR|linux-usermode}}
* Utility packages: vde2 uml_utilities
+
* Utility packages: {{pkg|vde2}} {{AUR|uml_utilities_tunpatch}}{{Broken package link|{{aur-mirror|uml_utilities_tunpatch}}}}
 
+
==== build rootfs image ====
+
1.) First you have to create a single, big file into which you will install Arch Linux. This command creates a single 1 GB file, only containing zeros - should be enough for a basic Arch Linux installation.
+
  
 +
==== Build rootfs image ====
 +
1.) First you have to create a single, big file into which you will install Arch Linux. This command creates a single 1 GB file, only containing zeros, which should be enough for a basic Arch Linux installation.
 
  dd if=/dev/zero of=rootfs bs=1MB count=1000
 
  dd if=/dev/zero of=rootfs bs=1MB count=1000
 +
or
 +
fallocate -l 1GB ./rootfs
  
2.) After the build process you have to format the root filesystem image:
+
2.) After the build process you have to format the root file system image:
 
  mke2fs -F rootfs
 
  mke2fs -F rootfs
  
3.) After formatting the file you have to mount it. Executing the following command as root does the job (you have also to load the loop module with modprobe):
+
3.) After formatting the file, you have to mount it. Executing the following command as root does the job (you have also to load the {{ic|loop}} module with {{ic|modprobe}}):
 
  mount -o loop rootfs /mnt
 
  mount -o loop rootfs /mnt
  
Line 49: Line 52:
 
  chown root:disk ubd0
 
  chown root:disk ubd0
  
5.) Before the system can be booted with user-mode-linux, some files inside the arch basic system have to be customised. Add this line to {{ic|/mnt/etc/fstab}}:
+
5.) Before the system can be booted with user-mode-Linux, some files inside the Arch basic system have to be customised. Add this line to {{ic|/mnt/etc/fstab}}:
 
  /dev/ubd0 / ext2 defaults 0 0
 
  /dev/ubd0 / ext2 defaults 0 0
  
To avoid long boot time you are advised to disable '''hotplugin''' in {{ic|/mnt/etc/rc.conf}}:
+
6.) Now unmount the file system.
DAEMONS=(.. !hotplugin ..)
+
{{Warning|If you change ''anything'' inside your mounted file system (e.g. {{ic|/mnt}}) while it is ''running'', it may lead to significant file system corruption inside your virtual machine and ''kill'' it!}}
 
+
6.) Now unmount the filesystem. <b>NOTE:</b> If you change ''anything'' inside your mounted filesystem (e.g. {{ic|/mnt}}) while it is ''running'' it may lead to significant filesystem corruption inside your virtual machine and ''kill'' it!
+
 
  umount /mnt
 
  umount /mnt
  
7.) Next step is to set up networking. Therefore you create a so called tun device (Please visit the [http://user-mode-linux.sourceforge.net/old/UserModeLinux-HOWTO.html uml howto] for further information about tun/tap), and give it an IP address. The following lines load the necessary tun module, create a tun/tap device that is readable by the users group and set it up with the given ip address. For security you should consider to create a certain uml group with read permissions for the network device.
+
7.) Next step is to set up networking. Therefore, you create a so called tun device (Please visit the [http://user-mode-linux.sourceforge.net/old/UserModeLinux-HOWTO.html UML how-to] for further information about tun/tap), and give it an IP address. The following lines load the necessary {{ic|tun}} module, create a tun/tap device that is readable by the {{ic|users}} group, and sets it up with the given IP address. For security, you should consider creating a certain UML group with read permissions for the network device.
 
  modprobe tun
 
  modprobe tun
  tunctl -g users
+
  ip tuntap add tap0 mode tap group users
 
  chown root.users /dev/net/tun
 
  chown root.users /dev/net/tun
 
  ip addr add 192.168.0.100/24 dev tap0
 
  ip addr add 192.168.0.100/24 dev tap0
  
8.) Now you can boot the image. To use the network you have to announce the proper device to the uml kernel. (Mind that the user running the uml command needs enough rights to access the tun device!)
+
8.) Now you can boot the image. To use the network, you have to announce the proper device to the UML kernel. (Mind that the user running the UML command needs enough rights to access the tun device!)
 
  vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100
 
  vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100
  
The ",,," mean:
+
The {{ic|,,,}} means:
 
  eth0=transport,tuntap device,MAC address,ip
 
  eth0=transport,tuntap device,MAC address,ip
  
Line 75: Line 76:
 
Headless example:
 
Headless example:
 
   vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100 mem=128M con=pty
 
   vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100 mem=128M con=pty
 +
 +
 +
=== Marionnet ===
 +
For use [https://www.marionnet.org/ Marionnet], you must install {{AUR|uml_utilities}}, and see https://bugs.launchpad.net/marionnet/+bug/1580349.

Latest revision as of 19:33, 22 May 2016

Tango-view-refresh-red.pngThis article or section is out of date.Tango-view-refresh-red.png

Reason: Dead project (last activity in 2007), inaccurate information (Discuss in Talk:User-mode Linux#Needs work)

User-mode-Linux (UML) is a method to run Linux inside Linux as a normal process. Please check [1] for in-depth information what UML is and how it works.

Why use UML?

Running UML is a safe way to run multiple instances of (Arch-)Linux at the same time. The single processes are separated from each other, which makes it secure to run, for example, a testing instance and a production instance on the same machine. If something goes wrong inside the testing instance, it does not interfere with the host Linux or the productive instance.

HOWTO

There are three methods:

  • Use hostfs with vde2 network (all UMLs use same file system)
  • Use rootfs with tap network (require build image)
  • Use Marionnet

Both methods are workable on Linux 3.4.4-3 (Jul 3 2012)

Setup by hostfs + vde2

Hostfs means use the host's file system in read-only mode.

Required packages

Launch script

  • download http://pastebin.com/qDE0D7Lk script as 2vm.bash
  • use normal user to launch 2vm.bash (there are two VMs named as 'C1' & 'C2')
  • modify the 2vm.bash to fit your requirements

Setup by rootfs + tap

Required packages

Build rootfs image

1.) First you have to create a single, big file into which you will install Arch Linux. This command creates a single 1 GB file, only containing zeros, which should be enough for a basic Arch Linux installation.

dd if=/dev/zero of=rootfs bs=1MB count=1000

or

fallocate -l 1GB ./rootfs

2.) After the build process you have to format the root file system image:

mke2fs -F rootfs

3.) After formatting the file, you have to mount it. Executing the following command as root does the job (you have also to load the loop module with modprobe):

mount -o loop rootfs /mnt

4.) Now the installation of the basic system may start:

mkdir -p /mnt/var/lib/pacman
pacman -Sy base -r /mnt
cd /mnt/dev
mknod --mode=660 ubd0 b 98 0
chown root:disk ubd0

5.) Before the system can be booted with user-mode-Linux, some files inside the Arch basic system have to be customised. Add this line to /mnt/etc/fstab:

/dev/ubd0 / ext2 defaults 0 0

6.) Now unmount the file system.

Warning: If you change anything inside your mounted file system (e.g. /mnt) while it is running, it may lead to significant file system corruption inside your virtual machine and kill it!
umount /mnt

7.) Next step is to set up networking. Therefore, you create a so called tun device (Please visit the UML how-to for further information about tun/tap), and give it an IP address. The following lines load the necessary tun module, create a tun/tap device that is readable by the users group, and sets it up with the given IP address. For security, you should consider creating a certain UML group with read permissions for the network device.

modprobe tun
ip tuntap add tap0 mode tap group users
chown root.users /dev/net/tun
ip addr add 192.168.0.100/24 dev tap0

8.) Now you can boot the image. To use the network, you have to announce the proper device to the UML kernel. (Mind that the user running the UML command needs enough rights to access the tun device!)

vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100

The ,,, means:

eth0=transport,tuntap device,MAC address,ip

Example:

eth0=tuntap,tap0,3f:2a:bb:00:00:00,192.168.0.100

Headless example:

 vmlinux ubd0=rootfs eth0=tuntap,,,192.168.0.100 mem=128M con=pty


Marionnet

For use Marionnet, you must install uml_utilitiesAUR, and see https://bugs.launchpad.net/marionnet/+bug/1580349.