linux基础之Mini Linux制作

一、编译一个简单的linux步骤如下:

# yum groupinstall ""Development Tools" "Server Platform Development" -y    //安装开发包组
# tar xf linux-3.10.65.tar.xz  //下载内核这里就不介绍了
# cd /usr/src
# ln -sv linux-3.10.15 linux  
# cd linux

# make help
# make allnoconfig
# make menuconfig
这里简单介绍下这次编译到的选项:
内核核心模块相关的:
[*]64-bit kernel  //内核编译成64位的
[*]enable loadable module support --> [*]Module uploading   //允许装卸载模块,这里都是编译进内核的,不借助ramdisk装载模块,先选中吧
   Processor type and features  --->  [*]Symmetric multi-processing support   //支持多处理器,linux上多处理器和多核心是一个意思
                                      Processor family (Generic-x86-64)  ---> (X) Generic-x86-64  //选通用的就可以     
   Bus options (PCI etc.)  --->  [*] PCI support    //PCI相关的
   Device Drivers  --->   SCSI device support  ----> [*]SCSI device support  //SCSI设备的支持
                                                     [*]SCSI disk support  //SCSI硬盘支持
                          [*] Fusion MPT device support  --->  [*] Fusion MPT ScsiHost drivers for SPI  //lspci命令可以查看到本机pci的信息    
                                                               (*) Fusion MPT misc device (ioctl) drivers 
文件系统相关的:
File systems  ---> <*> Second extended fs support    
                   <*> Ext3 journalling file system support                                     
                             [*]   Default to 'data=ordered' in ext3 (NEW)                               
                             [*]   Ext3 extended attributes (NEW)  
                             <*> The Extended 4 (ext4) filesystem         

Executable file formats / Emulations  ---> [*] Kernel support for ELF binaries
                                           [*] Write ELF core dumps with partial segments (NEW)
                                           <*> Kernel support for scripts starting with #!

键盘鼠标usb相关的:

Device Drivers  ---> Input device support  --->  [*]Keyboards  ---> 
                                                 [*]   Mice  ---> 
                                                 <*>   Mouse interface  
                     [*] USB support  ---> <*>   Support for Host-side USB 
                                                 <*>     xHCI HCD (USB 3.0) support
                                                 <*>     EHCI HCD (USB 2.0) support    
                                                 <*>     OHCI HCD support 
                                                 <*>     UHCI HCD (most Intel and VIA) Support

udev相关的:

Device Drivers --> Generic Driver Options --> Mintain a devtmpfs filesystem to mount at /dev  //识别到的设备都挂载到/dev目录
# make -j 4 bzImage //只编译内核文件
# fdisk /dev/sdb  //在现有系统上添加一块盘,分两个区,一个用来做boot,一个用来做根目录

# mke2fs -t ext4 /dev/sdb1
# mke2fs -t ext4 /dev/sdb2
# mkdir /mnt/{boot,sysroot}
# mkdir -pv etc dev proc sys bin usr/{lib,bin,sbin,lin64} lib64 lib/modules home var/{log,run,lock} tmp mnt media root    # mount /dev/sdb1 /mnt/boot/ # mount /dev/sdb2 /mnt/sysroot
# grub-install --root-directory=/mnt /dev/sdb    
# cd /usr/src/linux
# cp arch/x86/boot/bzImage /mnt/boot/bzImage
# file /mnt/boot/bzImage
# vim /mnt/boot/grub/grub.conf
    default=0
    timeout=5
    title Mini Linux (3.10.67)
    root (hd0,0)
    kernel /bzImage ro root=/dev/sda2 init=/bin/bash
写一个脚本bincp复制命令及依赖库到sysroot下
    #!/bin/bash
    #
    target=/mnt/sysroot
    [ -d $target ] || mkdir /mnt/sysroot

    read -p "A command:" command

    libcp(){
      for lib in $(ldd $1 | grep -o "[^[:space:]]*/lib[^[:space:]]*"); do
        libdir=$(dirname $lib)
        [ -d $target$libdir ] || mkdir -p $target$libdir
        [ -f $target$lib ] || cp $lib $target$lib
      done
    }

    while [ "$command" != 'q' -a "$command" != 'quit' ]; do
      if !which $command &> /dev/null;then
        read -p "No such command,enter again:" command
        continue
      fi
      command=$(which --skip-alias $command)
      cmnddir=$(dirname $command)

       [ -d $cmnddir ] || mkdir -p $target$cmnddir
       [ -f $target$command ] || cp $command $target$command
        libcp $command
        read -p "Another command(quit):" command
      done

 

新建虚拟机Mini Linux使用上面的sdb硬盘
重启Mini Linux,可以在bash命令行进行一些命令的操作,比如cd,ls,mount等

也可以新建init程序让系统开机运行

新建脚本init: /mnt/sysroot/sbin/init
                #!/bin/bash
                #
                echo -e "\twelcome to \033[32mMini\033[0m linux"
                mount -n -t proc proc /proc
                mount -n -t sysfs /sys
                mount -n -o remount,rw /dev/sda2 /
                /bin/bash
        # chmod +x /mnt/sysroot/sbin/init

二、

猜你喜欢

转载自www.cnblogs.com/ckh2014/p/10823127.html