The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/tools/mkboot

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 #!/bin/sh
    2 #
    3 #       mkboot 2.0 - make boot floppy, make root device bootable, etc.
    4 #                                                       Author: Kees J. Bot
    5 
    6 trap 'e=$?; rm -f /tmp/mkb.$$; exit $e' 0 2
    7 
    8 mdec=/usr/mdec  # bootstraps
    9 
   10 # Check arguments.
   11 case "$#:$1" in
   12 1:bootable | 1:hdboot | [12]:fdboot | 1:cdfdboot )
   13         action=$1 dev=$2
   14         ;;
   15 *)      echo "Usage: $0 [bootable | hdboot | cdfdboot | fdboot [device]]" >&2
   16         exit 1
   17 esac
   18 
   19 # Get the device table.
   20 . /etc/fstab
   21 
   22 # The real root device may be the RAM disk.
   23 realroot=`printroot -r`
   24 
   25 # If it's an initial fstab, pretend root is real root
   26 if [ $root = "/dev/ROOT" ]
   27 then    root=$realroot
   28 fi
   29 
   30 case $action in
   31 bootable | hdboot)
   32         # We need the root device.
   33 
   34         if [ $realroot = $root ]
   35         then
   36                 rootdir=
   37         else
   38                 umount $root 2>/dev/null
   39                 mount $root /mnt || exit
   40                 rootdir=/mnt
   41         fi
   42 esac
   43 
   44 case $action in
   45 bootable)
   46         # Install the boot monitor on the root device and make it bootable.
   47         install -cs -m 644 $mdec/boot $rootdir/boot/boot || exit
   48         sync
   49         installboot -device $root $mdec/bootblock /boot/boot || exit
   50         test $realroot != $root && umount $root
   51         ;;
   52 hdboot)
   53         # Install a new image on the root device.
   54         if [ ! -d $rootdir/boot/image ]
   55         then
   56                  /boot/image is not yet a directory!  Fix it.
   57                 su root -c \
   58                     "exec mv $rootdir/boot/image /M"
   59                 install -d $rootdir/boot/image
   60                 su root -c \
   61                     "exec mv $rootdir/M $rootdir/boot/image/`uname -r`.`uname -v`"
   62         fi
   63 
   64         sh tell_config OS_RELEASE . OS_VERSION >/tmp/mkb.$$
   65         version=`sed 's/["      ]//g;/^$/d' </tmp/mkb.$$`
   66 
   67         revision=`cat revision 2>/dev/null`
   68         oldrev=$revision
   69         target="${version}r${revision}"
   70 
   71         if [ -z "$revision" ]
   72         then
   73                 revision=0
   74         elif [ -f $rootdir/boot/image/$target ]
   75         then
   76                 if [ $rootdir/boot/image/$target -newer image ]
   77                 then
   78                         echo "$root:/boot/image/$target is up to date"
   79                         test $realroot != $root && umount $root
   80                         exit 0
   81                 fi
   82                 revision=`expr $revision + 1`
   83         fi
   84         target="${version}r${revision}"
   85 
   86         set -- `ls -t $rootdir/boot/image`
   87 
   88         case $# in
   89         0|1|2|3)
   90                 # Not much there, do not remove a thing.
   91                 ;;
   92         *)
   93                 # Remove the third-newest image in /boot/image, but
   94                 # only if there's an older one (which is kept). 
   95                 echo "rm $root:/boot/image/$3"
   96                 rm -f "$rootdir/boot/image/$3"
   97         esac
   98 
   99         # Install the new image.
  100         echo "install image $root:/boot/image/$target"
  101         install -o root -m 600 image $rootdir/boot/image/$target || exit
  102 
  103         # Save the revision number.
  104         test "$revision" != "$oldrev" && echo $revision >revision
  105 
  106         test $realroot != $root && umount $root
  107         echo "Done."
  108         ;;
  109 fdboot)
  110         # fdboot: Make a boot floppy.
  111 
  112         if [ -z "$dev" ]
  113         then
  114                 echo -n \
  115 "Finish the name of the floppy device to write (by default 'fd0'): /dev/";
  116                 read dev
  117                 case "$dev" in
  118                 '')     dev=/dev/fd0
  119                         ;;
  120                 /dev/*)
  121                         ;;
  122                 *)      dev=/dev/$dev
  123                 esac
  124         fi
  125 
  126         # Make a file system.
  127         umount $dev 2>/dev/null
  128         if mkfs -B 1024 -i 512 $dev
  129         then    :
  130         else
  131                 echo "mkfs of $dev failed."
  132                 exit 1;
  133         fi
  134 
  135         # Install /dev, /boot/boot and /boot/image.
  136         mount $dev /mnt || exit
  137         mkdir -p /mnt/boot/image || exit
  138         cpdir /dev /mnt/dev || exit
  139         cp -p $mdec/boot /mnt/boot/boot || exit
  140         cp -p image /mnt/boot/image/ || exit
  141         umount $dev || exit
  142 
  143         # Make bootable and copy the boot parameters.
  144         installboot -d $dev $mdec/bootblock /boot/boot || exit
  145         pfile=fdbootparams
  146         if [ -f $pfile ]
  147         then    echo "Using floppy boot parameters from file $pfile."
  148                 edparams $dev "`cat $pfile`" || exit
  149         else    echo "Copying floppy boot parameters from $root."
  150                 dd if=$root of=$dev skip=1 seek=1 count=1 conv=silent || exit
  151         fi
  152         edparams $dev 'main(){delay 2000;boot}; save' || exit
  153         echo "Test kernel installed on $dev"
  154         ;;
  155 
  156 cdfdboot)
  157         # cdfdboot: Make a boot floppy image to go on a CD for booting from.
  158         dev=/dev/ram
  159         umount $dev 2>/dev/null
  160         if mkfs -B 1024 -b 1440 -i 512 $dev || exit 1
  161         then :
  162         else
  163                 echo "mkfs of $dev failed."
  164                 exit 1;
  165         fi
  166 
  167         # Install /dev, /boot
  168         mount $dev /mnt || exit 1
  169         mkdir /mnt/dev
  170         mkdir /mnt/boot
  171         mkdir /mnt/boot/image
  172         ( cd /mnt/dev && /usr/src/commands/scripts/MAKEDEV.sh std )
  173         cp -p image image_* /mnt/boot/image || exit 1
  174         cp -p ../boot/boot /mnt/boot/boot || exit 1
  175         umount $dev || exit 1
  176         installboot -d $dev ../boot/bootblock boot/boot || exit 1
  177         edparams $dev 'unset bootopts; unset servers; disable=inet; image=/boot/image/image_big; bootbig(1, Regular MINIX 3 (requires at least 16 MB RAM)) { image=/boot/image/image ; boot } bootsmall(2, Small MINIX 3 (intended for 8 MB systems)) { image=/boot/image/image_small ; boot } cdproberoot=1; unset rootdev; unset leader; leader() { echo \n--- Welcome to MINIX 3. This is the boot monitor. ---\n\nChoose an option from the menu or press ESC if you need to do anything special.\nOtherwise I will boot with my defaults in 10 seconds.\n\n }; bootcd=1; main(){trap 10000 boot; menu; }; save' || exit
  178 
  179         # copy image
  180         dd if=$dev of=cdfdimage bs=8192 count=180
  181 esac
  182 sync
  183 exit 0

Cache object: 5217f9e141a6c2b3522a36bda6b909d5


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.