Re: Multiple profiles

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Thu Jun 27 2002 - 14:19:10 EST


On Thu, 27 Jun 2002, David Schwartz wrote:

>
> On Thu, 27 Jun 2002 14:22:07 +0200 (MET DST),
> Oliver.Neukum@lrz.uni-muenchen.de wrote:
>
> >On Thu, 27 Jun 2002, David Schwartz wrote:
> >
> >> There is no way to create multiple profiles on Linux. But there may be
> >> a way
>
> >Actually there is. We call them runlevels. init seems to be pretty
> >standard on Linux systems.
>
> True, though runlevels don't allow you to change the kernel you're
> using,
> its command line, or the initrd. In addition, many distributions' preferred
> means of creating profiles is not by means of runlevels.
>

You can boot different 'profiles' like the attached script shows. With
`initrd`, you can even query the user after initial boot, about what
'profile' you might want. It can then set up whatever you want, then
in a final heave, do `exec /sbin/init auto` and you are running the
startup files (the profile) that you specified.

Cheers,
Dick Johnson

Penguin : Linux version 2.4.18 on an i686 machine (797.90 BogoMips).

                 Windows-2000/Professional isn't.


#!/bin/bash
#
# This installs the kernel on a system that requires an initial
# RAM Disk and with an initial SCSI driver.
#

export VER=$1
RAMDISK_DEVICE=/tmp/RAM.DATA
RAMDISK_MOUNT=/tmp/Ramdisk
DISKSIZE=1800
SYS=/usr/src/linux-${VER}/arch/i386/boot/bzImage
MAP=/usr/src/linux-${VER}/System.map
if [ "$1" = "" ] ;
   then
       echo "Usage:"
       echo "make_ramdisk <version>"
       exit 1
fi
if [ ! -f ${SYS} ] ;
   then
    echo "File not found, ${SYS}"
    exit 1
fi
if [ ! -f ${MAP} ] ;
   then
    echo "File not found, ${MAP}"
    exit 1
fi
if ! depmod -a ${VER} ;
   then
      echo "This won't work! There are some unresolved symbols."
      exit 1
fi
umount /initrd 2>/dev/null
umount ${RAMDISK_DEVICE} 2>/dev/null
umount ${RAMDISK_MOUNT} 2>/dev/null
mkdir ${RAMDISK_MOUNT} 2>/dev/null
dd if=/dev/zero of=${RAMDISK_DEVICE} bs=1k count=${DISKSIZE}
mke2fs -Fq ${RAMDISK_DEVICE} ${DISKSIZE}
mount -o loop ${RAMDISK_DEVICE} ${RAMDISK_MOUNT}
rmdir ${RAMDISK_MOUNT}/lost+found
mkdir ${RAMDISK_MOUNT}/dev
mkdir ${RAMDISK_MOUNT}/etc
mkdir ${RAMDISK_MOUNT}/lib
mkdir ${RAMDISK_MOUNT}/bin
mkdir ${RAMDISK_MOUNT}/sbin
mknod ${RAMDISK_MOUNT}/dev/null c 1 3
mknod ${RAMDISK_MOUNT}/dev/ram0 b 1 0
mknod ${RAMDISK_MOUNT}/dev/ram1 b 1 1
mknod ${RAMDISK_MOUNT}/dev/sr0 b 11 0
mknod ${RAMDISK_MOUNT}/dev/scd0 b 11 0
mknod ${RAMDISK_MOUNT}/dev/tty0 c 4 0
mknod ${RAMDISK_MOUNT}/dev/tty1 c 4 1
mknod ${RAMDISK_MOUNT}/dev/tty2 c 4 2
mknod ${RAMDISK_MOUNT}/dev/tty3 c 4 3
mknod ${RAMDISK_MOUNT}/dev/tty4 c 4 4
ln -s /dev/tty0 ${RAMDISK_MOUNT}/dev/systty
ln -s /dev/tty0 ${RAMDISK_MOUNT}/dev/console
ln -s /dev/ram1 ${RAMDISK_MOUNT}/dev/ram
ln -s /dev/sr0 ${RAMDISK_MOUNT}/dev/cdrom
ln -s / ${RAMDISK_MOUNT}/dev/root
cp /bin/ash.static ${RAMDISK_MOUNT}/bin/sh
cp /sbin/insmod.static ${RAMDISK_MOUNT}/bin/insmod
cat >/tmp/fake.c << EOF
main(){return 0;}
EOF
gcc -o ${RAMDISK_MOUNT}/sbin/modprobe /tmp/fake.c --static
rm -f /tmp/fake.c
#
# Add modules to this list in the exact order you need them installed
#
modules="scsi_mod.o sd_mod.o BusLogic.o cdrom.o sr_mod.o loop.o isofs.o"
#
echo "#!/bin/sh" >${RAMDISK_MOUNT}/linuxrc
for x in $modules ; do
  cp `find /lib/modules/${VER} -name "$x"` ${RAMDISK_MOUNT}/lib
  echo "/bin/insmod /lib/$x" >>${RAMDISK_MOUNT}/linuxrc
done
chmod +x ${RAMDISK_MOUNT}/linuxrc
df ${RAMDISK_MOUNT}
sync
umount ${RAMDISK_MOUNT}
rmdir ${RAMDISK_MOUNT}
dd if=${RAMDISK_DEVICE} bs=1k count=${DISKSIZE} | gzip >/boot/initrd-${VER}
rm -f ${RAMDISK_DEVICE}
cp ${SYS} /boot/vmlinuz-${VER}
cp ${MAP} /boot/System.map-${VER}
rm -rf /boot/System.map
ln -s /boot/System.map-${VER} /boot/System.map
psupdate
#
echo >/boot/message
echo " Booting Linux version ${VER}" >>/boot/message
echo " Hit tab key to see alternatives" >>/boot/message
echo " This machine will self-destruct in 15 seconds" >>/boot/message
echo >>/boot/message
#
lilo -C - <<EOF
#
# Lilo boot-configuration script.
#
boot = /dev/sda
message = /boot/message
compact
delay = 15 # optional, for systems that boot very quickly
vga = normal # force sane state

image = /boot/vmlinuz-${VER}
  initrd = /boot/initrd-${VER}
  root = current
  label = new
  append = "nmi_watchdog=0"

image = /boot/vmlinuz-${VER}
  initrd = /boot/initrd-${VER}
  root = /dev/scd0
  label = cdrom

image = /vmlinuz
 root = current
 label = linux

image = /boot/vmlinuz-${VER}
  initrd = /boot/initrd-${VER}
  root = /dev/sdc3
  label = maint

image = /boot/vmlinuz-${VER}
  initrd = /boot/initrd-${VER}
  root = /dev/sdc1
  label = maint-su
  append="init=/bin/bash"

image = /vmlinuz.old
  root = current
  label = linux_old

other = /dev/sda1
  table = /dev/sda
  label = dos
EOF

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun Jun 30 2002 - 22:00:12 EST