HOWTO: Run UML with VLANs
When testing different VLANs, it is common to have multiple computers on a VLAN with similar
or same configurations. Other times, there is insufficient hardware to build similar machines.
Using GNU/Linux and User-Mode-Linux, you can use a clone of the same filesystem to connect
to different VLANs and test different scenarios based on the same hardware and kernel.
1. Requirements
- You are familiar with compiling kernels and software.
- Linux Kernel 2.4.x, 2.6.x with 802.1q VLAN, 802.1d Bridging, Universal TUN/TAP, Loopback block device
- vconfig (apt-get install vlan)
- Access to root (or equivalent) on the target machine.
- Why you shouldn't use the “Debian Way” (apt-get install whatever)
- This setup requires some kernel customizations as well as some custom settings for some portions of the UML.
- Debian has limited packaged support for different kernel versions and may or may not do things in a way that work with the newer kernels.
- The safest way is to compile your own kernel, UML, and utilities.
2. Get the files
Download the following files from the User-Mode-Linux webpage.(
http://user-mode-linux.sourceforge.net/ )
- UML Patch for kernels
- Choose which kernel you wish to run as the UML. This can be any version provided there is a patch available for it.
- UML Utilities
- Download the most recent version. These tools are required to make use of many UML features.
- Root filesystem
- This is the filesystem the UML will use and mount as / (root). I would recommend the Debian image as it is the easiest to work with and update/upgrade.
- Host SKAS patch (optional, but recommended)
- This patch allows the UML software to use Seperate Kernel Address Space. It is not known to cause any problems in the host, and gives a great performance boost to the UML (and consequently the software running in it).
Download the patch most appropriate to your kernel version. (highest version equal to or below your kernel)
You will also need one or more kernels from
http://www.kernel.org as your computer's kernel (host kernel) and your UML's kernel. They can be the same or different versions as long as UML/host patches are available for them.
3. Setup
3.1 Download and patch the Host kernel
3.2 Compile the host kernel
- On 2.4.x, they can either be compiled as modules or included into the kernel.
- Using make menuconfig
- Networking Options -> 802.1q VLAN support, 802.1d Ethernet Bridging
- Network Device Support -> Universal TUN/TAP device driver support
Block Devices -> Loopback device support
- (this is for SKAS mode): Processor type and features -> /proc/mm support
- Using make config
- CONFIG_TUN, CONFIG_VLAN_8021Q, CONFIG_BRIDGE, CONFIG_BLK_DEV_LOOP, CONFIG_PROC_MM
- On 2.6.x, they can either be compiled as modules or included into the kernel.
- Using make menuconfig
- Device Drivers -> Networking Support -> Universal TUN/TAP device driver support
- Device Drivers -> Networking Support -> Networking Options -> 802.1d Ethernet Bridging, 802.1Q VLAN support
- Device Drivers -> Block Devices -> Loopback device support
- (this is for SKAS mode): Processor type and features -> /proc/mm support
- Using make config
- CONFIG_TUN, CONFIG_VLAN_8021Q, CONFIG_BRIDGE, CONFIG_BLK_DEV_LOOP, CONFIG_PROC_MM
- Compile the kernel as you would normally do (i.e. make, or make dep ; make bzImage) and install it. Reboot.
3.3 Compile and install the UML utilities
3.4 Build the UML "kernel"
3.5 Set up the image
- Ensure the 'linux' binary is in the same directory as where you will decompress the UML image.
$ cd uml
$ bunzip2 -dc Debian-3.0r0.ext2.bz2 > root_fs
$ mkdir mnt
- If you need to install additional packages, or preconfigure the image, follow:
$ su -
# mount root_fs mnt -o loop
# chroot mnt
- Ensure that the DNS server is correct
# vi /etc/resolv.conf
- Install packages, you may want to get vlan, dhclient, ssh, and a console web browser, such as lynx. You will have to create a larger image file or create a second image file if you want to use X.
# apt-get update
# apt-get install <packages>
# exit
# umount mnt
# exit
3.6 Configure the tap device and the bridge
3.6.1 Method 1 (preferred):
- Host untags the VLANs for the UML
- This simulates a more “real” environment in the UML (most OSes don't have VLAN support built in!)
- This will create a device called eth0.192
# vconfig add <physical-interface> <vlan-number&g
- e.
# vconfig add eth0 192
- Add the interface to the bridge and bring it all up
# brctl addif br0 eth0.192
# ifconfig eth0.192 up; ifconfig tap0 up; ifconfig br0 up
- To add another host to the same VLAN, create a new tap device and add it to the bridge
# tunctl -u <UML-user>
# ifconfig tap1 up
# brctl addif br0 tap1
- To add another host to a different VLAN, create a new tap device and repeat the method 1 steps.
3.6.2 Method 2: Host bridges all VLANs to the UML
- Remove ip address from eth0
# ifconfig eth0 0.0.0.0
- add eth0 to bridge and configure
# brctl addif br0 eth0
# ifconfig eth0 up; ifconfig tap0 up; ifconfig br0 129.97.15.xx netmask 255.255.255.0 ; route add default gw 129.97.15.x
- To add another host to this set up, create a new tap device and add it to the bridge.
# tunctl -u <UML-user>
# ifconfig tap1 up
# brctl addif br0 tap1
3.6.3 Check
- If you're using kernel 2.4.x with ebtables/bridge-netfilter or 2.6.x, check for the prescence of /proc/sys/net/bridge ... by default this feature is disabled in the stock kernel.
- bridge-nf-call-arptables - pass (1) or don't pass (0) bridged ARP traffic to arptables' FORWARD chain.
- bridge-nf-call-iptables - pass (1) or don't pass (0) bridged IPv4 traffic to iptables' chains.
- bridge-nf-filter-vlan-tagged - pass (1) or don't pass (0) bridged vlan-tagged ARP/IP traffic to arptables/iptables.
- (from the bridge-nf FAQ at http://ebtables.sourceforge.net/)
- By default, all bridged ARP, IP and VLAN traffic are filtered through ebtables if these entries are present, and are not filtered if these entries are not present.
- For Method 1 to work, bridge-nf-call-arptables and bridge-nf-call-iptables must be 0, OR you must have ebtables entry permitting traffic to the UML ARP/IP address(es).
- For Method 2 to work, bridge-nf-filter-vlan-tagged must be 0 OR you must have an ebtables entry permitting the tagged vlan to pass through.
- For testing purposes, it is safe to set all three to 0.
4. Start the UML!
--
SevernTsui - 20 Jul 2004