Vnx-rootfsdebian

From VNX
Revision as of 22:56, 10 June 2012 by David (talk | contribs) (Basic installation and configuration)
Jump to: navigation, search

How to create a User-Mode-Linux Debian root-file-system for VNX

Follow this procedure to create a UML Debian Squeeze (6.0) root filesystem for VNX.

Basic installation and configuration

  • Requirements:
  • apt-get install debootstrap
    
  • Create and format the file that will host the filesystem:
  • dd bs=1M if=/dev/zero of=vnx_rootfs_uml_debian.img count=2048
    mkfs.ext4 vnx_rootfs_uml_debian.img 
    
  • Mount it and and use debootstrap to populate it:
  • mkdir mnt
    mount -o loop vnx_rootfs_uml_debian.img mnt/
    debootstrap --arch i386 squeeze mnt/ ftp://ftp.debian.org/debian/
    

    Note: change ftp.debian.org to the mirror nearest you (e.g. ftp.es.debian.org).

  • Chroot to the new filesystem to continue the installation:
  • mount -t proc none mnt/proc
    chroot mnt
    env -update
    ln -sf /usr/share/zoneinfo/Europe/Madrid /etc/localtime 
    
  • Install the packages desired. For example, for a root filesystem mainly used in networking laboratories:
  • apt-get install locales aptsh file less perl-modules vim openssh-server    \
       openssh-client telnet sudo lsof ssh ncurses-term bzip2 strace   \
       tcpdump tshark apache2 apache2-utils dnsutils finger ftp ftpd   \
       ipsec-tools iputils-tracepath ipv6calc ipvsadm lpr lynx         \
       nfs-common openssl pidentd portmap ppp procmail python          \
       python-central python-newt quagga racoon radvd  sharutils squid \
       squid-common ssl-cert vlan whois iptables bind9
    sudo dpkg-reconfigure locales
    
  • Stop and disable startup of services installed:
  • /etc/init.d/apache2 stop
    /etc/init.d/squid stop
    /etc/init.d/bind9 stop
    /etc/init.d/exim4 stop
    /etc/init.d/lpd stop
    update-rc.d -f apache2 remove
    update-rc.d -f squid remove
    update-rc.d -f bind9 remove
    update-rc.d -f exim4 remove
    update-rc.d -f lpd remove
    
  • Clean apt cache:
  • apt-get clean
    
  • Set hostname:
  • echo vnx > /etc/hostname
    
  • Set consoles and loopback network interface configuration:
  • echo '0:2345:respawn:/sbin/getty 38400 tty0' >> /etc/inittab
    echo 'tty0' >> /etc/securetty 
    echo 'ssh' >> /etc/securetty
    echo 'auto lo' >> /etc/network/interfaces
    echo 'iface lo inet loopback' >> /etc/network/interfaces
    
  • Configure /etc/fstab:
  • echo 'proc         /proc          proc     defaults   0 0' >> /etc/fstab
    echo 'devpts       /dev/pts       devpts   mode=0622  0 0' >> /etc/fstab
    echo '/dev/ubda    /              ext4     defaults   0 1' >> /etc/fstab
    echo '/dev/ubdb    /mnt/vnuml     iso9660  defaults   0 0' >> /etc/fstab
    
  • Set roort password:
  • passwd
    
  • Create VNX specific directories:
  • mkdir /mnt/vnuml
    mkdir /mnt/hostfs
    
  • Create file /etc/init.d/vnxboot:
  • #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          vnxboot
    # Required-Start:    $remote_fs $syslog $all
    # Required-Stop:
    # Default-Start:     2
    # Default-Stop:
    # Short-Description: Run /mnt/vnuml/umlboot if it exist
    ### END INIT INFO
    
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    
    . /lib/init/vars.sh
    . /lib/lsb/init-functions
    
    do_start() {
    	if [ -x /mnt/vnuml/umlboot ]; then
    	        [ "$VERBOSE" != no ] && log_begin_msg "Running vnxboot (/mnt/vnuml/umlboot)"
    		/mnt/vnuml/umlboot
    		ES=$?
    		[ "$VERBOSE" != no ] && log_end_msg $ES
    		return $ES
    	fi
    }
    
    case "$1" in
        start)
    	do_start
            ;;
        restart|reload|force-reload)
            echo "Error: argument '$1' not supported" >&2
            exit 3
            ;;
        stop)
            ;;
        *)
            echo "Usage: $0 start|stop" >&2
            exit 3
            ;;
    esac
    
  • Give it execution permissions and enable it at startup:
  • chmod +x /etc/init.d/vnxboot
    cd /etc/rc2.d
    ln -s ../init.d/vnxboot S11vnxboot
    update-rc.d vnxboot enable
    
  • Create the /usr/local/bin/vnx_halt script:
  • #!/bin/bash
    
    if [ "$1" == '-y' ]; then
        NOINTMODE='yes'
    fi
    
    # Clean apt cache
    apt-get clean
    apt-get -y autoremove
    
    # Delete /etc/resolv.conf
    rm -f /etc/resolv.conf
    
    # Clean command history
    rm -f /root/.bash_history
    
    # Delete udev net rules files:
    rm -f /etc/udev/rules.d/70-persistent-net.rules
    
    if [ ! $NOINTMODE ]; then
        while true; do
            # Ask for a message to save in /etc/vnx_rootfs_version file
            echo    "** Save a log message in /etc/vnx_rootfs_version file "
            echo -n "** describing the modifications done? "
            read -n 1 -p "[y/n] " answer
            echo ""
            case $answer in
                [Yy]* )
                        echo "** Log message (1 line maximum):"
                        read logmsg
                        DATE=`date`
                        echo "MODDATE=$DATE" >> /etc/vnx_rootfs_version
                        echo "MODDESC=$logmsg" >> /etc/vnx_rootfs_version
                        break;;
                [Nn]* ) break;;
                * )     echo "** Error: please answer 'y' or 'n'.";;
            esac
        done
    fi
    
    # Check whether we are running chrooted or not
    if [ ! -e /proc/1/root ]; then
      # Probably running chrooted. Do not halt!
      echo "**"
      echo "** Cannot read /proc. Probably running chrooted. Not halting"
      echo "** Type 'exit' to exit from chroot"
      exit
    elif [ ! -e /proc/1/root -o "$(stat -c %d:%i /)" != "$(stat -c %d:%i /proc/1/root/.)" ]; then
      # We are chrooted! Do not halt
      echo "**"
      echo "** Running chrooted. Not halting"
      echo "** Type 'exit' to exit from chroot"
      exit
    fi
    
    # We are NOT chrooted! We halt the virtual machine
    halt -p
    
  • Give it execution permissions:
  • chmod +x /usr/local/bin/vnx_halt
    
  • Create a file /etc/vnx_rootfs_version to store version number and informacion about modifications:
  • VER=v0.24
    OS=Debian Squeeze (6.0)
    DESC=Debian Squeeze root-file-system without GUI
    
  • Create /dev/ubd* devices:
  • cd /dev
    mknod --mode=660 ubda b 98 0
    mknod --mode=660 ubdb b 98 0
    chown root:disk ubda        
    chown root:disk ubdb
    
  • Clean caches and history files and optionally leave a description message /etc/vnx_rootfs_version file:
  • vnx_halt
    
  • Exit chroot: exit
  • Install kernel modules:
  • cd mnt/lib/modules/
    tar xfv /usr/share/vnx/kernels/linux-3.3.8-um-src/modules-3.3.8.tar 
    cd ../../../
    
  • Umount rootfs to finish installation:
  • umount mnt/proc/
    umount mnt
    

    Note: if you cannot umount 'mnt' directory, check which process is blocking the unmounting operation with 'lsof mnt' and stop it.

