Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mkinitrd
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
col
l33t
l33t


Joined: 08 May 2002
Posts: 817
Location: Melbourne - Australia

PostPosted: Mon Oct 07, 2002 12:34 pm    Post subject: mkinitrd Reply with quote

I found a mkinitrd script that runs on gentoo from LFS....someone want to make an ebuild of it ? maybe tweak it a little. I have tested it & it works fine... Before you run it emerge busybox....also edit the script & enter your root device.

/sbin/mkinitrd:
----->CUT

#!/bin/bash

# mkinitrd for LFS by Jim Gifford <giffordj@linkline.com>
# Release 1.5

# Variables
TEMP="$1"

KERNEL_VERSION=""
CONFIG_FILE="/etc/initrd.conf"
MODULES="`echo | cat | sed -e '/#/d' -e '/ /d' $CONFIG_FILE`"

IMAGE_SIZE=1500
MOUNT_IMAGE="/tmp/initrd.$$"
IMAGE="/tmp/initrd.img-$$"
MOUNT_POINT="/tmp/initrd.mnt-$$"
LINUXRC="$MOUNT_IMAGE/linuxrc"

# This needs to be your root. This must match what
# you have in fstab

ROOT_DEVICE="/dev/hde5"

# Check for initrd Directory

if ! [ -e /initrd ]
then
mkdir /initrd
fi

# Check for RAM Disk Device

if [ -e /dev/.devfsd ]
then
RAM_DEVICE="rd"
else
RAM_DEVICE="ram0"
fi

# Check for input

if [ "$TEMP" == "" ]
then
KERNEL_VERSION="`uname -r`"
else
KERNEL_VERSION="$TEMP"
fi

INITRD="/boot/initrd-$KERNEL_VERSION.img"

if [ "$TEMP" == "-h" ] || [ "$TEMP" == "--h" ] || [ "$TEMP" == "-help" ] || [ "$TEMP" == "--help" ]
then
echo "usage: mkinitrd kernel_version"
echo " : mkinitrd will automatically determin kernel version"
exit 1
fi

# Creating LoopBack Device

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 your loopback devices 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
}
# Creating Directories

mkdir -p $MOUNT_IMAGE
mkdir -p $MOUNT_IMAGE/lib
mkdir -p $MOUNT_IMAGE/bin
mkdir -p $MOUNT_IMAGE/etc
mkdir -p $MOUNT_IMAGE/dev
mkdir -p $MOUNT_IMAGE/proc
mkdir -p $MOUNT_IMAGE/sbin

rm -rf $MOUNT_POINT/lost+found

# Copying Static Programs

cp -a /bin/busybox $MOUNT_IMAGE/bin/busybox
ln -s /bin/busybox $MOUNT_IMAGE/bin/echo
ln -s /bin/busybox $MOUNT_IMAGE/bin/mount
ln -s /bin/busybox $MOUNT_IMAGE/bin/mkdir
ln -s /bin/busybox $MOUNT_IMAGE/bin/sh
ln -s /bin/busybox $MOUNT_IMAGE/bin/umount
ln -s /bin/busybox $MOUNT_IMAGE/sbin/insmod
ln -s /bin/busybox $MOUNT_IMAGE/sbin/pivot_root

# Copying Modules

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 $RAM_DEVICE tty[1234]
do
cp -a /dev/$i $MOUNT_IMAGE/dev
done

# Creating linuxrc File

echo "#!/bin/sh" > $LINUXRC
echo "" >> $LINUXRC

echo "/bin/echo \"Initial RAMDISK Loading Starting...\"" >> $LINUXRC

for MODULE in $MODULES
do
echo "$MODULE" | {
IFS=':' read module options
module=$module
options=$options

if [ "$options" = "" ]
then
echo "Loading module $module"
else
echo "Loading module $module with options $options"

fi

if [ "$options" = "" ]
then
echo "/sbin/insmod /lib/$module.o" >> $LINUXRC
else
echo "/sbin/insmod /lib/$module.o $options" >> $LINUXRC
fi
}
done

echo "/bin/echo \"Initial RAMDISK Loading Completed...\"" >> $LINUXRC
echo "/bin/mkdir /new_root" >> $LINUXRC
echo "/bin/echo \"Mounting proc...\"" >> $LINUXRC
echo "/bin/mount -n -t proc none /proc" >> $LINUXRC
echo "/bin/echo \"Mounting real root dev...\"" >> $LINUXRC
echo "/bin/mount -n -o ro $ROOT_DEVICE /new_root" >> $LINUXRC
echo "/bin/umount /proc" >> $LINUXRC
echo "cd /new_root" >> $LINUXRC
echo "/bin/echo \"Running pivot_root...\"" >> $LINUXRC
echo "/new_root/sbin/pivot_root . initrd" >> $LINUXRC
echo "if [ -c initrd/dev/.devfsd ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Mounting devfs...\"" >> $LINUXRC
echo " /new_root/bin/mount -n -t devfs none dev" >> $LINUXRC
echo "fi" >> $LINUXRC
echo "if [ \$\$ = 1 ]" >> $LINUXRC
echo " then" >> $LINUXRC
echo " echo \"Running init...\"" >> $LINUXRC
echo " exec /usr/sbin/chroot . sbin/init dev/console 2>&1" >> $LINUXRC
echo " else" >> $LINUXRC
echo " echo \"Using bug circumvention for busybox...\"" >> $LINUXRC
echo " exec /usr/sbin/chroot . linuxrc dev/console 2>&1" >> $LINUXRC
echo "fi" >> $LINUXRC

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 -v

