Linux01-Linux编辑内核定制属于自己的内核49
一、編譯內核相關命令
1、重裝initrd文件命令:
mkinitrd:creates initial ramdisk p_w_picpaths for preloading modules
格式:mkinitrd ?initrd文件路徑?內核版本號,如:mkinitrd ?/boot/initrd-`uname -r`.img ?`uname -r`
2、I/O處理命令
????????a、命令格式說明2
${parameter#*word}
${parameter##*word}
? ? ? ? ? ? ? The word is expanded to produce a pattern just as in pathname expansion. ?If the pattern matches the beginning of the value of
? ? ? ? ? ? ? parameter, then the result of the expansion is the expanded value of parameter with the shortest matching pattern ?(the ??..?.
? ? ? ? ? ? ? case) ?or ?the ?longest ?matching pattern (the ?..#?..case) deleted. ?If parameter is @ or *, the pattern removal operation is
? ? ? ? ? ? ? applied to each positional parameter in turn, and the expansion is the resultant list. ?If parameter is an array variable sub-
? ? ? ? ? ? ? scripted ?with ?@ or *, the pattern removal operation is applied to each member of the array in turn, and the expansion is the
? ? ? ? ? ? ? resultant list.
?
${parameter%word*}
${parameter%%word*}
? ? ? ? ? ? ? The word is expanded to produce a pattern just as in pathname expansion. ?If the pattern matches a ?trailing ?portion ?of ?the
? ? ? ? ? ? ? expanded ?value ?of ?parameter, then the result of the expansion is the expanded value of parameter with the shortest matching
? ? ? ? ? ? ? pattern (the ?..?..case) or the longest matching pattern (the ?..%?..case) deleted. ?If parameter ?is ?@ ?or ?*, ?the ?pattern
? ? ? ? ? ? ? removal ?operation ?is applied to each positional parameter in turn, and the expansion is the resultant list. ?If parameter is
? ? ? ? ? ? ? an array variable subscripted with @ or *, the pattern removal operation is applied to each member of the array in ?turn, ?and
? ? ? ? ? ? ? the expansion is the resultant list.
????????b、命令格式
????????????# FILE=/usr/local/src
????????????# echo ${FILE#*/}: usr/local/src
????????????#?echo ${FILE##*/}: src
????????????#?${FILE%/*}: /usr/local
????????????#?${FILE%%/*}:
二、編譯系統內核、grub和文件系統到新的磁盤
1、在原有CentOS5.9中添加一塊IDE硬盤分2個磁盤并格式化為ext3文件系統
2、掛載分區
mkdir /mnt/boot
mkdir /mnt/sysroot
mount /dev/hda1 /mnt/boot
moutn /dev/hda2 /mnt/sysroot
3、創建grub
grub-install --root-directory=/mnt /dev/hda
4、復制系統內核到/mnt/boot下cp /boot/vmlinuz-2.6.18-348.el5 /mnt/boot/vmlinuz
5、重裝initrd文件:mkinitrd ?/boot/initrd-`uname -r`.img ?`uname -r`
6、重新編譯根文件系統文件
cp /boot/initrd-2.6.18-348.el5.img /root
mv initrd-2.6.18-348.el5.img initrd-2.6.18-348.el5.img.gz
gzip -d initrd-2.6.18-348.el5.img.gz?
mkdir test
cd test
cpio -id < ../initrd-2.6.18-348.el5.img或zcat /boot/initrd-2.6.18-348.el5.img | cpio -id
vim init(修改其中一行為mkrootdev -t ext3 -o defaults,ro /dev/hda2注釋掉#resume LABEL=SWAP-sda5)
7、封裝新的根文件系統
find . | cpio -H newc --quiet -o | gzip -9 > /mnt/boot/initrd.gz
8、編輯新的grub文件vim /mnt/boot/grub/grub.conf
default=0
timeout=5
title Test Linux (Magedu Team)
root (hd0,0)
kernel /vmlinuz
initrd /initrd.gz
9、創建根文件系統中必要的文件
cd /mnt/sysroot
mkdir -pv proc sys dev etc/rc.d lib bin sbin boot home var/log usr/{bin,sbin} root tmp
10、復制文件系統的bash環境
cp /sbin/init /mnt/sysroot/sbin/
cp /bin/bash /mnt/sysroot/bin
11、復制系統共享庫文件
ldd /sbin/init
cp /lib/libsepol.so.1 /mnt/sysroot/lib
cp /lib/libselinux.so.1 /mnt/sysroot/lib
cp /lib/libc.so.6 /mnt/sysroot/lib
cp /lib/libdl.so.2 /mnt/sysroot/lib
ldd /bin/bash
cp /lib/libtermcap.so.2 /mnt/sysroot/lib
12、編輯inittab為linux初始化文件系統時init初始化程序用到的配置文件
vim /mnt/sysroot/etc/inittab
id:3:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
chmod +x /mnt/sysroot/etc/inittab
13、編輯vim /mnt/sysroot/etc/rc.d/rc.sysinit
#!/bin/bash
#
echo -e "\tWelcome to \033[31mMageEdu Team\033[0m Linux."
/bin/bash
chmod +x /mnt/sysroot/etc/rc.d/rc.sysinit
14、編輯腳本用于復制二進制程序及其依賴的庫文件的腳本可復制所有要用到的系統命令
#!/bin/bash
#
DEST=/mnt/sysroot
libcp() {
? LIBPATH=${1%/*}
? [ ! -d $DEST$LIBPATH ] && mkdir -p $DEST$LIBPATH
? [ ! -e $DEST${1} ] && cp $1 $DEST$LIBPATH && echo "copy lib $1 finished."
}
?
bincp() {
? CMDPATH=${1%/*}
? [ ! -d $DEST$CMDPATH ] && mkdir -p $DEST$CMDPATH
? [ ! -e $DEST${1} ] && cp $1 $DEST$CMDPATH
?
? for LIB in ?`ldd $1 | grep -o "/.*lib\(64\)\{0,1\}/[^[:space:]]\{1,\}"`; do
? ? libcp $LIB
? done
}
?
read -p "Your command: " CMD
until [ $CMD == 'q' ]; do
? ?! which $CMD &> /dev/null && echo "Wrong command" && read -p "Input again:" CMD && continue
? COMMAND=` which $CMD | grep -v "^alias" | grep -o "[^[:space:]]\{1,\}"`
? bincp $COMMAND
? echo "copy $COMMAND finished."
? read -p "Continue: " CMD
done
15、復制系統的網卡模塊
mkdir /mnt/sysroot/lib/modules
cp /lib/modules/2.6.18-348.el5/kernel/drivers/net/mii.ko /mnt/sysroot/lib/modules
cp /lib/modules/2.6.18-348.el5/kernel/drivers/net/pcnet32.ko /mnt/sysroot/lib/modules
16、編輯/mnt/sysroot/etc/inittab文件加載網卡模塊添加
insmod /lib/modules/mii.ko
insmod /lib/modules/pcnet32.ko
ifconfig eth0 172.16.100.13/16
ifconfig lo 127.0.0.1/8
/bin/bash
17、切入到定制的系統內核進行測試chroot /mnt/sysroot
18、***原有宿主機的第一塊磁盤保留第二塊磁盤啟動系統測試效果。
轉載于:https://blog.51cto.com/zkhylt/1417785
總結
以上是生活随笔為你收集整理的Linux01-Linux编辑内核定制属于自己的内核49的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: HDU 4831 Scenic Popu
- 下一篇: apply() filter()