fdisk /dev/sdb
mke2fs -j /dev/sdb1
mkswap /dev/sdb2
mke2fs -j /dev/sdb3
mkdir /mnt/{boot,sysroot}
mount /dev/sdb1 /mnt/boot
mount /dev/sdb3 /mnt/sysroot
grub-install --root-directory=/mnt /dev/sdb1
ls -l /mnt/boot
drwxr-xr-x 2 root root 1024 Aug 3 07:45 grub
drwx------ 2 root root 12288 Aug 3 07:42 lost+found
cp /boot/vmlinuz-2.6.18-398.el5 /mnt/boot/vmlinuz
file initrd-2.6.18-398.el5.img
initrd-2.6.18-398.el5.img: gzip compressed data, from Unix, last modified: Wed Jul 20 15:23:58 2011, max compression
cp /boot/initrd-2.6.18-398.el5.img /~/initrd-2.6.18-164.el5.img.gz
cd
gunzip initrd-2.6.18-164.el5.img.gz
zcat /boot/initrd-2.6.18-398.el5.img | cpio -id
ls
bin dev etc init lib proc sbin sys sysroot
file initrd-2.6.18-164.el5.img
initrd-2.6.18-164.el5.img: ASCII cpio archive (SVR4 with no CRC)
mkdir test
cd !$
cpio -id < initrd-2.6.18-164.el5.img
vim init
找到
mkrootdev -t ext3 -o defaults,ro /dev/vol0/root
改为
mkrootdev -t ext3 -o defaults,ro /dev/sda3
find . | cpio -H newc -o --quiet | gzip -9 > /mnt/boot/initrd.gz
mkdir -pv bin,sbin,usr/{bin,sbin},proc,sys,home,root,mnt,media,var,lib,etc,dev,boot,tmp
cp /sbin/init /mnt/sysroot/sbin/
ldd /sbin/init
linux-vdso.so.1 => (0x00007fff3adc4000)
libsepol.so.1 => /lib64/libsepol.so.1 (0x0000003f67a00000)
libselinux.so.1 => /lib64/libselinux.so.1 (0x0000003f67600000)
libc.so.6 => /lib64/libc.so.6 (0x0000003f5f800000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003f60000000)
/lib64/ld-linux-x86-64.so.2 (0x0000003f5f400000)
#!/bin/bash
#
dst=/mnt/sysroot
libcp(){
lib_path=${1%/*}
[ ! -d $dst$lib_path ] && mkdir -p $dst$lib_path
[ ! -e $dst$1 ] && cp $1 $dst$lib_path && echo "copy $1 finished."
}
bincp(){
cmd_path=${1%/*}
[ ! -d $dst$cmd_path ] && mkdir -p $dst$cmd_path
[ ! -e $dst$1 ] && cp $1 $dst$cmd_path
for lib in `ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`; do
libcp $lib
done
}
read -p "Enter the command that you want to copy: " user_cmd
until [ $user_cmd == "q" ]; do
! which $user_cmd && echo -e "\e[31;5m\tWrong Command!\e[0m" && read -p "Enter the command that you want to copy: " user_cmd && continue
cmd_real_path=`which $user_cmd | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"`
bincp $cmd_real_path
echo "Command $user_cmd copy finished."
echo -e "\e[32m##########################################################\e[0m"
read -p "Enter the command that you want to copy: " user_cmd
done
cd /mnt/sysroot/etc/
vim inittab
#在里面写入:
id:3:initdefault
si::sysinit:/etc/rc.d/rc.sysinit
- vim /etc/rc.d/
rc
.sysinit
#!/bin/bash
echo -e "===================================="
echo -e " \e[31;5mWelcome to MY Linux\3[0m"
echo -e " \e[32m`date`\e[0m"
echo -e "===================================="
insmod /lib/modules/mii.ko
insmod /lib/modules/pcnet32.ko
ifconfig eth0 192.168.8.61/16
ifconfig lo 127.0.0.1
/bin/bash
insmod /lib/modules/pcnet32.ko
chmod +x rc.sysinit
default=0
timeout=5
title My Linux
root (hd0,0)
kernel /vmlinuz ro root=/dev/sda3
initrd /initrd.gz
原文地址:http://hiyang.blog.51cto.com/10728919/1765173