l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
January 6: Social gathering
Next Installfest:
TBD
Latest News:
Nov. 18: Club officer elections
Page last updated:
2005 Dec 04 03:40

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] Problem on running initrd
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] Problem on running initrd



Hi folks,

Just join the list.

I encountered problem on running initrd burned on CD.  It consists of
following directories;
bin  dev  etc  lib  linuxrc  lost+found  mnt  proc  sbin  sys

linuxrc script;
/bin/sh
                                                                       
        
# ID is a file in root of the LFS boot CD, used to identify the CD.

ID="livecd"

TMP_MOUNT="/mnt"
                                                                       
        
PATH="/bin:/sbin:/usr/bin:/usr/sbin"
                                                                       
        
CHECK_TYPE="try_mount"
                                                                       
        
# MOUNT KERNEL FILESYSTEMS

# Create the proc directory if it does not exist

if [ ! -d "/proc/" ]; then
  mkdir /proc
fi

# Mount the proc filesystem

mount -n proc /proc -t proc

# If sysfs is listed as a valid filesystem type in /proc
# then mount it (if it doesnt then udev wont work
# and you wont have the devices you need)
                                                                       
      
if grep -q '[[:space:]]sysfs' /proc/filesystems; then
    if [ ! -d /sys/block ]; then
    mount -n sysfs /sys -t sysfs
    fi
fi
                                                                       
        
# Create some things that sysfs does not, and should not export for us.
 Feel
# free to add devices to this list.

make_extra_nodes() {
        ln -s /proc/self/fd /dev/fd
        ln -s /proc/self/fd/0 /dev/stdin
        ln -s /proc/self/fd/1 /dev/stdout
        ln -s /proc/self/fd/2 /dev/stderr
        ln -s /proc/kcore /dev/core
        mkdir /dev/pts
        mkdir /dev/shm
}
                                                                       
        
                                                                       
        
if [ ! -x /sbin/hotplug ]; then
    echo /sbin/udev > /proc/sys/kernel/hotplug
fi
                                                                       
        
# Mount a temporary file system over /dev, so that any devices
# made or removed during this boot don't affect the next one.
# The reason we don't write to mtab is because we don't ever
# want /dev to be unavailable (such as by `umount -a').
                                                                       
        
mount -n ramfs /dev -t ramfs
                                                                       
        
/sbin/udevstart
                                                                       
        
make_extra_nodes                                                       
        

# Detecting the live CD is pretty complicated, 
# but is a very logical process
                                                                       
        
# Search for cdrom devices and add them to CDROM_LIST
                                                                       
        
CDROM_LIST=""
                                                                       
        
# Search in proc tree for ide cdrom devices
# There used to be a section for devfs, but this was
# edited for udev. Actually we should probably not
# use /proc anymore, but use sysfs instead...
# Perhaps in the future;)
    
# Check for ide channels.
 
for ide_channel in /proc/ide/ide[0-9]
do

# If there are no ide channels found, then skip this

  if [ ! -d "$ide_channel" ]; then
    break
  fi

# Try each ide device to see if we can find the cd-rom drive

  for ide_device in hda hdb hdc hdd hde hdf hdg hdh hdi hdj hdk hdl hdm
hdn
  do
    device_media_file="$ide_channel/$ide_device/media"
    if [ -e "$device_media_file" ]; then
      grep -i "cdrom" $device_media_file > /dev/null 2>&1
      if [ $? -eq 0 ]; then
        CDROM_LIST="$CDROM_LIST /dev/$ide_device"
      fi
    fi
  done
done

# Check for scsi cds

for scsi_cdrom in /dev/scd[0-99]
do
  if [ -e "$scsi_cdrom" ]; then
    CDROM_LIST="$CDROM_LIST $scsi_cdrom"
  fi
done
                                                                       
        
# Now we try to find the LFS boot CD (we use ID as identification)
                                                                       
        
LFS_CDROM_DEVICE=""

for cdrom_device in $CDROM_LIST
do
  if [ "$CHECK_TYPE" = "try_mount" ]; then
    mount -n -t iso9660 ${cdrom_device} $TMP_MOUNT
    # > /dev/null 2>&1
    media_found=$?
  fi

  if [ $media_found -eq 0 ]; then
    echo -n "media found"
    if [ "$CHECK_TYPE" = "try_mount" ]; then
      [ -e "$TMP_MOUNT/$ID" ]
      media_lfs=$?
    fi
    
    if [ "$CHECK_TYPE" = "try_mount" ]; then
      umount -n $cdrom_device > /dev/null 2>&1
    fi
                                                                       
        
    if [ $media_lfs -eq 0 ]; then
      echo ", LFS boot CD found. Ready!"
      LFS_CDROM_DEVICE="$cdrom_device"
      break;
    else
      echo ", not LFS boot CD."
    fi
                                                                       
        
  else
    echo "no media "
  fi
done
                                                                       
        
# Mount LFS CD as / (root fs)
if [ "$LFS_CDROM_DEVICE" = "" ]; then
  echo "No LFS boot CD found!!!"
  exit 1
else
  echo "Booting from $LFS_CDROM_DEVICE..."
                                                    
# This is the magical part that makes a live CD live!
# The cd is mounted and pivot_root+chroot commands
# are used to start the system.
# If you really want to know what is going on here,
# You should read the chroot and pivot_root man pages

  mount -n -o ro -t iso9660 $LFS_CDROM_DEVICE $TMP_MOUNT
  cd $TMP_MOUNT
  pivot_root . mnt
  umount -n /mnt/proc >/dev/null 2>&1
  exec chroot . sh -c 'umount -n /mnt >/dev/null 2>&1; 
                exec -a init.new /sbin/init 3' <dev/console
>dev/console 2>&1

fi                            
 
******* EOF *******

Whenever after executing "pivot_root . mnt",  "chroot" can't be found. 
The script exits with following warning;
/linuxrc : line 164 : exec chroot : not found ......

The chroot command is on /bin together with pivot_root;

# ls -l /mount_point/bin/;
total 887
lrwxrwxrwx  1 root root      4 Nov 30 00:33 [ -> test
-rwxr-xr-x  1 root root 573171 Aug  5 18:57 bash
-rwxr-xr-x  1 root root  17497 Aug  5 18:57 chroot
-rwxr-xr-x  1 root root  18537 Aug  5 18:57 echo
-rwxr-xr-x  1 root root  83722 Aug  5 18:57 grep
-rwxr-xr-x  1 root root  29317 Aug  5 18:57 ln
-rwxr-xr-x  1 root root  26419 Aug  5 18:57 mkdir
-rwsr-xr-x  1 root root  64768 Aug  5 18:57 mount
-rwxr-xr-x  1 root root   3092 Aug  5 18:57 pivot_root
lrwxrwxrwx  1 root root      4 Nov 30 00:33 sh -> bash
-rwxr-xr-x  1 root root  27389 Aug  5 18:57 test
-rwsr-xr-x  1 root root  33812 Aug  5 18:57 umount[/code]

If comment out the line "pivot_root . mnt" then the script continues to
run.  Please advise how to solve this problem.  TIA


Furthermore how to test the initrd environment under operation on an
existing/running system without rebooting, with following command;

# chroot /mnt /linuxrc

together with pivot_root in such a chroot'ed initrd environment ? and
how?

B.R.
SL
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
Sunset Systems
Who graciously hosts our website & mailing lists!