id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc.shutdown
EOF
touch /mnt/sysroot/etc/rc.d/rc.sysinit
cat > /mnt/sysroot/etc/rc.d/rc.sysinit << EOF
#!/bin/bash
echo -e "\t\tWelcome to \033[31;1mMyLinux\033[0m ..."
swapon -a
mount -n -o remount,rw /
mount -n -a
/bin/bash
EOF
chmod +x /mnt/sysroot/etc/rc.d/rc.sysinit
touch /mnt/sysroot/etc/fstab
cat > /mnt/sysroot/etc/fstab << EOF
/dev/sda2 / ext3 defaults 0 0
/dev/sda1 /boot ext3 defaults 0 0
/dev/sda3 swap swap defaults 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
EOF
cat > /mnt/sysroot/etc/rc.d/rc.shutdown << EOF
#!/bin/bash
#
sync
sleep 2
sync
sleep 1
umount /dev/sda1
umount /dev/sda2
exec /sbin/halt -p
EOF
chmod +x /mnt/sysroot/etc/rc.d/rc.shutdown
else
echo "error!"
fi
}
COPYCOMMAND() {
if which $B ;then
COMMAND=`which $B | grep -o "/.*"`
PTH=`which $B | grep -o "/.*" |sed "s@\(/[[:alpha:]]*\)/[[:alpha:]]*@\1@g"`
if find /mnt/sysroot$PTH &> /dev/null;then
cp $COMMAND /mnt/sysroot$PTH
else
mkdir -p /mnt/sysroot$PTH
cp $COMMAND /mnt/sysroot$PTH
fi
else
echo "wrong command"
fi
LIBS=`ldd $COMMAND | grep -o "/lib.*" | awk '{print $1}'`
for I in $LIBS;do
[ ! -e /mnt/sysroot$I ] && cp $I /mnt/sysroot$I
done
}
function KERNEL {
TMPDIR=`mktemp -d /tmp/mylinux`
cd $TMPDIR
zcat /boot/initrd-`uname -r`.img | cpio -id
sed -i 's@echo Scanning and configuring dmraid supported devices@#&@g' init
sed -i 's@echo Scanning logical volumes@#&@g' init
sed -i 's@lvm vgscan --ignorelockingfailure@#&@g' init
sed -i 's@echo Activating logical volumes@#&@g' init
sed -i 's@lvm vgchange -ay --ignorelockingfailure vol0@#&@g' init
sed -i 's@resume LABEL=SWAP-sda3@#&@g' init
sed -i "s@\(mkrootdev.* \)/.*@\1sda2@g" init
find . | cpio -H newc -o --quiet | gzip -9 > /mnt/boot/initrd.gz
cp /boot/vmlinuz-`uname -r` /mnt/boot/vmlinuz
}
function GRUB {
MOUNTPOINT=`basename $2`
until [ "$MOUNTPOINT" == "boot" ];do
read -p "please modify the mountpoint." MOUNTPOINT
done
grub-install --root-directory=/mnt $1
cat > $2/grub/grub.conf << EOF
default=0
timeout=10
title mylinux
root (hd0,0)
kernel /$3 ro root=/dev/sda2
initrd /$4
EOF
}
FRESH
MOUNT ${DISKNAME}1 ${DISKNAME}2
INIT
for B in mingetty swapoff chmod sync sleep clear runlevel reboot sysctl swapon init bash mount umount halt poweroff shutdown ls vi cat; do
COPYCOMMAND
done
#read -p "input the command,'c' for skip:" B
#until [ "$B" == "c" ];do
#COPYCOMMAND
#read -p "input the command,'c' for skip:" B
#done
KERNEL
GRUB $DISKNAME /mnt/boot vmlinuz initrd.gz
rm -rf $TMPDIR
sync
sync
sync