amy_888 发表于 2015-4-4 22:12:30

Deploy Linux Kernel on CRUX using VMware

    本文旨在提供一个简易的内核编译实现方法,在对应设置下能够成功运行。
    软件环境:VMware 7.1;CRUX-2.6,内核版本2.6.30,官方主页 http://crux.nu/Main/HomePage
  
    1. 在VMware中新建一个虚拟机,光驱放入CRUX的IOS镜像,系统类型选择Other Linux 2.6.x kernel,网络连接选用host-only,硬盘驱动器选择IDE,其他默认。创建后启动虚拟机,按回车进入系统,输入root登录;
    2. 对磁盘分区,本文将+512M划分为swap分区hda1,剩余分给ext3格式分区hda2,



fdisk /dev/hda
#add a new partition
n: p-> 1-> enter-> +512M
#change partition id
t: 82
#add a new partition
n: p-> 2-> enter-> enter
#toggle a bootable flag
a: 2
#print
p
#write to disk
w
    3. 创建并挂载文件系统,创建并激活交换分区;



mkfs.ext3 /dev/hda2
mount /dev/hda2 /mnt
mkswap /dev/hda1
swapon /dev/hda1
    4. 启动CRUX安装,在选择安装包时注意除了core外还要勾选opt包,其他选项默认;



setup

    5. 之所以经常使用mount挂载文件是为了把“定制系统”根目录的基本结构在/mnt上架设好,这里还要补充下面几步,



mount --bind /dev /mnt/dev
mount --bind /tmp /mnt/tmp
mount -t proc proc /mnt/proc
mount -t sysfs none /mnt/sys
    最后把bash执行根目录挂在/mnt上,就可以让“定制系统”目录结构在现有bash上生效。



chroot /mnt /bin/bash
    以上5条语句可以用一条代替;



setup-chroot
    6. 修改文件系统表,添加/dev/hda1和/dev/hda2两条记录;



vi /etc/fstab


/dev/hda2    /      ext3    defaults   1   1
/dev/hda1   swap    swap    defaults   0   0
    7. 配置和编译内核,这是最为重要的部分,很多问题都是出自此处。作者遇到的问题是硬盘驱动配置不正确导致无法启动:

  kernel panic-not syncing: VFS: unable to mount root fs on unknown block(0,0)

    为了解决上述问题,作者采用了[点点滴滴]博客的观点和做法,在配置内核模块前,先将配置文件换回默认。这样可以避免驱动冲突。



cd /usr/src/linux-2.6.30.5                                 
make defconfig
make menuconfig
    启动内核配置界面,需要勾选下述项(注意*代表要编进内核中):
    Device Drivers --->
       ATA/ATAPI/MFM/RLL support --->
         generic/default IDE chipset support
         Intel PIIX/ICH chipsets support    // 此项与硬盘型号有关,可用 lspci | grep IDE 命令查询
      
[*] Network device support --->
        
[*] Ethernet (10 or 100Mbit) --->
           AMD PCnet32 PCI SUPPORT    // 网卡驱动



make
make modules_install
    为了提高编译速度,make一般可以加入参数,即



make -jn > /dev/null
    n即同时执行的作业数,一般1个处理器对应1~2个作业,比如我的CPU是i3,n可以选8,>/dev/null是扔掉标准输出流信息;
    编译完内核后,将镜像拷贝到/boot并更新系统符号表;



cp arch/i386/boot/bzImage /boot/vmlinuz
cp System.map /boot
    8. 配置grub,修改menu.lst,将无用的title/kernel行注释掉。



cp /usr/share/grub/i386-pc/* /boot/grub/
cd /boot/grub
cp menu.lst.sample menu.lst
vi menu.lst
    修改和添加以下内容:



splashimage (hd0,1)/boot/grub/crux03.xpm.gz#修改(hd0,0)为(hd0,1)
...
title GRUX
kernel (hd0,1)/boot/vmlinuz root=/dev/hda2
    在终端输入grub,启动grub程序设置引导扇区;



grub> root (hd0,1)
grub> setup (hd0)
grub> quit
    9. 重新启动



sync;sync
shutdown -r now
    10. 加入内核模块
    如果完成内核编译安装后,还需要加入其它模块,可以再执行上述步骤。
    下面以加入KGDB模块为例(在内核升级为2.6.25/2.6.26时,ARM架构和x86等架构先后加入对KGDB的支持):



cd /usr/src/linux-2.6.30.5                                 
make menuconfig
    确保以下选项被选中(注意*代表要编进内核中):
    General setup --->
      
[*] Prompt for development and/or incomplete code/drivers
    Kernel hacking --->
      
[*] Compile the kernel with debug info
      
[*] Compile the kernel with frame pointers
      
[*] KGDB: kernel debugging with remote gdb --->
         KGDB: use kgdb over the serial console



make -j4
make modules_install
cp arch/i386/boot/bzImage /boot/vmlinuz-kgdb
cp System.map /boot
    这里在拷贝bzImage时使用了另外的名字vmlinuz-kgdb,目的是要加入另外一个系统启动项。因此,还需要修改grub,添加新的引导项:



title GRUX-KGDB
kernel (hd0,1)/boot/vmlinuz-kgdb root=/dev/hda2 kgdboc=ttyS1,115200 kgdbwait
    重新启动即可进入CRUX-KGDB进行内核调试。
  
    参考文献:
   CRUX手册 http://crux.nu/Main/Handbook2-6
   操作系统课程设计 http://wenku.baidu.com/view/779802dd5022aaea998f0f2c.html
   内核配置选项 http://lamp.linux.gov.cn/Linux/kernel_options.html
   点点滴滴 http://scutzb.blogspot.com/2012/10/vm7crux-27.html
  
  
  
页: [1]
查看完整版本: Deploy Linux Kernel on CRUX using VMware