Jeremy Huntwork wrote:

As an example, look at this init:

https://github.com/jhuntwork/LightCube-OS/blob/master/packages/mkinitramfs/init.in

And the script that creates the image:

https://github.com/jhuntwork/LightCube-OS/blob/master/packages/mkinitramfs/mkinitramfs.orig

Very interesting. I took your scripts and hacked them a bit. I set it up so that if you specify the /lib/modules/version directory, it includes the kernel modules. If not, it creates initrd.img-no-kmods for a generic initrd. I removed the CD portions of the scripts.

I was able to use

menuentry "BLFS Dev (LFS-7.0-Feb14) initrd, Linux 3.0.4" {
linux /vmlinuz-3.0.4-lfs-20120214 root=UUID=54b934a9-302d-415e-ac11-4988408eb0a8 ro
   initrd /initrd.img-no-kmods
}

and it worked the first time.

One interesting thing is that the system I set up did not need the initrd. With the initrd, the kernel said it took 9.5 seconds to get to the first boot script. Without the initrd it was 4.0 seconds.

The other entry was:

menuentry "BLFS Dev (LFS-7.0-Feb14), Linux 3.0.4" {
        linux   /vmlinuz-3.0.4-lfs-20120214 root=/dev/sda8 ro
}


  -- Bruce
#!/bin/sh

PATH=/bin:/usr/bin:/sbin:/usr/sbin
export PATH

problem() 
{
   printf "Encountered a problem!\n\nDropping you to a shell.\n\n"
   sh
}

no_device()
{
   printf "The device %s, which is supposed to contain the\n" $1
   printf "root file system, does not exist.\n"
   printf "Please fix this problem and exit this shell.\n\n"
}

no_mount()
{
   printf "Could not mount device %s\n" $1
   printf "Sleeping forever. Please reboot and fix the kernel command line.\n\n"
   printf "Maybe the device is formatted with an unsupported file system?\n\n"
   printf "Or maybe filesystem type autodetection went wrong, in which case\n"
   printf "you should add the rootfstype=... parameter to the kernel command 
line.\n\n"
   printf "Available partitions:\n"
}

