剪辑内核linux,Linux01-Linux编辑内核定制属于自己的内核49
一、編譯內(nèi)核相關(guān)命令
1、重裝initrd文件命令:
mkinitrd:creates initial ramdisk p_w_picpaths for
preloading modules
格式:mkinitrd ?initrd文件路徑?內(nèi)核版本號(hào),如:mkinitrd
/boot/initrd-`uname -r`.img ?`uname -r`
2、I/O處理命令
a、命令格式說(shuō)明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%%/*}:
二、編譯系統(tǒng)內(nèi)核、grub和文件系統(tǒng)到新的磁盤(pán)
1、在原有CentOS5.9中添加一塊IDE硬盤(pán)分2個(gè)磁盤(pán)并格式化為ext3文件系統(tǒng)
2、掛載分區(qū)
mkdir /mnt/boot
mkdir /mnt/sysroot
mount /dev/hda1 /mnt/boot
moutn /dev/hda2 /mnt/sysroot
3、創(chuàng)建grub
grub-install --root-directory=/mnt
/dev/hda
4、復(fù)制系統(tǒng)內(nèi)核到/mnt/boot下cp
/boot/vmlinuz-2.6.18-348.el5 /mnt/boot/vmlinuz
5、重裝initrd文件:mkinitrd ?/boot/initrd-`uname -r`.img ?`uname -r`
6、重新編譯根文件系統(tǒng)文件
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、封裝新的根文件系統(tǒng)
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、創(chuàng)建根文件系統(tǒng)中必要的文件
cd /mnt/sysroot
mkdir -pv proc sys dev etc/rc.d lib
bin sbin boot home var/log usr/{bin,sbin} root tmp
10、復(fù)制文件系統(tǒng)的bash環(huán)境
cp /sbin/init /mnt/sysroot/sbin/
cp /bin/bash /mnt/sysroot/bin
11、復(fù)制系統(tǒng)共享庫(kù)文件
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初始化文件系統(tǒng)時(shí)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、編輯腳本用于復(fù)制二進(jìn)制程序及其依賴的庫(kù)文件的腳本可復(fù)制所有要用到的系統(tǒng)命令
#!/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、復(fù)制系統(tǒng)的網(wǎng)卡模塊
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文件加載網(wǎng)卡模塊添加
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、切入到定制的系統(tǒng)內(nèi)核進(jìn)行測(cè)試chroot /mnt/sysroot
18、***原有宿主機(jī)的第一塊磁盤(pán)保留第二塊磁盤(pán)啟動(dòng)系統(tǒng)測(cè)試效果。
總結(jié)
以上是生活随笔為你收集整理的剪辑内核linux,Linux01-Linux编辑内核定制属于自己的内核49的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: cordova 更改app版本_【ios
- 下一篇: java 16进制整数,Java将整数转