linux-grub,内核及模块关系,chroot,ldd
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux-grub,内核及模块关系,chroot,ldd相关的知识,希望对你有一定的参考价值。
Linux系统启动流程
PC: OS(Linux)
POST-->Bios(Boot Sequence)-->MBR(bootloader,446)-->Kernel-->initrd-->(ROOTFS)/sbin/init(/etc/inittab)
启动的服务不同:
运行级别:0-6
0:halt
1: single user mode, 直接以管理员身份切入, s,S,single
2:multi user mode, no NFS
3: multi user mode, text mode
4:reserved
5: multi user mode, graphic mode
6: reboot
详解启动过程
bootloader(MBR):只有446字节,太小
LILO: LInux LOader
GRUB: GRand Unified Bootloader (可以扩展更大内存空间)
Stage1: MBR
Stage1_5: (识别不同文件系统)
Stage2: /boot/grub/
[[email protected] ~]# ll -h /boot/grub/
total 276K
-rw-r--r--. 1 root root 63 Jun 21 2015 device.map
-rw-r--r--. 1 root root 14K Jun 21 2015 e2fs_stage1_5
-rw-r--r--. 1 root root 13K Jun 21 2015 fat_stage1_5
-rw-r--r--. 1 root root 12K Jun 21 2015 ffs_stage1_5
-rw-------. 1 root root 784 Jun 21 2015 grub.conf
-rw-------. 1 root root 789 Jun 21 2015 grub.conf.bak
-rw-r--r--. 1 root root 12K Jun 21 2015 iso9660_stage1_5
-rw-r--r--. 1 root root 13K Jun 21 2015 jfs_stage1_5
lrwxrwxrwx. 1 root root 11 Jun 21 2015 menu.lst -> ./grub.conf
-rw-r--r--. 1 root root 12K Jun 21 2015 minix_stage1_5
-rw-r--r--. 1 root root 15K Jun 21 2015 reiserfs_stage1_5
-rw-r--r--. 1 root root 1.4K May 6 2010 splash.xpm.gz 登陆背景图
-rw-r--r--. 1 root root 512 Jun 21 2015 stage1
-rw-r--r--. 1 root root 124K Jun 21 2015 stage2 大小远远大于446字节
-rw-r--r--. 1 root root 12K Jun 21 2015 ufs2_stage1_5
-rw-r--r--. 1 root root 12K Jun 21 2015 vstafs_stage1_5
-rw-r--r--. 1 root root 14K Jun 21 2015 xfs_stage1_5
[[email protected] ~]#
[[email protected] ~]# rpm -q grub (查询grub版本)
grub-0.97-93.el6.x86_64
[[email protected] ~]#
[[email protected] ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda2
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0 (默认启动第一个内核,从0开始)
timeout=5 (等待用户选择的超时时间,单位为s)
splashimage=(hd0,0)/grub/splash.xpm.gz (指定grub背景图片)
hiddenmenu (隐藏选择菜单)
title Red Hat Enterprise Linux 6 (2.6.32-504.el6.x86_64) (区别不同内核版本,名称;内核标题,或操作系统名称,字符串,可自由修改)
root (hd0,0) (内核文件所在的设备;对grub而言,所有类型硬盘一律hd,格式为(hd#,N);hd#, #表示第几个磁盘;最后的N表示对应磁盘的分区)
kernel /vmlinuz-2.6.32-504.el6.x86_64 ro root=UUID=57d85756-7680-4c7c-9125-6ad67dae2c45 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM quiet (内核文件路径,及传递给内核的参数)
initrd /initramfs-2.6.32-504.el6.x86_64.img (ramdisk文件路径)
[[email protected] ~]#
RedHat5: ramdisk-->initrd
RedHat6: ramfs-->initramfs
下载gimp,遇到在Linux中编译文件时出现:Your intltool is too old. You need intltool 0.35.0 or later
#wget http://ftp.gnome.org/pub/gnome/sources/intltool/0.40/intltool-0.40.6.tar.gz (下载地址)
#tar -zxvf intltool-0.40.6.tar.gz
#cd intltool-0.40.6
#./configure 这儿也可以指定安装目录,和man目录
#make && make install
无法安装gimp,登陆界面无法修改
内核设计风格:
RedHat, SUSE
核心:动态加载 内核模块
内核:/lib/modules/“内核版本号命令的目录”/
vmlinuz-2.6.32
/lib/modules/2.6.32/
[[email protected] 2.6.32-504.el6.x86_64]# du -sh /boot/vmlinuz-2.6.32-504.el6.x86_64
4.0M /boot/vmlinuz-2.6.32-504.el6.x86_64 (内核大小为4M)
[[email protected] 2.6.32-504.el6.x86_64]# du -sh /lib/modules/
107M /lib/modules/ (模块大小为107M,大大减少内核所在内存)
[[email protected] ~]# ll /lib/modules/ (模块所在目录)
total 4
drwxr-xr-x. 7 root root 4096 Jun 21 2015 2.6.32-504.el6.x86_64
[[email protected] ~]#
[[email protected] 2.6.32-504.el6.x86_64]# ll
total 3608
lrwxrwxrwx. 1 root root 46 Jun 21 2015 build -> ../../../usr/src/kernels/2.6.32-504.el6.x86_64
drwxr-xr-x. 2 root root 4096 Sep 15 2014 extra
drwxr-xr-x. 11 root root 4096 Jun 21 2015 kernel
-rw-r--r--. 1 root root 604652 Jun 21 2015 modules.alias
-rw-r--r--. 1 root root 579321 Jun 21 2015 modules.alias.bin
-rw-r--r--. 1 root root 1413 Sep 15 2014 modules.block
-rw-r--r--. 1 root root 69 Jun 21 2015 modules.ccwmap
-rw-r--r--. 1 root root 204307 Jun 21 2015 modules.dep (模块之间映射关系)
-rw-r--r--. 1 root root 296406 Jun 21 2015 modules.dep.bin
-rw-r--r--. 1 root root 68 Sep 15 2014 modules.drm
-rw-r--r--. 1 root root 665 Jun 21 2015 modules.ieee1394map
-rw-r--r--. 1 root root 141 Jun 21 2015 modules.inputmap
-rw-r--r--. 1 root root 1313 Jun 21 2015 modules.isapnpmap
-rw-r--r--. 1 root root 29 Sep 15 2014 modules.modesetting
-rw-r--r--. 1 root root 1974 Sep 15 2014 modules.networking
-rw-r--r--. 1 root root 74 Jun 21 2015 modules.ofmap
-rw-r--r--. 1 root root 76447 Sep 15 2014 modules.order
-rw-r--r--. 1 root root 452824 Jun 21 2015 modules.pcimap
-rw-r--r--. 1 root root 6259 Jun 21 2015 modules.seriomap
-rw-r--r--. 1 root root 165 Jun 21 2015 modules.softdep
-rw-r--r--. 1 root root 239283 Jun 21 2015 modules.symbols
-rw-r--r--. 1 root root 301921 Jun 21 2015 modules.symbols.bin
-rw-r--r--. 1 root root 852337 Jun 21 2015 modules.usbmap
lrwxrwxrwx. 1 root root 5 Jun 21 2015 source -> build
drwxr-xr-x. 2 root root 4096 Sep 15 2014 updates
drwxr-xr-x. 2 root root 4096 Jun 21 2015 vdso
drwxr-xr-x. 2 root root 4096 Sep 15 2014 weak-updates
[[email protected] 2.6.32-504.el6.x86_64]# cd kernel/
[[email protected] kernel]# ll
total 36
drwxr-xr-x. 3 root root 4096 Jun 21 2015 arch (平台)
drwxr-xr-x. 3 root root 4096 Jun 21 2015 crypto 加密
drwxr-xr-x. 63 root root 4096 Jun 21 2015 drivers 驱动
drwxr-xr-x. 30 root root 4096 Jun 21 2015 fs 文件系统
drwxr-xr-x. 3 root root 4096 Jun 21 2015 kernel 内核
drwxr-xr-x. 6 root root 4096 Jun 21 2015 lib 库
drwxr-xr-x. 2 root root 4096 Jun 21 2015 mm 内存管理
drwxr-xr-x. 28 root root 4096 Jun 21 2015 net 网络
drwxr-xr-x. 9 root root 4096 Jun 21 2015 sound 声卡
[[email protected] kernel]#
[[email protected] kernel]# ls drivers/net/ (所有类型网卡驱动,按需加载)
3c59x.ko bnx2.ko e1000 igb mlx5 ppp_async.ko r8169.ko sundance.ko via-rhine.ko
8139cp.ko bnx2x e1000e igbvf myri10ge ppp_deflate.ko s2io.ko sungem.ko via-velocity.ko
8139too.ko bonding e100.ko ipg.ko natsemi.ko ppp_generic.ko sc92031.ko sungem_phy.ko virtio_net.ko
8390.ko can enic ixgb ne2k-pci.ko ppp_mppe.ko sfc sunhme.ko vmxnet3
acenic.ko cassini.ko epic100.ko ixgbe netconsole.ko pppoe.ko sis190.ko tehuti.ko vxge
amd8111e.ko chelsio ethoc.ko ixgbevf netxen pppol2tp.ko sis900.ko tg3.ko vxlan.ko
atl1c cnic.ko fealnx.ko jme.ko niu.ko pppox.ko skge.ko tlan.ko wan
atl1e cxgb3 forcedeth.ko macvlan.ko ns83820.ko ppp_synctty.ko sky2.ko tulip wimax
atlx cxgb4 hyperv macvtap.ko pch_gbe qla3xxx.ko slhc.ko tun.ko wireless
b44.ko dl2k.ko i40e mdio.ko pcmcia qlcnic slip.ko typhoon.ko xen-netfront.ko
benet dnet.ko i40evf mii.ko pcnet32.ko qlge smsc9420.ko usb
bna dummy.ko ifb.ko mlx4 phy r6040.ko starfire.ko veth.ko
[[email protected] kernel]#
模拟根切换
chroot: chroot /PATH/TO/TEMPROOT [COMMAND...]
chroot /test/virrrot /bin/bash
[[email protected] ~]# ldd /test/myroot/bin/bash (显示二进制文件所依赖的共享库)
linux-vdso.so.1 => (0x00007fff557dd000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003ca3600000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003c98a00000)
libc.so.6 => /lib64/libc.so.6 (0x0000003c98e00000)
/lib64/ld-linux-x86-64.so.2 (0x0000003c98600000)
[[email protected] ~]# mkdir -p /test/myroot/lib64 (64位,创建/lib64)
[[email protected] ~]# cp /lib64/libtinfo.so.5 /test/myroot/lib64
[[email protected] ~]# cp /lib64/libdl.so.2 /test/myroot/lib64
[[email protected] ~]# cp /lib64/libc.so.6 /test/myroot/lib64
[[email protected] ~]# cp /lib64/ld-linux-x86-64.so.2 /test/myroot/lib64
[[email protected] ~]# ll /test/myroot/lib64
total 2200
-rwxr-xr-x. 1 root root 156936 Mar 1 19:55 ld-linux-x86-64.so.2
-rwxr-xr-x. 1 root root 1926760 Mar 1 19:55 libc.so.6
-rwxr-xr-x. 1 root root 22536 Mar 1 19:54 libdl.so.2
-rwxr-xr-x. 1 root root 138280 Mar 1 19:54 libtinfo.so.5
[[email protected]localhost ~]# ll /test/myroot/bin/
total 920
-rwxr-xr-x. 1 root root 940416 Mar 1 19:44 bash
[[email protected] ~]# ll /test/myroot/
total 12
drwxr-xr-x. 2 root root 4096 Mar 1 19:44 bin
drwxr-xr-x. 2 root root 4096 Mar 1 19:46 lib
drwxr-xr-x. 2 root root 4096 Mar 1 19:55 lib64
[[email protected] ~]# chroot /test/myroot/
bash-4.1# ll
bash: ll: command not found
bash-4.1# cd /bin/
bash-4.1# ls
bash: ls: command not found
bash-4.1#
单内核:Linux (LWP)
核心:ko(kernel object)
so()
微内核:Windows, Solaris (线程)
chroot: chroot /PATH/TO/TEMPROOT [COMMAND...]
chroot /test/virrrot /bin/bash
ldd /PATH/TO/BINARY_FILE:显示二进制文件所依赖的共享库
以上是关于linux-grub,内核及模块关系,chroot,ldd的主要内容,如果未能解决你的问题,请参考以下文章