Site Home Page
The UML Wiki
UML Community Site
The UML roadmap
What it's good for
Case Studies
Kernel Capabilities
Downloading it
Running it
Compiling
Installation
Skas Mode
Incremental Patches
Test Suite
Host memory use
Building filesystems
Troubles
User Contributions
Related Links
The ToDo list
Projects
Diary
Thanks
Contacts
Tutorials
The HOWTO (html)
The HOWTO (text)
Host file access
Device inputs
Sharing filesystems
Creating filesystems
Resizing filesystems
Virtual Networking
Management Console
Kernel Debugging
UML Honeypots
gprof and gcov
Running X
Diagnosing problems
Configuration
Installing Slackware
Porting UML
IO memory emulation
UML on 2G/2G hosts
Adding a UML system call
Running nested UMLs
How you can help
Overview
Documentation
Utilities
Kernel bugs
Kernel projects
Screenshots
A virtual network
An X session
Transcripts
A login session
A debugging session
Slackware installation
Reference
Kernel switches
Slackware README
Papers
ALS 2000 paper (html)
ALS 2000 paper (TeX)
ALS 2000 slides
LCA 2001 slides
OLS 2001 paper (html)
OLS 2001 paper (TeX)
ALS 2001 paper (html)
ALS 2001 paper (TeX)
UML security (html)
LCA 2002 (html)
WVU 2002 (html)
Security Roundtable (html)
OLS 2002 slides
LWE 2005 slides
Fun and Games
Kernel Hangman
Disaster of the Month

Configuration from the outside

Changing the configuration of a virtual machine between boots can be inconvenient because of the need to change config files in the root filesystem that boots the machine. For example, if you want to change the filesystems that are mounted, you need to change the kernel command line to pass in the new filesystems, but you also need to change /etc/fstab to mount them.

You can mount loopback-mount the root filesystem and go in and edit the relevant files, but this is more manual than necessary, and it's impossible without root privileges on the host.

The solution that I'm using is to:

  • Generate the config files and whatever else needs to be changed or added to the filesystem that will boot the machine
  • Lay them out in a skeletal filesystem structure reflecting where they will go in the virtual machine
  • Tar up that directory
  • Add that tar file as one of the block devices on the kernel command line
  • Also add
                      CONFIG_DEV=device-name
                      
                    
    to the command line
  • The first thing the machine does after it mounts the root filesystem read-write is check the CONFIG_DEV environment variable. If it has a value, then it tars the new files from the device after saving the originals. This is early enough to ensure that almost any new configuration options will take effect.

    To enable this, you need to put this script in /etc/rc.d/rc.configfiles

                  
    #!/bin/sh
    
    for ARG in $@
    do
        case $ARG in
        start)
            if [ "$CONFIG_DEV" != "" ]; then
                restore=""
                remove=""
                for file in `tar tf $CONFIG_DEV`; do
                    if [ -e $file ]
                    then restore="$restore $file"
                    else remove="$remove $file"
                    fi
                done
                [ "$restore" != "" ] && tar cf /tmp/restore.tar $restore
                echo $remove > /tmp/remove
                tar xf $CONFIG_DEV
            fi
        ;;
        stop)
            if [ "$CONFIG_DEV" != "" ]; then
                [ -e /tmp/restore.tar ] && tar xf /tmp/restore.tar
                [ -f /tmp/remove ] && rm -rf `cat /tmp/remove`
                rm -rf /tmp/restore.tar /tmp/remove
            fi
        ;;
        *)
            echo "usage: $0 (start|stop)"
            exit 1
            ;;
        esac
    done
    
    exit 0
    
                
    and add a call to /etc/rc.S:
                  /etc/rc.d/rc.configfiles start
                
    and a similar call to /etc/rc.0:
                  /etc/rc.d/rc.configfiles stop
                
    The addition to /etc/rc.S needs to be immediately after the read-write remount of /:
                  mount -o remount /
                
    and the /etc/rc.0 needs to be just before the read-only remount of /:
                  mount -n -o remount,ro /
                

    With this in place, it is possible to arbitrarily reconfigure a virtual machine without booting it up or loopback mounting its root filesystem beforehand.

    Hosted at SourceForge Logo