do_mount_root() 
{
   mkdir /.root
   [ -n "$rootflags" ] && rootflags="$rootflags,"
   rootflags="$rootflags$ro"

   case "$root" in
      /dev/* ) device=$root ;;
      UUID=* ) eval $root; device="/dev/disk/by-uuid/$UUID"  ;;
      LABEL=*) eval $root; device="/dev/disk/by-uuid/$LABEL" ;;
      ""     ) echo "No root device specified." ; problem    ;;
   esac
        
   while [ ! -b "$device" ] ; do
       no_device $device
       problem
   done
   
   if ! mount -n -t "$rootfstype" -o "$rootflags" "$device" /.root ; then
       no_mount $device
       cat /proc/partitions
       while true ; do sleep 10000 ; done
   else
       echo "Successfully mounted device $root"
   fi
}

init=/sbin/init
root=
rootdelay=
rootfstype=auto
ro="ro"
rootflags=
device=

mount -n -t devtmpfs devtmpfs /dev
mknod -m 640 /dev/console c 5 1
mknod -m 664 /dev/null    c 1 3
mount -n -t proc  proc /proc
mount -n -t sysfs sysfs /sys
mount -n -t tmpfs tmpfs /run

read -r cmdline < /proc/cmdline

for param in $cmdline ; do
   case $param in
   init=*      ) init=${param#init=}             ;;
   root=*      ) root=${param#root=}             ;;
   rootdelay=* ) rootdelay=${param#rootdelay=}   ;;
   rootfstype=*) rootfstype=${param#rootfstype=} ;;
   rootflags=* ) rootflags=${param#rootflags=}   ;;
   ro          ) ro="ro"                         ;;
   rw          ) ro="rw"                         ;;
   esac
done

udevd --daemon --resolve-names=never
udevadm trigger
udevadm settle

if [ -f /etc/mdadm.conf ] ; then mdadm -As                       ; fi
if [ -x /sbin/vgchange  ] ; then /sbin/vgchange -a y > /dev/null ; fi 
if [ -n "$rootdelay"    ] ; then sleep "$rootdelay"              ; fi

do_mount_root

killall -w /sbin/udevd

exec switch_root /.root "$init" "$@"

#!/bin/bash
# This file based in part on the mkinitrafms script for the LFS LiveCD
# written by Alexander E. Patrakov

function die 
{
   rm -rf $WDIR
   exit 1
}

copy()
{
  local file
  
  if [ "$2" == "lib" ]; then
    file=$(PATH=/lib:/usr/lib type -p $1)
  else
    file=$(type -p $1)
  fi

  if [ -n $file ] ; then
    cp $file $WDIR/$2
  else
    echo "Missing required file: $1 for directory $2"
    die
  fi
}

if [ -z $1 ] ; then
  INITRAMFS_FILE=initrd.img-no-kmods
else 
  KERNEL_VERSION=$1
  INITRAMFS_FILE=initrd.img-$KERNEL_VERSION
fi

if [ -n "$KERNEL_VERSION" ] && [ ! -d "/lib/modules/$1" ] ; then
  echo "No modules directory named $1"
  exit 1
fi

printf "Creating $INITRAMFS_FILE... "

DATADIR=/usr/share/mkinitramfs
INITIN=init.in

# Determine the main lib directory for this arch
case $(uname -m) in
    x86_64 ) DL=ld-linux-x86-64.so.2 ;;
    *      ) DL=ld-linux.so.2        ;;
esac

# Create a temporrary working directory
WDIR=`mktemp -d /tmp/initrd-work.XXXXXXXXXX`

# Create base directory structure
mkdir -p $WDIR/{bin,dev,lib/firmware,run,sbin,sys,proc}
mkdir -p $WDIR/etc/{modprobe.d,udev/rules.d}
touch $WDIR/etc/modprobe.d/modprobe.conf
ln -s lib $WDIR/lib64

# Create necessary device nodes
mknod -m 640 $WDIR/dev/console c 5 1
mknod -m 664 $WDIR/dev/null    c 1 3

# Install the udev configuration files
cp /etc/udev/udev.conf $WDIR/etc/udev/udev.conf

for file in $(find /etc/udev/rules.d/ -type f) ; do
  cp $file $WDIR/etc/udev/rules.d
done

if [ -f /etc/mdadm.conf ] ; then 
  cp /etc/mdadm.conf $WDIR/etc ; 
fi

# Install the init file
install -m0755 $DATADIR/$INITIN $WDIR/init

# Install basic binaries
for f in sh cat cp dd killall ls lsmod mdadm mkdir mknod mount \
         umount sed sleep ln rm uname
do
  copy $f bin
done

for f in udevadm udevd modprobe blkid switch_root
do
  copy $f sbin
done

# Install libraries
for library in $DL    \
 librt.so.1       \
 libpthread.so.0  \
 libblkid.so.1    \
 libc.so.6        \
 libdl.so.2       \
 libncursesw.so.5 \
 libreadline.so.6 \
 libhistory.so.6  \
 libz.so.1        \
 libuuid.so.1     \
 libblkid.so.1
do
  copy $library lib
done

cp -a /lib/udev $WDIR/lib

# Install the kernel modules if requested
if [ -n "$KERNEL_VERSION" ]; then
  find                                                                        \
     /lib/modules/$KERNEL_VERSION/kernel/{crypto,fs,lib}                      \
     /lib/modules/$KERNEL_VERSION/kernel/drivers/{block,ata,md,firewire}      \
     /lib/modules/$KERNEL_VERSION/kernel/drivers/{scsi,message,pcmcia,virtio} \
     /lib/modules/$KERNEL_VERSION/kernel/drivers/usb/{host,storage}           \
     -type f 2> /dev/null | cpio --make-directories -p --quiet $WDIR

  depmod -b $WDIR $KERNEL_VERSION
fi

( cd $WDIR ; find . | cpio -o -H newc --quiet | gzip -9 ) > $INITRAMFS_FILE

# Remove the temporary directory
rm -rf $WDIR
printf "done.\n"
-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to