Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fw-initramfs.git;a=commitdiff;h=3f7d8991055e523331410160615f2b87c0739b10

commit 3f7d8991055e523331410160615f2b87c0739b10
Author: Krisztian VASAS <i...@frugalware.org>
Date:   Sat Nov 7 17:17:13 2009 +0100

big cleanup and fixing the module copying part
- removed trailing spaces
- reworked 'if' conditions
- fixed a problem at copying modules: the script created dir twice with
the module name

diff --git a/create_initramfs.sh b/create_initramfs.sh
index 9ebb3d1..d46818f 100755
--- a/create_initramfs.sh
+++ b/create_initramfs.sh
@@ -1,58 +1,60 @@
#!/bin/sh

-#GNU General Public License Version
-#This program is free software; you can redistribute it and/or
-#modify it under the terms of the GNU General Public License
-#version 2 as published by the Free Software Foundation.
-#This program is distributed in the hope that it will be useful,
-#but WITHOUT ANY WARRANTY; without even the implied warranty of
-#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#GNU General Public License for more details.
-
-DIRTEMP=/tmp/init/
-DIRTEMPBUILD=/tmp/initbuild/
+# GNU General Public License Version
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# version 2 as published by the Free Software Foundation.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+DIRTEMP=/tmp/init
+DIRTEMPBUILD=/tmp/initbuild
KV=`uname -r`
-HOMESOURCE=/usr/share/fw-initramfs/
-LOGFILE=${DIRTEMPBUILD}log.txt
+HOMESOURCE=/usr/share/fw-initramfs
+LOGFILE=${DIRTEMPBUILD}/log.txt


. $HOMESOURCE/create_functions.sh
. $HOMESOURCE/modules.sh

###############################################################
-#Sources for build some statics binary only used for build
-#initramfs
+# Sources for build some statics binary only used for build
+# initramfs
###############################################################
REDHAT_URL="ftp://sources.redhat.com/pub/";
DM_URL="http://www.kernel.org/pub/linux/utils/raid/mdadm/";

-#TODO build it
-#busybox
+# TODO build it
+# busybox
BUSYBOX_URL="http://www.busybox.net/downloads";

-#lvm2
+# lvm2
LVM2_VERS='2.02.53'
LVM2_SOURCE="lvm2/LVM2.${LVM2_VERS}.tgz"
LVM2_ARCHIVE="LVM2.${LVM2_VERS}.tgz"
LVM2_DIR="LVM2.${LVM2_VERS}"

-#mdadm
+# mdadm
DMRAID_VERS='3.0'
DMRAID_SOURCE="mdadm-${DMRAID_VERS}.tar.bz2"
DMRAID_ARCHIVE="mdadm-${DMRAID_VERS}.tar.bz2"
DMRAID_DIR="mdadm-${DMRAID_VERS}"

