Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > Misc > Problem encountered on running initrd

Forgot Password?
 Misc   Any questions or Linux discussion that does not fit in any of the other technical areas.

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 12-01-2005   #1 (permalink)
Linux Engineer
 
Join Date: Sep 2004
Posts: 1,309
Problem encountered on running initrd

Hi folks,

initrd burned on CD consists of following directories;
bin dev etc lib linuxrc lost+found mnt proc sbin sys

linuxrc script
Code:
!/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
Code:
/linuxrc : line 164 : exec chroot : not found ......
The chroot command is on /bin together with pivot_root;

# ls -l /mount_point/bin/
Code:
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
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 operated on the 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.
satimis
satimis is offline  



Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
A Newbie's Getting Started Guide to Linux
Learn the basics of the Linux operating systems. Get to know what it is all about, and familiarize yourself with the practical side. Basically, if you're a complete Linux newbie and looking for a quick and easy guide to get you started this is it.
subscribe
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
Open Source Security Myths Dispelled
Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization
subscribe
InformationWeek
InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology.
subscribe



All times are GMT. The time now is 12:06 PM.






© 2000 - - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.1