]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/mkinitrd
9bbf2680114f4a679544b446a485928071981851
[bacula/rescue] / rescue / linux / cdrom / mkinitrd
1 #!/bin/bash
2
3 # mkinitrd
4 #
5 # Written by Erik Troan <ewt@redhat.com>
6 #
7 # Contributors:
8 #       Elliot Lee <sopwith@cuc.edu>
9 #       Miguel de Icaza <miguel@nuclecu.unam.mx>
10 #       Christian 'Dr. Disk' Hechelmann <drdisk@ds9.au.s.shuttle.de>
11 #       Michael K. Johnson <johnsonm@redhat.com>
12 #       Pierre Habraken <Pierre.Habraken@ujf-grenoble.fr>
13 #       Jakub Jelinek <jakub@redhat.com>
14 #       Carlo Arenas Belon (carenas@chasqui.lared.net.pe>
15 #       Keith Owens <kaos@ocs.com.au>
16 #       Bernhard Rosenkraenzer <bero@redhat.com>
17 #       Matt Wilson <msw@redhat.com>
18 #       Trond Eivind Glomsrød <teg@redhat.com>
19 #       Jeremy Katz <katzj@redhat.com>
20 #       Preston Brown <pbrown@redhat.com>
21 #       Bill Nottingham <notting@redhat.com>
22 #       Guillaume Cottenceau <gc@mandrakesoft.com>
23
24
25 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
26 export PATH
27
28 VERSION=4.1.18
29
30 compress=1
31 allowmissing=""
32 target="cdtree/boot/isolinux/initrd.img"
33 kernel=2.6.10-1.770_FC3
34 force=""
35 verbose=""
36 MODULES=""
37 img_vers=""
38 builtins=""
39 pivot=1
40 initramfs="1"
41 modulefile=/etc/modules.conf
42 rc=0
43
44 IMAGESIZE=8000
45 PRESCSIMODS="scsi_mod sd_mod unknown"
46 fstab="/etc/fstab"
47
48 rm -f $target
49 if [ -f /etc/udev/udev.conf ]; then
50     USE_UDEV="yes"
51     UDEV_TMPFS="yes"
52     UDEV_KEEP_DEV="yes"
53     . /etc/udev/udev.conf
54     [ -x /sbin/udev.static ] || USE_UDEV=
55 fi
56
57 usage () {
58     echo "usage: `basename $0` [--version] [-v] [-f] [--preload <module>]" >&2
59     echo "       [--omit-scsi-modules] [--omit-raid-modules] [--omit-lvm-modules]" >&2
60     echo "       [--with=<module>] [--image-version] [--fstab=<fstab>] [--nocompress]" >&2
61     echo "       [--builtin=<module>] [--nopivot] <initrd-image> <kernel-version>" >&2
62     echo "" >&2
63     echo "       (ex: `basename $0` /boot/initrd-2.2.5-15.img 2.2.5-15)" >&2
64     exit 1
65 }
66
67 moduledep() {
68     if [ ! -f "/lib/modules/$kernel/modules.dep" ]; then
69         echo "No dep file found for kernel $kernel" >&2
70         exit 1
71     fi
72
73     [ -n "$verbose" ] && echo -n "Looking for deps of module $1"
74     deps=$(awk 'BEGIN { searched=ARGV[2]; ARGV[2]=""; rc=1 } \
75                 function modname(filename) { match(filename, /\/([^\/]+)\.k?o:?$/, ret); return ret[1] } \
76                 function show() { if (orig == searched) { print dep; orig=""; rc=0; exit } } \
77                 /^\/lib/ { show(); \
78                            orig=modname($1); dep=""; \
79                            if ($2) { for (i = 2; i <= NF; i++) { dep=sprintf("%s %s", dep, modname($i)); } } } \
80                 /^      / { dep=sprintf("%s %s", dep, modname($1));  } \
81                 END      { show(); exit(rc) }' /lib/modules/$kernel/modules.dep $1)
82     [ -n "$verbose" ] && echo -e "\t$deps"
83 }
84
85 findmodule() {
86     skiperrors=""
87
88     if [ $1 == "--skiperrors" ]; then
89         skiperrors=--skiperrors
90         shift
91     fi
92
93     local modName=$1
94
95     if [ "$modName" = "off" -o "$modName" = "null" ]; then
96         return
97     fi
98
99     if [ $(echo $modName | cut -b1) = "-" ]; then
100         skiperrors=--skiperrors
101         modName=$(echo $modName | cut -b2-)
102     fi
103
104     if echo $builtins | egrep -q '(^| )'$modName'( |$)' ; then
105         [ -n "$verbose" ] && echo "module $modName assumed to be built in"
106         set +x
107         return
108     fi
109
110     # special cases
111     if [ "$modName" = "i2o_block" ]; then
112         findmodule i2o_core
113         findmodule -i2o_pci
114         modName="i2o_block"
115     elif [ "$modName" = "ppa" ]; then
116         findmodule parport
117         findmodule parport_pc
118         modName="ppa"
119     elif [ "$modName" = "sbp2" ]; then
120         findmodule ieee1394
121         findmodule ohci1394
122         modName="sbp2"
123     else
124         moduledep $modName
125         for i in $deps; do
126             findmodule $i
127         done
128     fi
129
130     for modExt in o.gz o ko ; do
131         if [ -d /lib/modules/$kernel/updates ]; then
132             fmPath=`(cd /lib/modules/$kernel/updates; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
133         fi
134         
135         if [ -f /lib/modules/$kernel/updates/$fmPath ]; then
136             fmPath=updates/$fmPath
137             break
138         fi
139
140         fmPath=`(cd /lib/modules/$kernel; echo find . -name $modName.$modExt -type f | /sbin/nash --quiet) | /bin/awk {'print $1; exit;'}`
141         if [ -f /lib/modules/$kernel/$fmPath ]; then
142             break
143         fi
144     done
145
146     if [ ! -f /lib/modules/$kernel/$fmPath ]; then
147         if [ -n "$skiperrors" ]; then
148             return
149         fi
150
151         # ignore the absence of the scsi modules
152         for n in $PRESCSIMODS; do
153             if [ "$n" = "$modName" ]; then
154                 return;
155             fi
156         done;
157
158         if [ -n "$allowmissing" ]; then
159             echo "WARNING: No module $modName found for kernel $kernel, continuing anyway" >&2
160             return
161         fi
162     
163         echo "No module $modName found for kernel $kernel, aborting." >&2
164         exit 1
165     fi
166
167     # only need to add each module once
168     if ! echo $MODULES | grep -q "$fmPath" 2>/dev/null ; then
169         MODULES="$MODULES $fmPath"
170     fi
171 }
172
173 inst() {
174     if [ "$#" != "2" ];then
175         echo "usage: inst <file> <destination>"
176         return
177     fi 
178     [ -n "$verbose" ] && echo "$1 -> $2"
179     cp $1 $2
180 }
181
182 while [ $# -gt 0 ]; do
183     case $1 in
184         --fstab*)
185             if echo $1 | grep -q '=' ; then
186                 fstab=`echo $1 | sed 's/^--fstab=//'`
187             else
188                 fstab=$2
189                 shift
190             fi              
191             ;;
192
193         --with-usb)
194             withusb=yes
195             ;;
196
197         --with*)
198             if echo $1 | grep -q '=' ; then
199                 modname=`echo $1 | sed 's/^--with=//'`
200             else
201                 modname=$2
202                 shift
203             fi              
204
205             basicmodules="$basicmodules $modname"
206             ;;
207
208         --builtin*)
209             if echo $1 | grep -q '=' ; then
210                 modname=`echo $1 | sed 's/^--builtin=//'`
211             else
212                 modname=$2
213                 shift
214             fi              
215             builtins="$builtins $modname"
216             ;;
217
218         --version)
219             echo "mkinitrd: version $VERSION"
220             exit 0
221             ;;
222
223         -v)
224             verbose=-v
225             ;;
226
227         --nocompress)
228             compress=""
229             ;;
230
231         --nopivot)
232             pivot=""
233             ;;
234
235         --ifneeded)
236             # legacy
237             ;;
238
239         -f)
240             force=1
241             ;;
242         --preload*)
243             if echo $1 | grep -q '=' ; then
244                 modname=`echo $1 | sed 's/^--preload=//'`
245             else
246                 modname=$2
247                 shift
248             fi              
249             PREMODS="$PREMODS $modname"
250             ;;
251         --omit-scsi-modules)
252             PRESCSIMODS=""
253             noscsi=1;
254             ;;
255         --omit-raid-modules)
256             noraid=1;
257             ;;
258         --omit-lvm-modules)
259             nolvm=1
260             ;;
261         --image-version)
262             img_vers=yes
263             ;;
264         --noudev)
265             USE_UDEV=
266             ;;
267         --allow-missing)
268             allowmissing=yes
269             ;;
270         *)
271             if [ -z "$target" ]; then
272                 target=$1
273             elif [ -z "$kernel" ]; then
274                 kernel=$1
275             else
276                 usage
277             fi
278             ;;
279     esac
280
281     shift
282 done
283
284 if [ -z "$target" -o -z "$kernel" ]; then
285     usage
286 fi
287
288 if [ -n "$img_vers" ]; then
289     target="$target-$kernel"
290 fi
291
292 if [ -z "$force" -a -f $target ]; then
293     echo "$target already exists." >&2
294     exit 1
295 fi
296
297 if [ ! -d /lib/modules/$kernel ]; then
298     echo "/lib/modules/$kernel is not a directory." >&2
299     exit 1
300 fi
301
302 if [ $UID != 0 ]; then
303     echo "mkinitrd must be run as root"
304     exit 1
305 fi
306
307 kernelmajor=`echo $kernel | cut -d . -f 1,2`
308
309 if [ "$kernelmajor" == "2.4" ]; then
310     if [ -n "$verbose" ]; then echo "Creating old-style initrd"; fi
311     USE_UDEV=
312 else
313     if [ -n "$verbose" ]; then echo "Creating initramfs"; fi
314     modulefile=/etc/modprobe.conf
315     initramfs=1
316     pivot=""
317 fi
318
319 # if we're not using udev, don't set any of the other bits
320 [ -z "$USE_UDEV" ] && UDEV_TMPFS= && UDEV_KEEP_DEV=
321
322 # find a temporary directory which doesn't use tmpfs
323 TMPDIR=""
324 for t in /tmp /var/tmp /root ${PWD}; do
325     if [ ! -d $t ]; then continue; fi
326     if ! echo access -w $t | /sbin/nash --quiet; then continue; fi
327
328     fs=$(df -T $t 2>/dev/null | awk '{line=$1;} END {printf $2;}')
329     if [ "$fs" != "tmpfs" ]; then 
330         TMPDIR=$t
331         break
332     fi
333 done
334
335 if [ -z "$TMPDIR" ]; then
336     echo "no temporary directory could be found" >&2
337     exit 1
338 fi
339
340 if [ $TMPDIR = "/root" -o $TMPDIR = "${PWD}" ]; then 
341     echo "WARNING: using $TMPDIR for temporary files" >&2
342 fi
343
344 for n in $PREMODS; do
345         findmodule $n
346 done
347
348 needusb=""
349 if [ -n "$withusb" ]; then
350     # If / or /boot is on a USB device include the driver. With root by
351     # label we could still get some odd behaviors
352     for fs in / /boot ; do
353         esc=$(echo $fs | sed 's,/,\\/,g')
354         dev=$(mount | awk "/ on ${esc} / { print \$1 }" | sed 's/[0-9]*$//' | cut -d/ -f3)
355         if [ "$(echo $dev | cut -c1-2)" = sd ]; then
356           if [ `which kudzu 2>/dev/null` ]; then
357             host=$(kudzu --probe -b scsi |
358               gawk '/^device: '${dev}'/,/^host:/ { if (/^host/) { print $2; exit; } }')
359             if [ -d /proc/scsi/usb-storage-${host} -o -f /proc/scsi/usb-storage/${host} ]; then
360                 needusb=1
361             fi
362           fi
363         fi
364     done
365 fi
366
367 if [ -n "$needusb" ]; then
368     drivers=$(awk '/^alias[[:space:]]+usb-controller[0-9]* / { print $3}' < $modulefile)
369     if [ -n "$drivers" ]; then
370         for driver in $drivers; do
371             findmodule $driver
372         done
373         findmodule scsi_mod
374         findmodule sd_mod
375         findmodule usb-storage
376     fi
377 fi
378
379 if [ -z "$noscsi" ]; then
380     if [ ! -f $modulefile ]; then
381         modulefile=/etc/conf.modules
382     fi
383
384     if [ -f $modulefile ]; then
385         scsimodules=`grep "alias[[:space:]]\+scsi_hostadapter" $modulefile | grep -v '^[        ]*#' | LC_ALL=C sort -u | awk '{ print $3 }'`
386
387         if [ -n "$scsimodules" ]; then
388             for n in $PRESCSIMODS; do
389                 findmodule $n
390             done
391
392             for n in $scsimodules; do
393     # for now allow scsi modules to come from anywhere.  There are some
394     # RAID controllers with drivers in block/
395                 findmodule $n
396             done
397         fi
398     fi
399 fi
400
401 # If we have ide devices and module ide, do the right thing
402 ide=/proc/ide/ide*
403 if [ -n "$ide" ]; then
404     findmodule -ide-disk
405 fi
406
407 # If we use LVM, include lvm-mod
408 if [ -z "$nolvm" ]; then
409     if [ -f /proc/lvm/global  ]; then
410         if  grep -q '^VG:' /proc/lvm/global ; then
411             if [ "$kernelmajor" == "2.4" ]; then
412                 findmodule -lvm-mod
413             else
414                 findmodule -dm-mod
415             fi
416         fi
417     fi
418
419     if [ -x /sbin/dmsetup -a -e /dev/mapper/control ]; then
420         dmout=$(/sbin/dmsetup ls 2>/dev/null)
421         if [ "$dmout" != "No devices found" -a "$dmout" != "" ]; then
422             findmodule -dm-mod
423         fi
424     fi
425 fi
426
427 # If we have dasd devices, include the necessary modules (S/390)
428 if [ -d /proc/dasd ]; then
429     findmodule -dasd_mod
430     findmodule -dasd_eckd_mod
431     findmodule -dasd_fba_mod
432 fi
433
434 if [ -z "$noraid" -a -f /proc/mdstat ]; then
435     # load appropriate raid devices if necessary -- we'll load whatever
436     # /proc/mdstat suggests
437
438     # note that the awk below contains a space and a tab
439     for level in $(awk '/^md[0-9][0-9]*[        ]*:/ { print $4 }' \
440                     /proc/mdstat | sort -u); do
441         case $level in
442         linear)
443             findmodule linear
444             startraid=1
445             ;;
446         multipath)
447             findmodule multipath
448             startraid=1
449             ;;
450         raid[01456])
451             findmodule $level
452             startraid=1
453             ;;
454         *)
455             echo "raid level $level (in /proc/mdstat) not recognized" >&2
456             ;;
457         esac
458     done
459
460     if [ -n "$startraid" ]; then
461         raiddevices=$(awk '/^md[0-9][0-9]*[        ]*:/ { print $1 }' \
462                             /proc/mdstat | sort)
463     fi
464 fi
465
466 # check to see if we need to set up a loopback filesystem
467 rootdev=$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' $fstab)
468 if echo $rootdev | cut -d/ -f3 | grep -q loop ; then
469     key="^# $(echo $rootdev | cut -d/ -f3 | tr '[a-z]' '[A-Z]'):"
470     if ! grep "$key" $fstab > /dev/null; then
471         echo "The root filesystem is on a $rootdev, but there is no magic entry in $fstab" 1>&2
472         echo "for this device. Consult the mkinitrd man page for more information" 2>&2
473         exit 1
474     fi
475
476     line=$(grep "$key" $fstab)
477     loopDev=$(echo $line | awk '{print $3}')
478     loopFs=$(echo $line | awk '{print $4}')
479     loopFile=$(echo $line | awk '{print $5}')
480
481     basicmodules="$basicmodules -loop"
482     if [ "$loopFs" = "vfat" -o "$loopFs" = "msdos" ]; then
483         basicmodules="$basicmodules -fat"
484     fi
485     basicmodules="$basicmodules -${loopFs}"
486 # check if the root fs is on a logical volume
487 elif ! echo $rootdev | cut -c1-6 |grep -q "LABEL=" ; then
488     rootdev=$(echo "readlink $rootdev" | /sbin/nash --quiet)
489     major=`ls -l $rootdev | sed -e "s/.* \\([0-9]\+\\), *[0-9]\+.*/\\1/"`
490     [ "$major" != "58" ] || root_lvm=1
491     if echo $rootdev |grep -q /dev/mapper 2>/dev/null ; then root_lvm=1 ; fi
492 fi
493
494 rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $3; }}' $fstab)
495 rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' $fstab)
496
497 # in case the root filesystem is modular
498 findmodule -${rootfs}
499
500 if [ -n "$root_lvm" ]; then
501     if [ "$kernelmajor" == "2.4" ]; then    
502         findmodule -lvm-mod
503     else
504         findmodule -dm-mod
505         # DM requires all of these to be there in case someone used the
506         # feature.  broken.  (#132001)
507         findmodule -dm-mirror
508         findmodule -dm-zero
509         findmodule -dm-snapshot
510     fi
511 fi
512
513 for n in $basicmodules; do 
514     findmodule $n
515 done
516
517 if [ -n "$verbose" ]; then
518     echo "Using modules: $MODULES"
519 fi
520
521
522 MNTIMAGE=roottree
523 IMAGE=root
524 RCFILE=$MNTIMAGE/init
525
526 if [ -z "$MNTIMAGE" -o -z "$IMAGE" ]; then
527     echo "Error creating temporaries.  Try again" >&2
528     exit 1
529 fi
530
531 mkdir -p $MNTIMAGE
532 mkdir -p $MNTIMAGE/lib
533 mkdir -p $MNTIMAGE/bin
534 mkdir -p $MNTIMAGE/etc
535 mkdir -p $MNTIMAGE/dev
536 mkdir -p $MNTIMAGE/loopfs
537 mkdir -p $MNTIMAGE/proc
538 mkdir -p $MNTIMAGE/sys
539 mkdir -p $MNTIMAGE/sysroot
540 ln -s bin $MNTIMAGE/sbin
541
542 inst /sbin/nash "$MNTIMAGE/bin/nash"
543 inst /sbin/insmod.static "$MNTIMAGE/bin/insmod"
544 ln -s /sbin/nash $MNTIMAGE/sbin/modprobe
545
546 if [ -n "$USE_UDEV" ]; then
547     inst /sbin/udev.static $MNTIMAGE/sbin/udev
548     ln -s udev $MNTIMAGE/sbin/udevstart
549     mkdir -p $MNTIMAGE/etc/udev
550     inst /etc/udev/udev.conf $MNTIMAGE/etc/udev/udev.conf
551     ln -s /sbin/nash $MNTIMAGE/sbin/hotplug
552 fi
553
554 for MODULE in $MODULES; do
555     if [ -x /usr/bin/strip ]; then
556         /usr/bin/strip -g $verbose /lib/modules/$kernel/$MODULE -o $MNTIMAGE/lib/$(basename $MODULE)
557     else
558         cp $verbose -a /lib/modules/$kernel/$MODULE $MNTIMAGE/lib
559     fi
560 done
561
562 # mknod'ing the devices instead of copying them works both with and
563 # without devfs...
564 mknod $MNTIMAGE/dev/console c 5 1
565 mknod $MNTIMAGE/dev/null c 1 3
566 mknod $MNTIMAGE/dev/ram b 1 1
567 mknod $MNTIMAGE/dev/systty c 4 0
568 for i in 1 2 3 4; do
569     mknod $MNTIMAGE/dev/tty$i c 4 $i
570 done
571
572 # FIXME -- this won't work if you're using devfs
573 if [ -n "$root_lvm" -a "$kernelmajor" == "2.4" ]; then
574     pvs=$(/sbin/pvscan | grep " PV " | /bin/awk {'print $5;'} |sed 's/"//g')
575     for pv in $pvs; do
576         cp $verbose --parents -a $pv $MNTIMAGE/
577     done
578
579     inst /sbin/vgwrapper "$MNTIMAGE/bin/vgwrapper"
580     ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgscan"
581     ln "$MNTIMAGE/bin/vgwrapper" "$MNTIMAGE/bin/vgchange"
582
583     mknod $MNTIMAGE/dev/lvm b 109 0
584 fi
585
586 if [ -n "$root_lvm" -a "$kernelmajor" == "2.6" ]; then
587     inst /sbin/lvm.static "$MNTIMAGE/bin/lvm"
588     if [ -f /etc/lvm/lvm.conf ]; then
589         cp $verbose --parents /etc/lvm/lvm.conf $MNTIMAGE/
590     fi
591 fi
592
593 echo "#!/bin/nash" > $RCFILE
594 echo "" >> $RCFILE
595
596 echo "mount -t proc /proc /proc" >> $RCFILE
597 echo "setquiet" >> $RCFILE
598 echo "echo Mounted /proc filesystem" >> $RCFILE
599
600 if [ "$kernelmajor" != "2.4" ]; then
601     echo "echo Mounting sysfs" >> $RCFILE
602     echo "mount -t sysfs none /sys" >> $RCFILE
603 fi
604
605 if [ -n "$USE_UDEV" ]; then
606     if [ -n "$UDEV_TMPFS" ]; then
607         cat >> $RCFILE <<EOF
608 echo Creating /dev
609 mount -o mode=0755 -t tmpfs none /dev
610 mknod /dev/console c 5 1
611 mknod /dev/null c 1 3
612 mknod /dev/zero c 1 5
613 mkdir /dev/pts
614 mkdir /dev/shm
615 EOF
616     fi
617     cat >> $RCFILE <<EOF
618 echo Starting udev
619 /sbin/udevstart
620 echo -n "/sbin/hotplug" > /proc/sys/kernel/hotplug
621 EOF
622 fi
623
624 for MODULE in $MODULES; do
625     text=""
626     module=`echo $MODULE | sed "s|.*/||" | sed "s/.k\?o$//"`
627     fullmodule=`echo $MODULE | sed "s|.*/||"`
628
629     options=`sed -n -e "s/^options[     ][      ]*$module[      ][      ]*//p" $modulefile 2>/dev/null`
630
631     if [ -n "$verbose" ]; then
632         if [ -n "$options" ]; then
633             text=" with options $options"
634         fi
635         echo "Loading module $module$text"
636     fi
637     echo "echo \"Loading $fullmodule module\"" >> $RCFILE
638     echo "insmod /lib/$fullmodule $options" >> $RCFILE
639
640     # Hack - we need a delay after loading usb-storage to give things
641     #        time to settle down before we start looking a block devices
642     if [ "$module" = "usb-storage" ]; then
643         echo "sleep 5" >> $RCFILE
644     fi
645     if [ "$module" = "zfcp" -a -f /etc/zfcp.conf ]; then
646         echo "sleep 2" >> $RCFILE
647         cat /etc/zfcp.conf | grep -v "^#" | tr "A-Z" "a-z" | while read DEVICE SCSIID WWPN SCSILUN FCPLUN; do
648             echo "echo -n $WWPN > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/port_add" >>$RCFILE
649             echo "echo -n $FCPLUN > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/$WWPN/unit_add" >>$RCFILE
650             echo "echo -n 1 > /sys/bus/ccw/drivers/zfcp/${DEVICE/0x/}/online" >>$RCFILE
651         done
652     fi
653 done
654
655 # HACK: module loading + device creation isn't necessarily synchronous...
656 # this will make sure that we have all of our devices before trying
657 # things like RAID or LVM
658 if [ -n "$USE_UDEV" ]; then
659   echo "/sbin/udevstart" >> $RCFILE
660 fi
661
662 if [ -n "$startraid" ]; then
663     for dev in $raiddevices; do
664         cp -a /dev/${dev} $MNTIMAGE/dev
665         echo "raidautorun /dev/${dev}" >> $RCFILE
666     done
667 fi
668
669 if [ -z "$USE_UDEV" ]; then
670     echo "echo Creating block devices" >> $RCFILE
671     echo "mkdevices /dev" >> $RCFILE
672 fi
673
674 if [ -n "$loopDev" ]; then
675     mkdir /initrd
676     cp -a $loopDev $MNTIMAGE/dev
677     cp -a $rootdev $MNTIMAGE/dev
678     echo "echo Mounting device containing loopback root filesystem" >> $RCFILE
679     echo "mount -t $loopFs $loopDev /loopfs" >> $RCFILE
680     echo "echo Setting up loopback device $rootdev" >> $RCFILE
681     echo "losetup $rootdev /loopfs$loopFile" >> $RCFILE
682 elif [ -n "$root_lvm" ]; then
683   if [ "$kernelmajor" == "2.4" ]; then
684     echo "echo Scanning logical volumes" >> $RCFILE
685     echo "vgscan" >> $RCFILE
686     echo "echo Activating logical volumes" >> $RCFILE
687     echo "vgchange -ay" >> $RCFILE
688   else
689     echo "echo Making device-mapper control node" >> $RCFILE
690     echo "mkdmnod" >> $RCFILE
691     echo "echo Scanning logical volumes" >> $RCFILE
692     echo "lvm vgscan" >> $RCFILE
693     echo "echo Activating logical volumes" >> $RCFILE
694     echo "lvm vgchange -ay" >> $RCFILE
695     echo "echo Making device nodes" >> $RCFILE
696     echo "lvm vgmknodes" >> $RCFILE
697   fi
698 fi
699
700 echo "echo Creating root device" >> $RCFILE
701 echo "mkrootdev /dev/root" >> $RCFILE
702 rootdev=/dev/root
703
704 if [ "$kernelmajor" != "2.4" ]; then
705     echo "umount /sys" >> $RCFILE
706 fi
707
708 if [ -n "$initramfs" ]; then
709     echo "echo Mounting root filesystem" >> $RCFILE
710     echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
711
712     [  -n "$UDEV_KEEP_DEV" ] && echo "mount -t tmpfs --bind /dev /sysroot/dev" >> $RCFILE
713
714     echo "echo Switching to new root" >> $RCFILE
715     echo "switchroot /sysroot" >> $RCFILE
716 else 
717   if [ -n "$pivot" ]; then
718     echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $RCFILE
719
720     echo "echo Mounting root filesystem" >> $RCFILE
721     echo "mount -o $rootopts --ro -t $rootfs $rootdev /sysroot" >> $RCFILE
722
723     echo "pivot_root /sysroot /sysroot/initrd" >> $RCFILE
724     echo "umount /initrd/proc" >> $RCFILE
725   else
726     echo "umount /proc" >> $RCFILE
727   fi
728 fi
729
730 [ -n "$UDEV_TMPFS" ] && echo "umount /initrd/dev" >> $RCFILE
731 chmod +x $RCFILE
732
733   (cd $MNTIMAGE; find . | cpio --quiet -c -o) > $IMAGE || exit 1
734
735 if [ -n "$compress" ]; then
736     gzip -9 < $IMAGE > $target || rc=1
737 else
738     cp -a $IMAGE $target || rc=1
739 fi
740
741 exit $rc