3 AUTHOR: Randy Hron <rwhron (at) earthlink.net>
6 How to configure a basic user-mode-linux on lfs.
9 This hint is for user-mode-linux (UML) for linux-2.4.x. It helps you
10 build a UML kernel and create a small root filesystem for UML. The
11 kernel and root_fs build are done with two scripts. build_uml
12 builds the UML kernel and build_rootfs creates a root filesystem.
13 The root filesystem we build can be configured to automatically mount
14 the host / and /usr/src filesystems. For this reason, and many others
15 it's best to only run UML as a non-root user. You will have to be
16 root to create the root_fs though.
22 Where can I find out more?
23 UML Patch for 2.4.x kernel
26 Assumptions for this hint
27 Installing uml_utilities
32 Building the user-mode-linux kernel
33 build_uml - Build UML kernel script from source
34 Comments on UML kernel build commands
35 Cleaning up UML processes
36 Creating a root filesystem for user-mode-linux
37 build_rootfs - Root filesystem build script
38 Comments on commands to build root_fs
42 Taking down loopback filesystem if something went wrong
45 UML hangs with "Initializing stdio console driver"
46 Xterm insane after shutdown
47 Panic when you have root_fs
49 kernel BUG at page_alloc.c:112!
51 ioctl: LOOP_SET_FD: Device or resource busy
52 make does not return when compiling with UML
59 This information is meant to be helpful only. It contains the scripts I use.
60 There is no warranty of any kind. If you use this information, you take full
61 liability for anything that goes wrong.
65 Experimentation. It's fun. You could try a new glibc without fear of changing
66 your LFS by running it in user-mode-linux first. Setup a virtual network with only
67 one box. Answer questions like, "what happens if I...".
69 Where can I find out more?
70 ==========================
71 Project: http://user-mode-linux.sourceforge.net/
72 HOWTO: http://user-mode-linux.sourceforge.net/UserModeLinux-HOWTO.html
73 Download: http://user-mode-linux.sourceforge.net/dl-sf.html
75 UML Patch for 2.4.x kernel
76 ==========================
77 The patch for user-mode-linux is available through the Download link. You need
78 the UML patch for the kernel you want to build. The UML kernel version can
79 be different from your host system. I.E. you can run 2.4.14 on LFS and boot
80 a 2.4.18 UML kernel. The UML patches come out quite regularly, so check the
81 UML webite for patches for newer kernels. The latest uml-patch should be the
84 uml-patch-2.4.18-18.bz2 goes with kernel linux-2.4.18. This example happens
85 to be the 18th UML release for 2.4.18.
89 host: Your linux box. It is "hosting" the virtual
91 host kernel: The kernel for your LFS system. It "hosts" the
93 kernel pool: Source code tree of stable kernel. (extracted
94 2.4.x kernel tarball).
95 pool: The HOWTO uses pool to refer to a directory tree,
96 like cvs, linux source, or the UML source tree.
98 vanilla kernel: Term some people call the official Linus (or Marcelo)
100 virtual machine: Another name for a UML instance.
104 linux-2.4.18.tar.bz2 kernel source
105 uml-patch-2.4.18-18.bz2
106 uml_utilities_20020415.tar.bz2
107 readline-4.2 or greater. # for uml_utilities.
108 reiserfsprogs-3.x.1b.tar.gz or greater # 3.x.1a may work.
111 The versions above were current when this hint was written. Newer
112 versions will work similarly, but you will have to edit the build_uml
113 script or pass it a command line argument.
115 Assumptions for this hint
116 =========================
117 o You have the files in the "What do I need" section above.
118 o You have Loopback Device (CONFIG_BLK_DEV_LOOP) support configured in
119 your host kernel (this doesn't mean lo0 = 127.0.0.1. Loopback block
120 device allows a regular file to be used as a block device. We use
121 this feature to create the UML filesystem.
122 o You have TUN/TAP (CONFIG_TUN) configured in your kernel.
123 o You don't have anything in /mnt/uml or /usr/src/uml, as the build scripts
124 included here will unquestionably stomp these directories, (unless you
125 pass appropriate arguments to the scripts).
126 o You have reiserfsprogs installed, and CONFIG_REISERFS_FS=y set in your host
127 linux .config. ext[23] will work also; you'll have to change the build_rootfs
129 o You have at least 32 megs of free ram. You can boot UML with less, by passing
130 mem=#m on the command line. I.E. ./linux init=/bin/bash mem=16m will boot a
131 virtual machine with 16 megs of ram. 8 megs is about as small as you can go.
134 Installing uml_utilities
135 ========================
136 We start by installing the uml_utilities.
138 tar xjf uml_utilities_20020415.tar.bz2 &&
139 cd tools && make && make install
141 The commands above install five UML utilities in /usr/bin on the "host" system
146 uml_mconsole is the management console for a UML.
150 uml_moo is a clever name for copy on write (COW) merge utility. The idea
151 of COW is that you can share a root_fs (backing store, actually) between
152 multiple UML's, and changes are written to a COW file. This utility lets
153 you merge the COW file with the backing store. Check out the UML website
154 for details. This hint won't use uml_moo.
158 uml_net is for setting up a network between the host system and UML.
159 uml_net must be installed setuid root so you can setup networking when
160 you run UML as a non-root user.
164 uml_switch lets you setup a router network between UML's and the host system.
165 uml_switch is also installed in /usr/bin on the host system. This hint
166 doesn't use uml_switch.
170 Helper for the port channel. This hint doesn't use port_helper either.
173 Building the user-mode-linux kernel
174 ===================================
175 IMPORTANT NOTE: Don't build user-mode-linux in /usr/src/linux because UML
176 replaces some headers that other linux programs could use. Also, you don't
177 want to stomp your "host" kernel source.
179 Note: the scripts below assume your linux kernel source is in
180 /usr/src/sources/l and the user-mode-linux patch in /usr/src/sources/u.
181 Change these paths to match where you have the kernel and uml-patch
184 There is some explanation of the scripts below each one.
186 build_uml - Build UML kernel script from source
187 ===============================================
190 # build_uml - create user mode linux kernel from source
191 # the defaults are good for me, they probably aren't good for you.
192 # @(#) $Id: uml.txt,v 1.1 2003/09/13 16:18:16 tushar Exp $
196 echo "$command is meant to abort if it encounters a problem."
197 echo "The idea is that you can address that problem,"
198 echo "then re-run $command from the begining."
202 uml_dest="/usr/src/uml"
203 kernel_tarball="/usr/src/sources/l/linux-2.4.18.tar.bz2"
206 uml_patch="/usr/src/sources/u/uml-patch-2.4.18-18.bz2"
211 echo "usage: $command [ -c dot_config_file ] [ -d /path/to/uml/target ] "
212 echo " [ -k /path/to/kernel/tarball.tar.bz2 ] [ -s ] [ -t tar_unZ_opt ]"
213 echo " [ -u /path/to/uml/patch.bz2 ] [ -v ]" >&2
215 echo "example: $command -d${uml_dest} -k${kernel_tarball} \\"
216 echo " -u${uml_patch}" >&2
218 echo "options defaults" >&2
219 echo " c .config file to use $config" >&2
220 echo " d destination for uml tree $uml_dest" >&2
221 echo " k linux tarball $kernel_tarball" >&2
222 echo " s silent make $make_opt" >&2
223 echo " t tar uncompress option $tar_z_opt" >&2
224 echo " u user-mode-linux patch $uml_patch" >&2
225 echo " v verbose" >&2
233 # c config file to use
234 # d destination for uml tree
237 # t tar uncompress option
238 # u user-mode-linux patch
240 while getopts :c:d:k:st:u:v arg
244 d) uml_dest=$OPTARG;;
245 k) kernel_tarball=$OPTARG;;
247 t) tar_z_opt=$OPTARG;;
248 u) uml_patch=$OPTARG;;
249 # v doubles as an option for tar
251 \?) echo "$command: Invalid switch $OPTARG" >&2
259 if [[ ! -f $kernel_tarball ]]
260 then echo -e "\nThere is not kernel tarball in $kernel_tarball" >&2
264 if [[ ! -f $uml_patch ]]
265 then echo -e "\nThere is no uml patch in $uml_patch" >&2
269 if [[ ! -f $config ]]
270 then if [[ ! -f /usr/src/linux/.config ]]
271 then echo -e "\nThere is no $config or /usr/src/linux/.config file," >&2
272 echo -e "which is where $command wanted to get your host config." >&2
281 echo "Current options:" >&2
282 echo "config=$config" >&2
283 echo "uml_dest=$uml_dest" >&2
284 echo "kernel_tarball=$kernel_tarball" >&2
285 echo "make_opt=$make_opt" >&2
286 echo "tar_z_opt=$tar_z_opt" >&2
287 echo "uml_patch=$uml_patch" >&2
288 echo "verbose=$verbose" >&2
291 if [[ $error = yes ]]
292 then echo -e "\nErrors detected ... $command will exit.\n" >&2
293 echo -e "The current options are listed above.\n" >&2
297 [ -c /dev/tap0 ] || mknod /dev/tap0 c 36 16 &&
298 echo -n "ok to remove $uml_dest (y/N)? "
301 y*|Y*) echo "removing $uml_dest"
305 echo "$command rebuilds the entire uml kernel tree from scratch."
306 echo "If $uml_dest isn't where you want the uml kernel built,"
307 echo "try passing -u /where/i/want/uml/kernel/built to ${command}."
314 echo "extracting $kernel_tarball in $PWD" &&
315 tar x${tar_z_opt}${verbose}f $kernel_tarball &&
317 # perhaps we should allow other compression formats.
318 echo "applying $uml_patch"
319 bzcat $uml_patch|patch -p1 &&
321 make mrproper ARCH=um &&
322 # forgot why we do this
325 then cp $config ${uml_dest}/linux/.config &&
326 yes "y" | make oldconfig ARCH=um
327 else echo "no $config file"
328 echo "using default configuration, which may (not) work"
330 # there was a bug around 2.4.9 that required these sed statements.
331 sed 's:^CONFIG_GPROF.*:# CONFIG_GPROF is not set:' .config>.config~ &&
332 mv .config~ .config &&
333 sed 's:^CONFIG_GCOV.*:# CONFIG_GCOV is not set:' .config>.config~ &&
334 mv .config~ .config &&
335 yes "" | make config ARCH=um &&
336 # UML SMP wasn't working on my box.
337 sed 's:\(^CONFIG_.*SMP\)=.:# \1 is not set:' .config>.config~ &&
338 mv .config~ .config &&
339 # Since I'm not using X, don't default to console on xterm.
340 sed 's:^CONFIG_CON_CHAN=xterm:CONFIG_CON_CHAN=pty:' .config>.config~ &&
341 mv .config~ .config &&
343 make linux ARCH=um &&
344 make modules ARCH=um &&
347 echo "The UML kernel is in $uml_dest/linux" &&
348 echo "You'll need a root filesystem." &&
349 echo "Run 'build_rootfs' to create a root filesystem in $uml_dest/linux"
352 Comments on UML kernel build commands
353 =====================================
354 Extract the pristine linux source for your UML tree. Install the UML patch.
355 Keep most of your current configuration (if possible) by copying .config
356 from /usr/src/linux (not really necessary, just convenient). Say "y"
357 to the new config options from the UML patch. We run 'sed' against the
358 config file as CONFIG_GPROF and CONFIG_GCOV were not be working perfectly
359 when this was written. Unset PAGER because I saw "make oldconfig" using
360 $PAGER once and didn't like it. Creates /dev/tap0 if it doesn't exist.
361 (you set CONFIG_TUN in your host kernel, right?)
363 Changing UML kernel configuration
364 ---------------------------------
365 If you want to change the configuration for UML from what the host system
368 cd /usr/src/uml/linux
369 make menuconfig ARCH=um
376 After running the commands above you will have a file called
377 /usr/src/uml/linux/linux. This is the UML kernel. You can run it now as
378 any user (preferably not root, just to be safe). It will panic because
379 there is no root filesystem for UML yet. Here is then end of the boot
380 when there is no rootfs:
382 ubd0: Can't open "root_fs": errno = 2
383 VFS: Cannot open root device "ubd0" or 62:00
384 Please append a correct "root=" boot option
385 Kernel panic: VFS: Unable to mount root fs on 62:00
387 No problem, we'll create a root filesystem in a little bit. Just hit
388 <ctrl c> to kill the UML process.
390 Cleaning up UML processes
391 =========================
392 If you were couragous and booted the kernel without root_fs to see the panic,
393 you'll have some UML processes hanging around. You can kill them with a
396 kill -9 $(ps -fu $LOGNAME|awk '/linux/ {print $2}')
400 alias kuml="kill -9 \$(ps -fu\$LOGNAME|awk '/\.\/[l]inux/ {print \$2}')"
402 Creating a root filesystem for user-mode-linux
403 ==============================================
404 User mode linux will have it's own filesystem. You have to have
405 CONFIG_BLK_DEV_LOOP defined in your kernel to create a root filesystem
406 for user-mode-linux. Look at your /usr/src/linux/.config file to see
407 if you already have the block loopback device. If you don't, configure
408 and compile your normal (host) boot kernel before continuing.
410 We'll create a 200 megabyte root filesystem using reiserfs. This filesystem
411 will not contain everything that a basic LFS system has, but it could. For
412 now, just /bin /sbin /lib, and a few bits of /usr/bin and /etc.
414 Note: The script below uses "here documents" and is very sensitive to
415 extraneous spaces. I.E. a space after a '!' character can cause the
416 script to not complete. The safe way to execute this is to pop this
417 file into vim and grab the script verbatum. Then read it and change
420 There are some variables you may want to change in the script:
422 About 37 lines into the script there is an "export user=rwhron"
423 line. You want to change that to whatever user you normally login as.
424 We will grab /etc/passwd from the host system, so root for UML will be
425 your normal root password.
427 55 lines into the script you can set "hostfs=true" if you want UML
428 to access the the host root and /usr/src filesystems.
430 Look at the script closely. There may be some other things you
431 want to change too. Most of the things you may want to modify
432 are in the first 69 lines or so.
434 build_rootfs - root filesystem build script
435 ===========================================
438 # note the "-e" above - it means exit script on any error.
439 # @(#) $Id: uml.txt,v 1.1 2003/09/13 16:18:16 tushar Exp $
441 PATH=/sbin:/bin:/usr/sbin:/usr/bin
442 # build_rootfs - create a basic root filesystem for user mode linux
443 # uses BSD style init scripts. (nice and simple).
447 # root has to run build_rootfs to execute losetup environment.
449 then echo "root has to run $command for losetup" >&2
453 # $uml is where root_fs will be temporarily mounted while
454 # it is built. $uml_root will get blown away by this script.
457 # loopback block device - $loop will be mounted on $uml_root
460 # cleanup if build_rootfs bombed in a previous run.
461 if mount|grep $uml_root >/dev/null
462 then umount $uml_root
466 # uml_dest is the directory the uml root filesystem will be built in.
467 uml_dest=/usr/src/uml
469 # root_fs is the default name, if you change it, you'll have to
470 # pass an option to uml with the rootfs name.
472 # if user is set, the script will su to $user and boot uml at the end
476 # size of filesystem in megs
481 # uml_tun_ip is the address you want the uml machine to have.
482 uml_tun_ip="192.168.0.250"
483 # interface address of tap0 (interface to uml) - becomes uml defaultroute.
484 # this should not be the same as eth0 or ppp0.
485 host_tun_ip="192.168.0.230"
487 # hostfs lets you mount host filesystem under uml
490 # set hostfs to true to mount host / on /mnt/$host and
491 # host /usr/src under /mnt/$host/usr/src
494 # set devel=true if you want compilers and header files.
497 # command to create filesystem --format 3.6 needed for
498 # reiserfsprogs 3.x.0k-pre14 on linux-2.5.x host, to get
499 # the --format option for mkreiserfs.
500 #mkfs="mkreiserfs --format 3.6"
503 # set network_server=true if you want uml network server commands
507 echo "usage: $command [ -d /path/to/uml/dest ] [ -f ] [ -g ] [ -h uml_hostname ]"
508 echo " [ -i uml_ipaddress ] [ -m megs ] [ -n ] [ -s ] [ -r /path/to/uml_root ]"
509 echo " [ -u /path/to/uml/patch.bz2 ] [ -v ]" >&2
511 echo "example: $command -d/usr/src/uml -f -h myuml -i 192.168.0.222 \\"
512 echo " -m 500 -r/mnt/uml2 >&2"
514 echo "options defaults" >&2
515 echo " d destination for uml tree $uml_dest" >&2
516 echo " f use hostfs $hostfs" >&2
517 echo " g add development files $devel" >&2
518 echo " h uml hostname $uml_hostname" >&2
519 echo " i uml ip address $uml_tun_ip" >&2
520 echo " m rootfs size in MB $megs" >&2
521 echo " n network server $network_server" >&2
522 echo " r uml root for build $uml_root" >&2
523 echo " s silent make true" >&2
530 # d destination for uml tree
532 # t tar uncompress option
533 # u user-mode-linux patch
535 while getopts :d:fgh:i:m:ns arg
538 d) uml_dest=$OPTARG;;
540 g) devel=false;; # guru
541 h) uml_hostname=$OPTARG;;
542 i) uml_tun_ip=$OPTARG;;
543 m) megs=$OPTARG;; # number
544 n) network_server=false;;
545 r) uml_root=$OPTARG;;
547 \?) echo "$command: Invalid switch $OPTARG" >&2
553 # list of daemons in /usr/sbin that you want if network_server=true
554 network_usr_sbin_daemons="inetd in.telnetd in.rlogind in.ftpd tcpd"
556 # commands to grab from /usr/bin on host machine
557 usr_bin="awk basename bc cal chroot cksum clear cmp col cut dc diff dirname ed
558 egrep ex expr file find fmt fold free ftp fuser gawk getconf grep head id join
559 last ldd nohup od passwd paste perl pkill procinfo reset setterm sleep sort split
560 ssh ssh-keygen strace strings tail tee test time top tput tr tset tty uptime vi
561 vim vmstat xargs w wc who"
563 # these might help figuring out <ctrl c \>
564 key_cmds="dumpkeys getkeycodes setkeycodes showkey"
566 usr_bin="$usr_bin $key_cmds"
568 # eliminate any files that haven't been installed
570 do [ -f /usr/bin/$f ] && ub="$ub $f"
574 # readprofile requires System.map
575 usr_sbin="klogd readprofile sshd syslogd tcpdump xinetd"
576 # eliminate any files that haven't been installed
578 do [ -f /usr/sbin/$f ] && us="$us $f"
582 # /usr/bin commands included if $devel is true
583 usr_bin_dev="ar as as86 as86_encap autoconf autoexpect autoheader automake
584 autoreconf autoscan autoupdate bison c++ c++filt cc cpp flex flex++ g++ gasp
585 gcc gdb ld ld86 m4 make nm nm86 objcopy objdump objdump86 patch ranlib size
587 # eliminate any files that haven't been installed
588 for f in $usr_bin_dev
589 do [ -f /usr/bin/$f ] && ud="$ud $f"
593 # set v=v for verbose build
596 # argument to make ARCH=um install_modules quiet
599 ########### end of configuration setup ##############
601 # host system will need a tap interface
602 if [[ ! -c /dev/tap0 ]]
603 then mknod /dev/tap0 c 36 16
608 # use /dev/zero for building a file full of 00000000's
609 if [[ ! -c /dev/zero ]]
610 then mknod --mode 0644 /dev/zero c 1 5
615 dd if=/dev/zero of=$root_fs seek=$megs count=1 bs=1M
618 losetup $loop $uml_dest/linux/$root_fs
620 # take the defaults creating reiserfs
625 # mount the loopback reiserfs file
626 mount -t reiserfs $loop $uml_root
629 # create directory structure and copy /lib /sbin /dev into rootfs
630 mkdir -p bin dev etc lib mnt proc root sbin tmp usr/{bin,sbin,src} var/{log,run,tmp}
631 chmod 1777 tmp var/tmp
633 # duplicate the dev directory of the host system
635 echo -en "/dev\t\t\t\t\t"
636 find . -print|cpio -pdm $uml_root/dev
638 # create ttyp (slave) and ptyp (master) for console if necessary.
641 do [[ ! -c ptyp$i ]] && mknod --mode=644 ptyp$i c 2 $i
642 [[ ! -c ttyp$i ]] && mknod --mode=644 ttyp$i c 3 $i
646 # # put everything in /sbin /bin and /lib on uml root_fs
647 # copy everything in /sbin and /bin on uml root_fs
649 echo -en "/sbin\t\t\t\t\t"
650 find . -print|cpio -pdm $uml_root/sbin
653 echo -en "/bin\t\t\t\t\t"
654 find . -print|cpio -pdm $uml_root/bin
656 # grab some goodies from /usr/bin and /usr/sbin
658 echo -en "/usr/bin\t\t\t\t"
659 find $usr_bin|cpio -pdm $uml_root/usr/bin
661 echo -en "/usr/sbin\t\t\t\t"
662 find $usr_sbin|cpio -pdm $uml_root/usr/sbin
664 # maybe this will make <ctrl c> work for /dev/console (nope)
666 echo -en "/usr/share/kbd\t\t\t\t"
667 find share/kbd|cpio -pdm $uml_root/usr
668 echo -en "/usr/share/misc/magic\t\t\t"
669 find share/misc/magic*|cpio -pdm $uml_root/usr
671 # grab linux terminfo and keyboard files
672 mkdir -p $uml_root/usr/share/terminfo/l
673 [[ -f /usr/share/terminfo/l/linux ]] && cp -p /usr/share/terminfo/l/linux $uml_root/usr/share/terminfo/l
675 # development support files
676 if [[ $devel == true ]]
677 then echo "Including files for development"
679 echo -en "Development commands\t\t\t"
680 find $usr_bin_dev|cpio -pdm $uml_root/usr/bin
683 echo -en "/usr/lib/gcc-lib\t\t\t"
684 find gcc-lib *crt*.o|cpio -pdm $uml_root/usr/lib
685 # /usr/$MACHTYPE has some support files for binutils.
686 # get header files too
688 echo -en "/usr/include\t\t\t\t"
689 find include $MACHTYPE|cpio -pudm $uml_root/usr
693 if [[ $network_server == true ]]
695 for f in $network_usr_sbin_daemons
697 then cp -${v}p $f ${uml_root}/usr/sbin/${f}
704 # Run ldd on everything to figure out what libs we need.
706 echo -en "Libraries\t\t\t\t"
707 libs=$(ldd sbin/* bin/* usr/sbin/* usr/bin/* 2>/dev/null|
708 awk '/=>/ {print $3}'|egrep -v '^/lib|perl5/'|sort -u|
709 sed -e 's:-.*:\*.so\*:' -e 's:\.*so.*:\*so\*:')
711 # grab all of /lib, other libs needed by commands, and /usr/lib/libc*
712 find lib/*so* $libs usr/lib/libc*|sed 's:^/::'|cpio -pudm $uml_root
713 if [[ -f $uml_root/usr/bin/perl ]]
714 then echo -en "Perl libs\t\t\t\t"
715 find usr/lib/perl5|cpio -pdm $uml_root
718 # create an empty ld.so.conf for ldconfig
719 > $uml_root/etc/ld.so.conf
720 ldconfig -${v}r $uml_root
723 echo -en "/etc\t\t\t\t\t"
724 # some important things in /etc
725 [[ -f /etc/bashrc ]] && cp -p /etc/bashrc $uml_root/etc
726 [[ -f /etc/hosts ]] && cp -p /etc/hosts $uml_root/etc
727 [[ -f /etc/inetd.conf ]] && cp -p /etc/inetd.conf $uml_root/etc
728 [[ -f /etc/inputrc ]] && cp -p /etc/inputrc $uml_root/etc
729 [[ -f /etc/limits ]] && cp -p /etc/limits $uml_root/etc
730 [[ -e /etc/localtime ]] && cp -d /etc/localtime $uml_root/etc
731 [[ -f /etc/login.defs ]] && cp -p /etc/login.defs $uml_root/etc
732 [[ -f /etc/nsswitch.conf ]] && cp -p /etc/nsswitch.conf $uml_root/etc
733 [[ -f /etc/profile ]] && cp -p /etc/profile $uml_root/etc
734 [[ -f /etc/protocols ]] && cp -p /etc/protocols $uml_root/etc
735 [[ -f /etc/resolv.conf ]] && cp -p /etc/resolv.conf $uml_root/etc
736 [[ -f /etc/services ]] && cp -p /etc/services $uml_root/etc
737 [[ -d /etc/ssh ]] && cp -rp /etc/ssh $uml_root/etc
738 # UML host will need new host keys
739 rm -f $uml_root/etc/ssh/*key
740 [[ -f /etc/syslog.conf ]] && cp -p /etc/syslog.conf $uml_root/etc
742 # instruct about login
744 You can log into $uml_hostname with one of your normal accounts or root.
745 The passwords are the same as on $(hostname).
746 " > $uml_root/etc/issue
748 # Get passwd and shadow so we can login with the same accounts as the host
749 cp -p /etc/passwd /etc/shadow /etc/group $uml_root/etc
753 cat<<!>$uml_root/etc/fstab
754 /dev/bd0 / reiserfs defaults 0 0
755 proc /proc proc defaults 0 0
756 none /dev/pts devpts defaults 0 0
759 # append hostfs to fstab if desired
760 if [[ $hostfs == true ]]
761 then cat<<-!>>$uml_root/etc/fstab
762 none /mnt/$host hostfs defaults 0 0
763 none /mnt/$host/usr/src hostfs /usr/src 0 0
765 mkdir -p $uml_root/mnt/$host/usr/src
769 cat <<!>$uml_root/etc/inittab
770 # user-mode-linux inittab
772 si::sysinit:/etc/rc.d/rc.sysinit
773 l0:0:wait:/etc/rc.d/rc.0
774 l1:S1:wait:/etc/rc.d/rc.1
775 l2:2:wait:/etc/rc.d/rc.2
776 l3:3:wait:/etc/rc.d/rc.3
777 l4:4:wait:/etc/rc.d/rc.4
778 l5:5:wait:/etc/rc.d/rc.5
779 l6:6:wait:/etc/rc.d/rc.6
780 ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
781 su:S016:wait:/sbin/sulogin
782 c1:23:respawn:/sbin/agetty console 38400 linux
786 mkdir $uml_root/etc/rc.d
788 # Create rc.sysinit for uml.
789 cat<<!>$uml_root/etc/rc.d/rc.sysinit
791 # begin of /etc/rc.d/rc.sysinit
793 # Mount root device ro.
794 /bin/mount -n -o remount,ro /
796 # Mount swap partitions.
799 # Remount root device rw.
800 /bin/mount -n -v -o remount,rw /
803 /bin/mount -f -o remount,rw /
805 # Mount special filesystems
809 # Initialize loopback network interface.
810 /sbin/ifconfig lo 127.0.0.1
813 /bin/hostname -v $uml_hostname
815 # Recreate the utmp file so w/who are correct.
818 chmod 0644 /var/run/utmp
820 # end of /etc/rc.d/rc.sysinit
823 # Create rc.0 for uml.
824 cat <<!>$uml_root/etc/rc.d/rc.0
827 # Sending TERM signal to all processes.
830 # Sending KILL signal to all processes.
833 # Unmounting swap partitions.
836 # put marker in messages
848 # Remount root filesystem ro.
849 /bin/mount -n -o remount,ro /
851 # Unmount other filesystems
856 /sbin/reboot -d -f -i
862 # end of /etc/rc.d/rc.0
864 # end of here doc for /etc/rc.d/rc.0
866 # Create rc.1 for uml.
867 cat<<!>$uml_root/etc/rc.d/rc.1
871 # Send TERM signal to all processes.
874 # Send KILL signal to all processes.
878 /sbin/ifconfig eth0 down
880 # end of /etc/rc.d/rc.1
882 # end of here document for /etc/rc.d/rc.1
884 # Create rc.2 for uml
885 cat<<!>$uml_root/etc/rc.d/rc.2
891 /bin/mkdir --mode=1777 /tmp
893 # don't put MARK in syslog every 20 minutes
894 /usr/sbin/syslogd -m0
896 # -c set console log level to 3 (warning?)
897 # -x Omits EIP translation and therefore doesn't read the System.map file.
898 # Suggestion from Keith Owens on lkml on 10/31/2001.
899 #/usr/sbin/klogd -c3 -x -k /boot/System.map-`uname -r`
900 /usr/sbin/klogd -c3 -x
902 # load default keymap
905 # Initialize uml eth0.
906 /sbin/ifconfig eth0 $uml_tun_ip up
907 /sbin/route add default gw $host_tun_ip
909 # Starting inetd server.
910 if [[ -r /etc/inetd.conf ]] && [[ -x /usr/sbin/inetd ]]
914 if [[ -x /usr/sbin/sshd ]]
915 then if [ -d /etc/ssh ]
916 then if [ -f /etc/ssh/ssh_host_key ]
917 then echo "/etc/ssh/ssh_host_key already exists, skipping."
918 else ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_key -N ""
920 if [ -f /etc/ssh/ssh_host_dsa_key ]
921 then echo "/etc/ssh/ssh_host_dsa_key already exists, skipping."
922 else ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ""
924 if [ -f /etc/ssh/ssh_host_rsa_key ]
925 then echo "/etc/ssh/ssh_host_rsa_key already exists, skipping."
926 else ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ""
932 # Mount other filesystems
934 # end of /etc/rc.d/rc.1
937 # links for rc scripts
938 cd $uml_root/etc/rc.d
944 # permissions for rc scripts
945 cd $uml_root/etc/rc.d
952 # install modules from uml kernel
953 echo -en "Installing kernel modules\t\t"
955 make $silent_make modules_install INSTALL_MOD_PATH=$uml_root ARCH=um
958 # basic .bash_profile for root.
960 cat<<EOF>.bash_profile
961 export PATH="\$PATH:/sbin:/usr/sbin"
969 echo "umounting $uml_root"
971 echo "detaching $loop"
974 if ! grep -q $user /etc/passwd
975 then echo "change user=$user at the top of $0 to whatever your login name is"
976 else chown $user:root $uml_dest/linux/$root_fs
979 # load tun driver on host system - only necessar.
980 if [[ -f /lib/modules/`uname -r`/kernel/drivers/net/tun.o ]] && ! modprobe tun
985 # boot uml if user was specified in script.
988 echo -e "\nBooting uml!\n"
989 su - $user -c "cd $uml_dest/linux&&./linux rootfs=$root_fs eth0=tuntap,,,$host_tun_ip umid=$uml_hostname"
990 else echo "Your uml $root_fs is in $uml_dest"
991 echo "boot uml as a non-root user with a command like:"
992 echo "cd $uml_dest/linux && ./linux rootfs=$root_fs eth0=tuntap,,,$host_tun_ip umid=$uml_hostname"
994 # use the line below for no networking, and no init. It may be useful
995 # for troubleshooting.
996 #su - $user -c "cd $uml_dest/linux&&./linux rootfs=$root_fs init=/bin/bash"
997 # end of build_root_fs
999 Comments on commands to build root_fs
1000 =========================================
1001 Create a 200 megabyte sparse file called root_fs and associate it with
1002 /dev/loop0. Copy devices, /lib, /sbin, /bin, a few things from /etc, and
1003 /usr/bin into the loopback root filesystem. If devel=true is set in
1004 build_rootfs, part of /usr/bin, /usr/lib/gcc-lib and /usr/include will
1005 be copied too. Create bsd style init scripts.
1007 If you defined user=somebody, build_rootfs will boot UML. You can always
1008 boot UML after building root_fs with a command like:
1010 Switch back to a non-priviledged user and run the kernel:
1012 ./linux init=/bin/bash
1016 ./linux rootfs=root_fs eth0=ethertap,tap0,,$uml_ip_address umid=$LOGNAME
1020 Login to UML as root with your usual root password. To the host
1021 filesystem, you will still be a non-priviledged user. You will
1022 be root in the UML environment. Take a look around. If the terminal
1023 doesn't format properly, try the reset(1) command. When you
1024 are done, type /sbin/halt to kill UML. If you can't shutdown
1025 the UML for some reason, just kill the "linux" processes from UML.
1029 You can do some UML management with uml_mconsole. The "management"
1030 device is printed in the boot message, and it changes from boot to boot.
1031 You can make the socket used my mconsole stay the same by adding
1032 umid=something to the UML command line. In this example, the
1033 socket will by /tmp/uml/something/mconsole.
1035 uml_mconsole /tmp/uml/something/mconsole
1037 OK Linux uml 2.4.16-2um #1 Tue Dec 11 21:15:47 EST 2001 i686
1043 sync # halt in mconsole doesn't sync the filesystem.
1044 /sbin/halt # from within UML
1045 kuml # alias mentioned earlier if UML processes are still out there.
1047 Taking down loopback filesystem if something went wrong
1048 =======================================================
1050 losetup -d /dev/loop0
1054 The first place to look for troubleshooting help is the FAQ at:
1055 http://user-mode-linux.sourceforge.net/faq.html
1056 Some other troubleshooting suggestions below.
1060 Run "make ARCH=um menuconfig" in the uml source tree (default /usr/src/uml/linux)
1061 and disabling drivers that are questionable for UML. This could include DRI,
1062 APM, sound, and other things that you won't use in UML. Save the possibly
1063 better .config file that menuconfig creates into the directory you have
1064 build_uml in. build_uml looks for a .config file in the current directory
1065 before it tries /usr/src/linux/.config. Then run:
1066 make ARCH=um dep linux modules
1068 UML hangs with "Initializing stdio console driver"
1069 --------------------------------------------------
1070 The default console is an xterm. Configure CONFIG_CON_CHAN=pty instead
1073 Xterm insane after shutdown
1074 ---------------------------
1075 If your X terminal goes haywire, after killing UML, try "reset;reset;clear".
1077 Panic when you have root_fs
1078 ---------------------------
1079 If you run UML as non-root, the user running UML must own root_fs.
1080 chown the root_fs file, (not everything inside root_fs).
1082 Error building kernel
1083 ---------------------
1084 gcc -Wl,-T,/usr/src/uml/linux/arch/um/link.ld -o linux -static \
1085 /usr/src/uml/linux/arch/um/main.o vmlinux.o -L/usr/lib
1086 vmlinux.o: In function `linux_main':
1087 /usr/src/uml/linux/arch/um/kernel/um_arch.c:211: undefined reference
1088 to `remap_profiling_buffers'
1089 collect2: ld returned 1 exit status
1090 make: *** [linux] Error 1
1091 Somehow CONFIG_GPROF in .config is defined to 1. make mrproper and try building
1092 the kernel again. Read the build_uml script, there's a sed hack in there for this.
1095 kernel BUG at page_alloc.c:112!
1096 ------------------------------
1097 Similar to the previous error. CONFIG_GPROF and CONFIG_GCOV are set. Look at
1098 the sed hack for the CONFIG in build_uml. Here is what the error may look like:
1100 hrandoz@rushmore:/usr/src/uml/linux$ ./linux
1101 tracing thread pid = 17848
1102 Linux version 2.4.15-3um (hrandoz@rushmore) (gcc version 2.95.3 20010315 (release)) #1 Sun Dec 2 13:19:51 EST 2001
1103 On node 0 totalpages: 8192
1105 zone(1): 8192 pages.
1107 Kernel command line: root=/dev/ubd0
1108 Calibrating delay loop... 25.47 BogoMIPS
1109 kernel BUG at page_alloc.c:112!
1113 tuntap_open_tramp failed during ifconfig. The /usr/include/linux/if_tun.h has changed
1114 a lot since you installed glibc. Copy /usr/src/linux/include/if_tun.h to
1115 /usr/include/linux/if_tun.h and rebuild the UML kernel.
1117 ioctl: LOOP_SET_FD: Device or resource busy
1118 -------------------------------------------
1119 This may show up if build_rootfs bombed for some reason. It means /dev/loop0 is
1120 still mounted. umount /mnt/uml && losetup -d /dev/loop0 and re-run build_rootfs.
1121 Another possiblitity is that you /dev/loop0 device isn't a block device.
1123 make does not return when compiling with UML
1124 --------------------------------------------
1125 I had to reconfigure/compile make on the host system without optimization
1126 and these configure options:
1128 ./configure --prefix=/usr --disable-job-server
1130 I've had better luck compiling in UML with CFLAGS and CPPFLAGS unset.
1134 HOWTO: Loopback Encrypted Filesystem HOWTO (info about building a
1135 filesystem on a loopback device)
1136 HOWTO: The Linux Bootdisk HOWTO
1140 irc.openprojects.org #kernelnewbies and #uml
1144 user-mode-linux-user@lists.sourceforge.net
1146 #(@) $Id: uml.txt,v 1.1 2003/09/13 16:18:16 tushar Exp $