UserModeLinux

Content Cleanup Required: This article should be cleaned-up to follow the content standards in the Wiki Guide. More info...

Needs Expansion: This article is incomplete, and needs to be expanded. More info...

User-Mode Linux is another virtualisation technique for running VirtualMachines under GNU/Linux. A simplified version of the Linux kernel is run as a normal user-space process.

See the User-Mode Linux project page for more information.

This page will help you get started using User-Mode Linux with Ubuntu. Guide is created for Hardy LTS, but will most likely work with other releases.

Installing required packages

The first thing we need is to install the uml kernel and utilities we will need.

sudo apt-get install user-mode-linux uml-utilities bridge-utils debootstrap

Creating a virtual machine image

The next step is getting us a nice ubuntu hardy filesystem:

# Create an empty file to contain the root filesystem
dd if=/dev/zero of=uml-root-hardy bs=4096 seek=1M count=1

# Create the filesystem on the file
mkfs.xfs uml-root-hardy

# Mount the filesystem
sudo mount -o loop uml-root-hardy /mnt

# Switch to root account for the rest
sudo -i

# Install a base system on the mounted partition. Use i386 or amd64 for the --arch option
debootstrap --arch amd64 hardy /mnt http://us.archive.ubuntu.com/ubuntu

# Create an fstab file
echo "/dev/ubd0  /       xfs     defaults     0 1" > /mnt/etc/fstab
echo "proc       /proc   proc    defaults     0 0" >> /mnt/etc/fstab

# Create the device file for the root file system and configure permissions
mknod --mode=660 /mnt/dev/ubd0 b 98 0
chown root:disk /mnt/dev/ubd0

# Create a hosts file
echo "127.0.0.1 localhost" > /mnt/etc/hosts

# Configure network interfaces: eth0 using dhcp
echo "auto lo" > /mnt/etc/network/interfaces
echo "iface lo inet loopback" >> /mnt/etc/network/interfaces
echo "auto eth0" >> /mnt/etc/network/interfaces
echo "iface eth0 inet dhcp" >> /mnt/etc/network/interfaces 

# Add first terminal and serial terminal to secure list
echo "tty0" >> /mnt/etc/securetty
echo "ttys/0" >> /mnt/etc/securetty

# Remove the other terminal events
rm /mnt/etc/event.d/tty2
rm /mnt/etc/event.d/tty3
rm /mnt/etc/event.d/tty4
rm /mnt/etc/event.d/tty5
rm /mnt/etc/event.d/tty6
rm /mnt/etc/udev/rules.d/75-persistent-net-generator.rules

# Return to normal account
exit

TODO: network bridge

Basically what we've done is created an empty filesystem, mounted it, and made some changes that we want done on all our VMs. Most of the commands need to be run as root using sudo in order to set the permissions correctly.

Running the VM

We should be ready to run our new VM now:

linux ubd0=uml-root-hardy.cow1,uml-root-hardy umid=uml1

This command runs the virtual machine using a copy-on-write (COW) file in uml-root-hardy.cow1. This file receives all changes that are made in the filesystem. uml-root-hardy remains unchanged, so we can run several virtual machines from this image.

  • Note: if your virtual machine crashes when mounting the root filesystem, the copy-on-write mechanism doesn't work. Use the following command instead:

     linux ubd0=uml-root-hardy umid=uml1
    This means that the original image will be modified.

    This issue has been reported in Launchpad as bug 338795. In the meantime you can use the package from Debian.

Networking

Just started

To have your UML talking to the rest of the world, you have some options and one would be to use a TAP-interface in the host-OS. This interface is created with the use of tunctl as in:

tunctl -u uml-net
where uml-net is the user who should own the interface /dev/net/tun. It's very important this user matches the one specified in /etc/default/uml-utilities or the network won't work.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值