cvs commit: hints/ATTACHMENTS/initrd mkinitrd

tushar at linuxfromscratch.org tushar at linuxfromscratch.org
Wed Dec 3 10:36:40 PST 2003


tushar      03/12/03 11:36:40

  Modified:    ATTACHMENTS/initrd mkinitrd
  Log:
  mkinitrd updated
  
  Revision  Changes    Path
  1.2       +86 -7     hints/ATTACHMENTS/initrd/mkinitrd
  
  Index: mkinitrd
  ===================================================================
  RCS file: /home/cvsroot/hints/ATTACHMENTS/initrd/mkinitrd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- mkinitrd	30 Oct 2003 06:51:32 -0000	1.1
  +++ mkinitrd	3 Dec 2003 18:36:40 -0000	1.2
  @@ -1,7 +1,7 @@
   #!/bin/bash
   
   # mkinitrd for LFS by Jim Gifford <scripts at j555.com>
  -# Release 3.02
  +# Release 3.10
   
   # Usage Menu
   #
  @@ -10,6 +10,9 @@
   	echo "options available"
   	echo "  Required"
   	echo "	[--kernel_version={version} = use kernel version]"
  +	echo "  Root Change Method - one must be selected"
  +	echo "  [--change-root]"
  +	echo "  [--pivot-root]"
   	echo "	Optional"
   	echo "	[--ide = remove ide modules] [--scsi = remove scsi modules]"
   	echo "	[--usb = remove usb modules] [--cdrom = remove cdrom modules]"
  @@ -32,6 +35,16 @@
   while [ $# -gt 0 ]
   	do
   		case $1 in
  +		--change-root)
  +			CHANGE_ROOT="1"
  +			PIVOT_ROOT="0"
  +			echo "	Change Root Method Selected."
  +			;;
  +		--pivot-root)
  +			PIVOT_ROOT="1"
  +			CHANGE_ROOT="0"
  +			echo "	Pivot Root Method Selected."
  +			;;
   		--ide)
   			REMOVE_IDE="1"
   			echo "	Removing IDE Modules."
  @@ -92,6 +105,33 @@
   
   echo "Setting up Parameters..."
   
  +
  +# Show Root Device Information
  +#
  +ROOT_DEVICE="$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' /etc/fstab)"
  +echo "	Root Device is $ROOT_DEVICE."
  +
  +# Check for Method
  +#
  +METHOD="0"
  +
  +if [ "$PIVOT_ROOT" == "1" ] && [ "$CHANGE_ROOT" == "0" ]
  +	then
  +		METHOD="1"
  +fi
  +
  +if [ "$CHANGE_ROOT" == "1" ] && [ "$PIVOT_ROOT" == "0" ]
  +	then
  +		METHOD="1"
  +fi
  +
  +if [ "$METHOD" != "1" ]
  +	then
  +		echo "	No Root Change Method Choosen."
  +		echo "......"
  +		usage
  +fi
  +
   # Files
   #
   CONFIG_FILE="/etc/modules.conf"
  @@ -110,10 +150,6 @@
   	done
   }
   
  -# Set Root Device and File System
  -#
  -ROOT_DEVICE="$(awk '/^[ \t]*[^#]/ { if ($2 == "/") { print $1; }}' /etc/fstab)"
  -
   # Add or Remove IDE Modules
   #
   if [ "$REMOVE_IDE" == "1" ]
  @@ -229,6 +265,14 @@
   		mkdir /initrd
   fi
   		
  +# Check for Pivot Root Method Fixesx
  +#
  +if [ "$PIVOT_ROOT" == "1" ]
  +	then
  +		cd /sbin
  +		ln -sf init linuxrc
  +fi
  +
   # Check for RAM Disk Device
   #
   if [ -e /dev/.devfsd ]
  @@ -354,6 +398,14 @@
   ln -s /bin/busybox $MOUNT_IMAGE/bin/insmod
   cp -a /etc/fstab $MOUNT_IMAGE/etc/fstab
   cp -a /etc/modules.conf $MOUNT_IMAGE/etc/modules.conf
  +if [ "$PIVOT_ROOT" == "1" ]
  +	then
  +		ln -s /bin/busybox $MOUNT_IMAGE/bin/mkdir
  +		ln -s /bin/busybox $MOUNT_IMAGE/bin/mount
  +		ln -s /bin/busybox $MOUNT_IMAGE/bin/pivot_root
  +		ln -s /bin/busybox $MOUNT_IMAGE/bin/umount
  +fi
  +
   rm -f /bin/busybox
   
   # Copying Modules
  @@ -382,7 +434,7 @@
   								done
   							if [ "$REMOVE_MOD" != "1" ]
   								then
  -										cp $SEARCH $MOUNT_IMAGE/lib
  +									cp $SEARCH $MOUNT_IMAGE/lib
   									echo "$module" >> /tmp/copiedmodules
   							fi
   					fi
  @@ -414,9 +466,36 @@
   		}
   done
   
  -echo "echo \"Initial RAMDISK Loading Completed...\"" >> $LINUXRC
  +if [ "$PIVOT_ROOT" == "1" ]
  +	then
  +		echo "mkdir /new_root" >> $LINUXRC
  +		echo "echo \"Mounting proc...\"" >> $LINUXRC
  +		echo "mount -n -t proc none /proc" >> $LINUXRC
  +		echo "echo 0x0100 > /proc/sys/kernel/real-root-dev" >> $LINUXRC
  +		echo "echo \"Mounting real root dev...\"" >> $LINUXRC
  +		echo "mount -n -o ro $ROOT_DEVICE /new_root" >> $LINUXRC
  +		echo "umount /proc" >> $LINUXRC
  +		echo "cd /new_root" >> $LINUXRC
  +		echo "echo \"Running pivot_root...\"" >> $LINUXRC
  +		echo "pivot_root . initrd" >> $LINUXRC
  +		echo "if [ -c initrd/dev/.devfsd ]" >> $LINUXRC
  +		echo "	then" >> $LINUXRC
  +		echo "		echo \"Mounting devfs...\"" >> $LINUXRC
  +		echo "		mount -n -t devfs none dev" >> $LINUXRC
  +		echo "fi" >> $LINUXRC
  +		echo "if [ \$\$ = 1 ]" >> $LINUXRC
  +		echo "	then" >> $LINUXRC
  +		echo "		echo \"Running init...\"" >> $LINUXRC
  +		echo "		exec chroot . sbin/init dev/console 2>&1" >> $LINUXRC
  +		echo "	else" >> $LINUXRC
  +		echo "		echo \"Using bug circumvention for busybox...\"" >> $LINUXRC
  +		echo "		exec chroot . sbin/linuxrc dev/console 2>&1" >> $LINUXRC
  +		echo "fi" >> $LINUXRC
  +fi
   
   chmod +x $LINUXRC
  +
  +echo "echo \"Initial RAMDISK Loading Completed...\"" >> $LINUXRC
   
   # Unmount and Compress initrd
   #
  
  
  



More information about the hints mailing list