Installing additional software

There is two basic ways to update a UML root filesystems:

A. Starting a virtual machine that mounts the rootfs in direct mode:

  • Create a VNX scenario named, for example, update_uml.xml (available in /usr/share/vnx/examples):
  • <?xml version="1.0" encoding="UTF-8"?>
    <!--
    ~~~~~~~~~~~~~~~~~~~~
    VNX Sample scenarios
    ~~~~~~~~~~~~~~~~~~~~
    Name:        update_uml
    Description: Simple scenario to start a uml virtual machine in direct mode to make modifications 
                 in a filesystem. Tha VM is connected to virbr0, the default network used by libvirt, 
                 to gain network connectivity.
    
    This file is part of the Virtual Networks over LinuX (VNX) Project distribution. 
    (www: http://www.dit.upm.es/vnx - e-mail: vnx@dit.upm.es) 
    
    Departamento de Ingenieria de Sistemas Telematicos (DIT)
    Universidad Politecnica de Madrid
    SPAIN
    -->
    
    <vnx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="/usr/share/xml/vnx/vnx-2.00.xsd">
      <global>
        <version>2.0</version>
        <scenario_name>update_uml</scenario_name>
        <automac/>
        <vm_mgmt type="none" />
        <vm_defaults>
            <exec_mode type="uml">mconsole</exec_mode>
        </vm_defaults>
      </global>
    
      <net name="virbr0" mode="virtual_bridge" />
    
      <vm name="uml" type="uml" subtype="" os="">
        <filesystem type="direct">ROOTFS_PATHNAME</filesystem>
        <mem>64M</mem>
        <kernel trace="on">UML_KERNEL</kernel>
        <console id="0" display="yes">xterm</console>
        <if id="1" net="virbr0">
        </if>
        <exec seq="on_boot" type="verbatim">dhclient eth1</exec>
      </vm>
    
    </vnx>
    

    Change ROOTFS_PATHNAME and UML_KERNEL by the full pathname of the root filesystem to be modified and the UML kernel to be used to start it.

  • Start the virtual machine with:
  • vnx -f update_uml.xml -v -t
    
  • Once started, check that the virtual machine has network connectivity. If not, try to configure it with:
  • dhclient eth1
    
  • Do the installations or modifications desired
  • Finally, clean caches and history files and, optionally, leave a message describing the modifications done (saved to /etc/vnx_rootfs_version file), befor halting the virtual machine:
  • vnx_halt
    

B. Mounting the rootfs and chrooting to it:

  • Mount the rootfs:
  • mkdir mnt
    mount -o loop vnx_rootfs_uml_debian.img mnt/
    mount -t proc none mnt/proc
    
  • Chroot:
  • chroot mnt
    env -update
    
  • Check you have network connectivity. You'll probably have to modify /etc/resolv.conf file to configure DNS server IP address
  • Modify the rootfs
  • Clean caches and history files and optionally leave a message describing the modifications done (saved to /etc/vnx_rootfs_version file:
  • vnx_halt
    
  • Exit chroot an umount:
  • exit
    umount mnt/proc
    umount mnt
    

    Note: if you cannot umount 'mnt' directory, check which process is blocking the unmounting operation with 'lsof mnt' and stop it.