<----- CUT

----->CUT
# 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


<----- CUT


Last edited by col on Thu Oct 10, 2002 3:43 am; edited 2 times in total
Back to top
View user's profile Send private message
mksoft
l33t
l33t


Joined: 28 May 2002
Posts: 844

PostPosted: Tue Oct 08, 2002 12:38 pm    Post subject: Reply with quote

An ebuild for a script :?: Seems like an overkill.
_________________
There's someone in my head but it's not me - Pink Floyd
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Thu Oct 10, 2002 2:50 am    Post subject: Reply with quote

though you have to admit, very easy LOL
Perhaps just post the script in the "tips & tricks" section.
That would probably be best.

EDIT: D'OH! I forgot which forum I was in...
maybe cut and paste it to the first post? (the script that is)
Back to top
View user's profile Send private message
col
l33t
l33t


Joined: 08 May 2002
Posts: 817
Location: Melbourne - Australia

PostPosted: Thu Oct 10, 2002 3:34 am    Post subject: Reply with quote

No I think an ebuild because it requires the busybox ebuild to be installed. I know it may be overkill but would save people a little hassle downloading the script then emerge busy box ... maybe they wont realise they need busybox when they download it ?
Back to top
View user's profile Send private message
arkane
l33t
l33t


Joined: 30 Apr 2002
Posts: 918
Location: Phoenix, AZ

PostPosted: Thu Oct 10, 2002 8:23 pm    Post subject: Reply with quote

Well, now they know... (you just said it)
The main reason I would be against an ebuild for it is that it can be quite simply copied and pasted, and people now know they need busybox.
It's simply not worth it, quite honestly. There are a dozens of scripts in "Documentation, Tips & Tricks" that do very nifty things, but to be quite honest none of them deserve an ebuild. Ebuilds are mainly for things that are either built from source, or huge binary trees of things. Basically, something that is more than one file, and a dependancy of another ebuild.

I'm not going to stop you from doing this, because quite frankly I can't. But it is a bad idea.
That is what this area is for... to fill the grey area between ebuild and nothing.
Back to top
View user's profile Send private message
cchapman
Guru
Guru


Joined: 16 Jan 2003
Posts: 440
Location: Fremont, NE

PostPosted: Fri Feb 14, 2003 7:02 pm    Post subject: Reply with quote

Stupid question here but doesnt modules.autoload do pretty much the same thing....
Back to top
View user's profile Send private message
cchapman
Guru
Guru


Joined: 16 Jan 2003
Posts: 440
Location: Fremont, NE

PostPosted: Fri Feb 14, 2003 7:04 pm    Post subject: Reply with quote

Why isnt it download with the gentoo-sources kernel
Back to top
View user's profile Send private message
col
l33t
l33t


Joined: 08 May 2002
Posts: 817
Location: Melbourne - Australia

PostPosted: Sat Feb 15, 2003 7:28 am    Post subject: Reply with quote

I have found the lvm mkinitrd script works fine. You can install it by emerging lvm-user.
Back to top
View user's profile Send private message
stefanonafets
l33t
l33t


Joined: 10 Feb 2003
Posts: 644

PostPosted: Sat Feb 15, 2003 7:42 pm    Post subject: Reply with quote

A question: I have emerged lvm-user, but when i write mkinitrd ecc ecc my pc tells me that the command mkinitrd doesn't exist...
Why???
I have tried '#/sbin/mkinitrd etc etc...' , and don't change...
Anyone?
_________________
registered Linux user number #411324
sed 's/ke/che/g'

<The Deployment Slave is initializing>
Back to top
View user's profile Send private message
col
l33t
l33t


Joined: 08 May 2002
Posts: 817
Location: Melbourne - Australia

PostPosted: Mon Feb 17, 2003 10:16 am    Post subject: Reply with quote

lvmcreate_initrd does nearly the same thing as mkinitrd but you have to mount & edit the initrd on loopback
Back to top
View user's profile Send private message
cchapman
Guru
Guru


Joined: 16 Jan 2003
Posts: 440
Location: Fremont, NE

PostPosted: Sat Feb 22, 2003 5:39 am    Post subject: Reply with quote

What has to be compiled into the kernel make initrd image. When I try it says
All loopback devices in use.

Do I need to comppile RAMDISK Support into the kernel??
Back to top
View user's profile Send private message
cchapman
Guru
Guru


Joined: 16 Jan 2003
Posts: 440
Location: Fremont, NE

PostPosted: Sat Feb 22, 2003 7:37 am    Post subject: Reply with quote

Never mind. I figured it out. Just being a dumbshit
Back to top
View user's profile Send private message
col
l33t
l33t


Joined: 08 May 2002
Posts: 817
Location: Melbourne - Australia

PostPosted: Sun Feb 23, 2003 12:10 am    Post subject: Reply with quote

as u said loopback & ramdisk.

this is how to modify the lvm initrd

- mv lvm.....img initrd.gz
- gunzip initrd.gz
- mkdir /mnt/initrd
- mount -t ext2 -o loop initrd /mnt/initrd/
- cd /mnt/initrd/
- copy your kernel modules to /mnt/initrd
- edit /mnt/initrd/linuxrc (usually insmod you modules here)
- umount /mnt/initrd
- gzip -9 initrd

then edit & update grub or lilo to use the initrd image.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum