cvs commit: hints initrd.txt

timothy at linuxfromscratch.org timothy at linuxfromscratch.org
Sun Jul 14 10:53:50 PDT 2002


timothy     02/07/14 10:53:50

  Added:       .        initrd.txt
  Log:
  Initial commit.
  
  Revision  Changes    Path
  1.1                  hints/initrd.txt
  
  Index: initrd.txt
  ===================================================================
  TITLE:          initrd for LFS
  LFS VERSION:    any
  AUTHOR:         Jim Gifford <giffordj at linkline.com>
  
  SYNOPSIS:
          How to setup initrd for LFS.
  
  HINT:
  v0.1
  
  Introduction to Initial RAMDisk
  
  This hint will help you configure an LFS system for Initial RAMDisk.
  Which will allow you to add modules at start-up instead of compiling them
  into the kernel.
  
  ---
  Assumptions Made in this document
  
  	I have made the following assumptions in this document.
  	File have been downloaded.
  
  ---
  Kernel Configuration
  
  	You will need to make sure the following items are configured
  	in your kernel. With out these, the initrd will not work.
  
  	Block Devices
  	
  	Select Loopback Device Support this can be a module
  	or built-in.
  
  	Select RAM Disk Support this needs to be compiled as 
  	built-in or the initrd will not show up.
  
  	Set Default RAM Disk size is 4096 which is the default
  
  	Select Initial RAM Disk (initrd) support needs be selected.
  
  ---
  Needed Static Modules
  
  	In order for the initrd to work properly during boot up
  	you will need to create to static programs.
  
  	The first one being bash.
  
  	bash.static
  	----
  	
  	To create a static version of bash needed for initrd use
  	the following commands.
  	
  	cd /usr/src
  	tar zxvf /usr/src/bash-2*.tar.gz
  	cd bash*
  	./configure --quiet --enable-static-link
  	make -s
  	strip bash
  	cp bash /bin/bash.static
  	rm -rf /usr/src/bash*
  
  	insmod.static
  	---
  
  	To create a static version of lsmod for initrd use the
  	following commands.
  	
  	tar jxvf /usr/src/modutils-*.tar.bz2
  	cd mod*
  	./configure --enable-insmod-static
  	make -s
  	cd insmod
  	strip insmod.static
  	cp insmod.static /sbin/insmod.static
  	rm -rf /usr/src/modutils*
  
  ---
  initrd.conf
  
  	This is the configuration file that lists the modules
  	that need to be included in the Initial RAM Disk.
  
  	Important note: The order you put the files in is
  	very important. If you do not have the modules in 
  	the correct order, your will get Unresolved Symbols.
  
  	The easiest way to see what order to load modules is
  	to look use lsmod. Look at the modules you are using
  	and see if they have an order to them.
  
  	Here is an example
  
  	scsi_mod               87064   4  [sd_mod aic7xxx]
  	
  	In this case scsi_mod is the first file to be loaded.
  	aic7xxxx is the second file to be loaded.
  	sd_mod is the third file to be loaded.
  	
  # Begin /etc/initrd.conf
  #
  # This is a file that is used to create an initrd image.
  # The only items need to be listed in this file are ones that
  # you need to boot up. IE a SCSI controller that has hard drives
  # on it.
  # 
  # If you use this to create a initial ram disk for scsi you
  # must include the following modules
  # scsi_mod sd_mod
  #
  # File format is as follows
  # module:options_for_module
  # Example
  # aic7xxx:io=0xc00
  # Example without options
  # aic7xxx:
  
  # SCSI
  scsi_mod:
  aic7xxx:
  sd_mod:
  
  # End /etc/initrd.conf
  	
  ---
  mkinitrd
  	
  	This script will create the initial RAM Disk image file.
  	By default this script creates /boot/initrd.img
  	
  #!/bin/bash
  
  # mkinitrd for LFS by Jim Gifford <giffordj at linkline.com>
  # Release 0.1
  
  # Variables
  TEMP="$1"
  
  KERNEL_VERSION=""
  CONFIG_FILE="/etc/initrd.conf"
  MODULES="`echo | cat | sed -e '/#/d' -e '/ /d' $CONFIG_FILE`"
  INITRD="/boot/initrd.img"
  
  IMAGE_SIZE=2000
  MOUNT_IMAGE="/tmp/initrd.$$"
  IMAGE="/tmp/initrd.img-$$"
  MOUNT_POINT="/tmp/initrd.mnt-$$"
  LINUXRC="$MOUNT_IMAGE/linuxrc"
  
  # Check for input
  
  if [ "$TEMP" == "" ]
  	then
  		KERNEL_VERSION="`uname -r`"
  	else 
  		KERNEL_VERSION="$TEMP"
  fi
  
  if [ "$TEMP" == "-h" ] || [ "$TEMP" == "--h" ] || [ "$TEMP" == "-help" ] || [ "$TEMP" == "--help" ]
  	then
  		echo "usage: mkinitrd kernel_version"
  		exit 1
  fi
  
  # Start Creation on Image
  
  dd if=/dev/zero of=$IMAGE bs=1k count=$IMAGE_SIZE 2> /dev/null
  
  for device_number in 0 1 2 3 4 5 6 7 8
  	do
  		if losetup /dev/loop$device_number $IMAGE 2>/dev/null
  			then
  				break
  		fi
  done
  
  if [ "$device_number" = "8" ]
  	then
  		rm -rf $MOUNT_POINT $IMAGE
  		echo "All of you loopback dvice are in use!" >&2
  		exit 1
  fi
  
  LOOP_DEVICE=/dev/loop$device_number
  
  echo y | mke2fs $LOOP_DEVICE $IMAGE_SIZE > /dev/null 2> /dev/null
  
  echo "Using loopback device $LOOP_DEVICE"
  
  mkdir -p $MOUNT_POINT
  mount -t ext2 $LOOP_DEVICE $MOUNT_POINT || {
  					     echo "Can't get a loopback device"
  					     exit 1
  					   }
  mkdir -p $MOUNT_IMAGE
  mkdir -p $MOUNT_IMAGE/lib
  mkdir -p $MOUNT_IMAGE/bin
  mkdir -p $MOUNT_IMAGE/etc
  mkdir -p $MOUNT_IMAGE/dev
  
  rm -rf $MOUNT_POINT/lost+found
  
  # Copying Static Shell and Insmod
  
  cp -a /bin/bash.static $MOUNT_IMAGE/bin/sh
  cp -a /sbin/insmod.static $MOUNT_IMAGE/bin/insmod
  
  for MODULE in $MODULES
  	do
  		echo "$MODULE" | {
  		IFS=':' read module options
  		module=$module
  		options=$options
  		DIR_SEARCH1="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers`"
  		for DIR_1SEARCH in $DIR_SEARCH1
  		do
  			cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
  			DIR_SEARCH2="`ls -1 /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH`"
  			for DIR_2SEARCH in $DIR_SEARCH2
  				do
  					cp /lib/modules/$KERNEL_VERSION/kernel/drivers/$DIR_1SEARCH/$DIR_2SEARCH/$module.o $MOUNT_IMAGE/lib > /dev/null 2>&1
  				done
  		done
  			           }
  	done
  
  for i in console null tty[1234]
  	do
  		cp -a /dev/$i $MOUNT_IMAGE/dev
  done
  
  # Creating linuxrc File
  
  echo "#!/bin/sh" > $LINUXRC
  echo "" >> $LINUXRC
  					
  for MODULE in $MODULES
  	do
  		echo "$MODULE" | {
  		IFS=':' read module options
  		module=$module
  		options=$options
  
  		if [ "$options" = "" ]
  			then
  				echo "Loading module $module"
  				echo "echo \"Loading $module\"" >> $LINUXRC
  			else
  				echo "Loading module $module with options $options"
  				echo "echo \"Loading $module with options $options\"" >> $LINUXRC
  
  		fi
  
  		if [ "$options" = "" ]
  			then
  				echo "insmod /lib/$module.o" >> $LINUXRC
  			else
  				echo "insmod /lib/$module.o $options" >> $LINUXRC
  		fi
  		                  }
  done
  
  chmod +x $LINUXRC
  
  (cd $MOUNT_IMAGE; tar cf - .) | (cd $MOUNT_POINT; tar xf -)
  
  umount $MOUNT_POINT
  losetup -d $LOOP_DEVICE
  
  gzip -9 < $IMAGE > $INITRD
  # rm -rf $MOUNT_IMAGE $MOUNT_POINT $IMAGE
  
  ---
  lilo.conf
  
  	In order to use the initrd.img file is to add the
  	following entry to you lilo.conf file
  
  	initrd=/boot/initrd.img
  
  	So you lilo.conf should look something like this.
  
  	image=/boot/vmlinuz-2.4.18
  	label=test
  	initrd=/boot/initrd.img
  	read-only
  	root=/dev/discs/disc0/part2
  
  	If you are just testing. You should make a separate
  	entry in lilo.conf. This will still allow you to boot.	
  
  Mail suggestions to giffordj at linkline.com
  
  New Version of this document can be viewed from
  http://www.jg555.com/cvs
  
  
  
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe hints' in the subject header of the message



More information about the hints mailing list