##########################################################
-#Some functions for build static binary
+# Some functions for build static binary
##########################################################
-Download_Archive() {
+Download_Archive()
+{
good_msg "Download $2"
wget $1
}

-Build_Lvm2() {
-       mkdir -p $DIRTEMPBUILD
-       cd $DIRTEMPBUILD
+Build_Lvm2()
+{
+       mkdir -p ${DIRTEMPBUILD}
+       cd ${DIRTEMPBUILD}
if [ ! -f "${LVM2_ARCHIVE}" ]
then
#If don't find archive we download it
@@ -64,30 +66,31 @@ Build_Lvm2() {
then
die_msg 'LVM2 directory invalid'
fi
-       #time to build it!
+       # time to build it!
cd ${LVM2_DIR}
good_msg "Build LVM2"
unset MAKEFLAGS
./configure --enable-static_link --prefix=${DIRTEMPBUILD}/lvm >> ${LOGFILE} 
2>&1 ||
-                               die_die 'Configure of lvm failed!'
+               die_msg 'Configure of lvm failed!'
make >> ${LOGFILE} 2>&1 || die_msg 'make lvm2 failed!'
make install >> ${LOGFILE} 2>&1 || die_msg 'make install lvm2 failed!'
make device-mapper || die_msg 'make lvm2 failed!'
-       make install >> ${LOGFILE} 2>&1 || die_msg 'make install device-mapper 
failed!'
+       make install >> ${LOGFILE} 2>&1 || die_msg 'make install device-mapper 
failed!'
strip "${DIRTEMPBUILD}/lvm/sbin/lvm.static" ||
-                       die_msg 'Could not strip lvm binary!'
+               die_msg 'Could not strip lvm binary!'
strip "${DIRTEMPBUILD}/lvm/sbin/dmsetup.static" ||
-                       die_msg 'Could not strip dmsetup binary!'
+               die_msg 'Could not strip dmsetup binary!'
good_msg "Install lvm to initramfs"
-       cp ${DIRTEMPBUILD}/lvm/sbin/lvm.static $DIRTEMP/work/initramfs/bin/lvm 
||
-                       die_msg "couldn't install lvm to initramfs !"
-       cp ${DIRTEMPBUILD}/lvm/sbin/dmsetup.static 
$DIRTEMP/work/initramfs/bin/dmsetup ||
-                       die_msg "couldn't install device-mapper to initramfs !"
+       cp ${DIRTEMPBUILD}/lvm/sbin/lvm.static 
${DIRTEMP}/work/initramfs/bin/lvm ||
+               die_msg "couldn't install lvm to initramfs !"
+       cp ${DIRTEMPBUILD}/lvm/sbin/dmsetup.static 
${DIRTEMP}/work/initramfs/bin/dmsetup ||
+               die_msg "couldn't install device-mapper to initramfs !"
}

-Build_Mdadm() {
-       mkdir -p $DIRTEMPBUILD
-       cd $DIRTEMPBUILD
+Build_Mdadm()
+{
+       mkdir -p ${DIRTEMPBUILD}
+       cd ${DIRTEMPBUILD}
if [ ! -f "${DMRAID_ARCHIVE}" ]
then
#If don't find archive we download it
@@ -99,106 +102,108 @@ Build_Mdadm() {
then
die_msg 'Mdadm directory invalid'
fi
-       #time to build it!
+       # time to build it!
cd ${DMRAID_DIR}
good_msg "Build Mdadm"
export LDFLAGS="${LDFLAGS} -static"
make all mdassemble >> ${LOGFILE} 2>&1 || die_msg 'make Mdadm failed!'
make DESTDIR="${DIRTEMPBUILD}/mdadm" install >> ${LOGFILE} 2>&1 || die_msg 
'make install Mdadm failed!'
strip "${DIRTEMPBUILD}/mdadm/sbin/mdadm" ||
-                       die_msg 'Could not strip lvm binary!'
+               die_msg 'Could not strip lvm binary!'
good_msg "Install mdadm to initramfs"
-       cp ${DIRTEMPBUILD}/mdadm/sbin/mdadm $DIRTEMP/work/initramfs/sbin/mdadm 
||
-                       die_msg "couldn't install mdadm to initramfs !"
+       cp ${DIRTEMPBUILD}/mdadm/sbin/mdadm 
${DIRTEMP}/work/initramfs/sbin/mdadm ||
+               die_msg "couldn't install mdadm to initramfs !"
}

#####################################################################
-#check if root user
+# check if root user
#####################################################################
checkUser

#####################################################################
-#delete old initramfs
+# delete old initramfs
#####################################################################
-rm -rf $DIRTEMP
-rm -f $LOGFILE
+rm -rf ${DIRTEMP}
+rm -f ${LOGFILE}

#####################################################################
-#create layout
+# create layout
#####################################################################
-mkdir -p $DIRTEMP/work/initramfs/{bin,sbin,etc,proc,sys,newroot,lib,dev}
-echo "/dev/ram0     /           ext2    defaults       0 0" > 
${TEMP}/$DIRTEMP/work/initramfs/etc/fstab
-echo "proc          /proc       proc    defaults    0 0" >> 
${TEMP}/$DIRTEMP/work/initramfs/etc/fstab
+good_msg "Creating layout"
+mkdir -p ${DIRTEMP}/work/initramfs/{bin,sbin,etc,proc,sys,newroot,lib,dev}
+echo "/dev/ram0     /           ext2    defaults       0 0" > 
${TEMP}/${DIRTEMP}/work/initramfs/etc/fstab
+echo "proc          /proc       proc    defaults       0 0" >> 
${TEMP}/${DIRTEMP}/work/initramfs/etc/fstab

-cd $DIRTEMP/work/initramfs/dev
+cd ${DIRTEMP}/work/initramfs/dev
mknod -m 660 console c 5 1
mknod -m 660 null c 1 3
mknod -m 600 tty1 c 4 1
-cd $HOMESOURCE
+cd ${HOMESOURCE}

#####################################################################
-#copy init and functions
-#####################################################################
-cp init $DIRTEMP/work/initramfs/init
-chmod +x $DIRTEMP/work/initramfs/init
-cp init_functions.sh $DIRTEMP/work/initramfs/etc/init_functions.sh
-cp modules.sh $DIRTEMP/work/initramfs/etc/modules.sh
-Fsed "#!/bin/sh" "#!/bin/ash" $DIRTEMP/work/initramfs/etc/modules.sh
+# copy init and functions
+####################################################################
+good_msg "Copying init and functions"
+cp init ${DIRTEMP}/work/initramfs/init
+chmod +x ${DIRTEMP}/work/initramfs/init
+cp init_functions.sh ${DIRTEMP}/work/initramfs/etc/init_functions.sh
+cp modules.sh ${DIRTEMP}/work/initramfs/etc/modules.sh
+Fsed "#!/bin/sh" "#!/bin/ash" ${DIRTEMP}/work/initramfs/etc/modules.sh


#####################################################################
-#append busybox
+# append busybox
#####################################################################
-
+good_msg "Downloading and copying static busybox"
wget http://dors.frugalware.org/initramfs/busybox-1.15.2-2-i686.fpm
pacman-g2 -U busybox-1.15.2-2-i686.fpm --noconfirm
rm -rf busybox-1.15.2-2-i686.fpm
-cp -prf /usr/share/busybox/* $DIRTEMP/work/initramfs/
-rm $DIRTEMP/work/initramfs/linuxrc
-chmod +x $DIRTEMP/work/initramfs/bin/busybox
-cd $DIRTEMP/work/initramfs
+cp -prf /usr/share/busybox/* ${DIRTEMP}/work/initramfs/
+rm ${DIRTEMP}/work/initramfs/linuxrc
+chmod +x ${DIRTEMP}/work/initramfs/bin/busybox
+cd ${DIRTEMP}/work/initramfs
ln -sf busybox bin/sh

#####################################################################
-#append static lvm2 dm
+# append static lvm2 dm
#####################################################################
Build_Lvm2
Build_Mdadm

#####################################################################
-#append modules
+# append modules
#####################################################################

MOD_EXT=".ko"

-mkdir -p $DIRTEMP/work/initramfs/lib/modules/${KV}
-cp -pr /lib/modules/${KV}/modules.*  $DIRTEMP/work/initramfs/lib/modules/${KV}/
+mkdir -p ${DIRTEMP}/work/initramfs/lib/modules/${KV}
+cp -pr /lib/modules/${KV}/modules.*  
${DIRTEMP}/work/initramfs/lib/modules/${KV}/

-for module in $ALL_MODULES
+for module in ${ALL_MODULES}
do
ModuleFile=`find "/lib/modules/${KV}" | grep ${module}${MOD_EXT}`
if find /lib/modules/${KV} | grep /"${module}${MOD_EXT}" >/dev/null 2>&1
then
-               mkdir -p 
$DIRTEMP/work/initramfs/${ModuleFile/${module}${MOD_EXT}/}
+               mkdir -p ${DIRTEMP}/work/initramfs/`dirname ${ModuleFile}`
good_msg "Install module ${module} to initramfs"
-               cp -prv $ModuleFile $DIRTEMP/work/initramfs/$ModuleFile
+               cp -prv ${ModuleFile} ${DIRTEMP}/work/initramfs/${ModuleFile}
else
bad_msg "Don't install ${module} to initramfs"
-               Fsed "${module} " "" $HOMESOURCE/modules.sh
+               Fsed "${module} " "" ${HOMESOURCE}/modules.sh
fi
done

#####################################################################
-#create initramfs
+# create initramfs
#####################################################################
-cd $DIRTEMP/work/initramfs
+cd ${DIRTEMP}/work/initramfs
find . | cpio -H newc -o > ../initramfs.cpio
cd ..
cat initramfs.cpio | gzip > initramfs.igz


good_msg 'for use this initramfs :'
-good_msg "cp ${DIRTEMP}work/initramfs.igz /boot/initramfs.igz"
+good_msg "cp ${DIRTEMP}/work/initramfs.igz /boot/initramfs.igz"
good_msg 'edit /boot/grub/menu.lst'
good_msg 'add initrd /boot/initramfs.igz'

diff --git a/init b/init
index e5cfe83..4f7462e 100755
--- a/init
+++ b/init
@@ -24,8 +24,8 @@ mknod /dev/tty c 5 0
#lvm
if [ -e /bin/lvm ]
then
-               ln -s /bin/lvm /bin/vgscan
-               ln -s /bin/lvm /bin/vgchange
+       ln -s /bin/lvm /bin/vgscan
+       ln -s /bin/lvm /bin/vgchange
fi


@@ -34,39 +34,40 @@ init="/sbin/init"
root="/dev/hda1"

#Process command line options
-for i in $(cat /proc/cmdline); do
+for i in $(cat /proc/cmdline)
+do
case $i in
root\=*)
root=$(get_opt $i)
-                       ;;
+               ;;
init\=*)
init=$(get_opt $i)
-                       ;;
+               ;;
# Scan delay options (usb for exemple)
scandelay\=*)
SDELAY=$(get_opt $i)
-                       ;;
+               ;;
# Debug Options
debug)
DEBUG='yes'
-                       ;;
+               ;;
#for delete save suspend
real_resume\=*|resume\=*)
REAL_RESUME=$(get_opt $i)
-                       ;;
-               bootusb)
-                        BOOTUSB=1
-                       ;;
+               ;;
+               bootusb)
+                       BOOTUSB=1
+               ;;
enc_root\=*)
enc_root=$(get_opt $i)
CRYPT=1
-                       ;;
-               # /dev/md
-                lvmraid\=*)
+               ;;
+               # /dev/md
+               lvmraid\=*)
RAID_DEVICES=$(get_opt $i)
-                       
RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
-                       ;;
-               # Start Volume manager options 
+                       RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
+               ;;
+               # Start Volume manager options
dolvm)
USE_LVM_NORMAL=1
;;
@@ -96,27 +97,29 @@ cd /

startVolumes

-if [ "${BOOTUSB}" -eq '1' ] ; then
+if [ "${BOOTUSB}" -eq '1' ];
+then
#create mount dir
-       mkdir /key
-       for a in `find /dev/ -name [sh]???`
-       do
-               mount $a /key
+       mkdir /key
+       for a in `find /dev/ -name [sh]???`
+       do
+               mount $a /key
#wait the time to mount usb
-               sleep 10
+               sleep 10
#search the file FrugalMove
-               if [ -e /key/FrugalMove ]
-               then
-                       root="${a}"
-                       umount /key 2>/dev/null
-                       break
-               fi
-               umount /key 2>/dev/null
+               if [ -e /key/FrugalMove ]
+               then
+                       root="${a}"
+                       umount /key 2>/dev/null
+                       break
+               fi
+               umount /key 2>/dev/null
done
rm -R /key 2>/dev/null
-fi 
+fi

-if [ "${CRYPT}" -eq '1' ] ; then
+if [ "${CRYPT}" -eq '1' ]
+then
#Open encrypted partition to create /dev/mapper/enc-pv
cryptsetup luksOpen "${enc_root}" enc-pv
#Get LVM volumes up
@@ -132,17 +135,16 @@ echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting 
(initramfs)${NORMAL}"
mount "${root}" /newroot

#Check if $init exists and is executable
-if [[ -x "/newroot/${init}" ]] ; then
+if [[ -x "/newroot/${init}" ]]
+then
#Unmount all other mounts so that the ram used by
#the initramfs can be cleared after switch_root
umount /sys /proc
-
+
#Switch to the new root and execute init
exec switch_root /newroot "${init}"
fi

-
-
#This will only be run if the exec above failed
bad_msg 'Failed to switch_root, dropping to a shell'
exec sh
_______________________________________________
Frugalware-git mailing list
Frugalware-git@frugalware.org
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to