标签:rtx options 文件复制 顺序 org call relay 10g isp
了解linux的启动过程
1.grub 是启动程序的bootloader
2.linux-kernel 是linux的开源内核
3.busybox 是linux的工具集合
grub-> bzimage > initrd > init > chroot sbin/init (从内存镜像转换成rootfs)>/etc/inittab > fstab>etc/init.d/rcS
操作系统(编译使用): CentOS 7.4Kernel 版本 :5.5.2
1.编译linux kernel
1) 下载及解压:
https://www.kernel.org/
目前最新版本5.5.2
https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.5.2.tar.xz
复制文件到 /usr/src/linux-5.5.2.tar.xz
解压 tar -xvf linux-5.5.2.tar.xz
1 yum install ncusres‐devel # 按照需要编译的一些包
2 cd /usr/src/linux‐5.5.2 # 切换到linux源代码目录
3 make menuconfig #配置内核编译内容,配置一些信息 ,由于是演示,默认就可以了
4 make ‐j4 #执行多cpu方式编译
5 midir /usr/src/modules
6 make modules_install INSTALL_MOD_PATH=/usr/src/modules #将modules安装在这里
https://busybox.net/
目前最新版本1.31.1
https://busybox.net/downloads/busybox-1.31.1.tar.bz2
复制文件到 /usr/src/busybox-1.31.1.tar.bz2
解压 tar -jxvf busybox-1.31.1.tar.bz2
1 yum install glibc‐static # 按照需要编译的静态库包
2 cd /usr/src/busybox‐1.31.1 # 切换到busybox源代码目录
3 make menuconfig # 配置 Settings‐>Build Options‐>Build static binary
4 make install
1 make /usr/src/initrd # 创建初始化目录
2 cd /usr/src/initrd # 进入工作目录
3 cp /usr/src/busybox‐1.31.1/_install/* ‐a . #复制所有busybox文件
4 mkdir proc sys mnt/sysroot dev tmp etc ‐pv #创建必要的目录
5 mknod dev/console c 5 1 # 创建console设备
6 mknod dev/null c 1 3 # 创建null设备
7 rm linuxrc # 删除软连接,这个文件没啥用看着不舒服而已
8 touch init # 创建init 引导程,具体内容见下面信息
9 chmod +x init # 设置可运行程序
10 find . | cpio ‐H newc ‐‐quiet ‐o | gzip ‐9 > /usr/src/initrd.gz #打包initrd
1 #!/bin/sh
2
3 echo "Mounting proc and sys..."
4 mount ‐t sysfs sysfs /sys
5 mount ‐t proc proc /proc
6
7 echo "Detect and export hardware infomation..."
8 mdev ‐s
9
10 echo "Mount real rootfs to /mnt/sysroot..."
11 mount ‐t ext4 ‐o ro /dev/sda2 /mnt/sysroot
12
13 echo "Switch to real rootfs..."
14 exec chroot /mnt/sysroot /sbin/init
1 cp /usr/src/linux‐5.5.2/arch/x86/boot/bzImage /usr/src/vmlinuz #复制内核
1 make /usr/src/sysroot #创建工作目录
2 cd sysroot #进入工作目录
3 cp /usr/src/busybox‐1.31.1/_install/* ‐a . #复制所有busybox文件
4 rm linuxrc # 删除软连接,这个文件没啥用看着不舒服而已
5 # 创建目录
6 mkdir dev var sys mnt etc proc lib home tmp root boot
7 mkdir var/{log,run,lock}
8 mkdir lib/modules
9 mknod dev/console c 5 1 # 创建console设备
10 mknod dev/null c 1 3 # 创建null设备
11 vim etc/inittab #创建rootfs启动文件,内容见下图
12 vim etc/init.d/rcS #创建启动脚本
13 chmod +x rcS
14 vim etc/fstab #当执行mount ‐a 的时候就会执行这个文件里的挂载
1 ::sysinit:/etc/init.d/rcS
2 ::askfirst:‐/bin/sh
3 ::ctrlaltdel:/sbin/reboot
4 ::shutdown:/bin/umount ‐a ‐r
5 ::restart:/sbin/init
1 #!/bin/sh
2
3 echo ‐e "Welcome To My Linux"
4
5 echo "Remount the rootfs..."
6 mount ‐t ext4 ‐o remount,rw /dev/sda2 /
7 echo "Detect and export hardware infomation..."
8 mdev ‐s
9 echo "Mount the other filesystem...fstab"
10 mount ‐a
1 # device mount‐point type options dump fsck
2 sysfs /sys sysfs defaults 0 0
3 proc /proc proc defaults 0 0
4 /dev/sda1 /boot ext4 defaults 0 0
5 /dev/sda2 / ext4 defaults 1 1
1 [root@centos ~]# lsblk
2 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3 sda 8:0 0 100G 0 disk
4 ├─sda1 8:1 0 1G 0 part /boot
5 └─sda2 8:2 0 99G 0 part
6 ├─cl‐root 253:0 0 50G 0 lvm /
7 ├─cl‐swap 253:1 0 2G 0 lvm [SWAP]
8 └─cl‐home 253:2 0 47G 0 lvm /home
9 sdb 8:16 0 10G 0 disk
10 sr0 11:0 1 1024M 0 rom
11 ###############################################
12 [root@centos ~]# fdisk /dev/sdb #开始格式化
13 Welcome to fdisk (util‐linux 2.23.2).
14
15 Changes will remain in memory only, until you decide to write them.
16 Be careful before using the write command.
17
18 Device does not contain a recognized partition table
19 Building a new DOS disklabel with disk identifier 0x3f5d5436.
20
21 Command (m for help): n
22 Partition type:
23 p primary (0 primary, 0 extended, 4 free)
24 e extended
25 Select (default p): p
26 Partition number (1‐4, default 1): 1
27 First sector (2048‐20971519, default 2048): 2048
28 Last sector, +sectors or +size{K,M,G} (2048‐20971519, default 20971519):
+5G
29 Partition 1 of type Linux and of size 5 GiB is set
30
31 Command (m for help): n
32 Partition type:
33 p primary (1 primary, 0 extended, 3 free)
34 e extended
35 Select (default p): p
36 Partition number (2‐4, default 2):
37 First sector (10487808‐20971519, default 10487808):
38 Using default value 10487808
39 Last sector, +sectors or +size{K,M,G} (10487808‐20971519, default 209715
19):
40 Using default value 20971519
41 Partition 2 of type Linux and of size 5 GiB is set
42
43 Command (m for help): p
44
45 Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
46 Units = sectors of 1 * 512 = 512 bytes
47 Sector size (logical/physical): 512 bytes / 512 bytes
48 I/O size (minimum/optimal): 512 bytes / 512 bytes
49 Disk label type: dos
50 Disk identifier: 0x3f5d5436
51
52 Device Boot Start End Blocks Id System
53 /dev/sdb1 2048 10487807 5242880 83 Linux
54 /dev/sdb2 10487808 20971519 5241856 83 Linux
55
56 Command (m for help): w
57 The partition table has been altered!
58
59 Calling ioctl() to re‐read partition table.
60 Syncing disks.
61 [root@centos ~]#
1 mkdir /mnt/boot /mnt/sysroot # 在centos系统上创建两个目录
2 [root@centos src]# lsblk # 查看刚刚分好区的sdb 盘
3 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
4 sda 8:0 0 100G 0 disk
5 ├─sda1 8:1 0 1G 0 part /boot
6 └─sda2 8:2 0 99G 0 part
7 ├─cl‐root 253:0 0 50G 0 lvm /
8 ├─cl‐swap 253:1 0 2G 0 lvm [SWAP]
9 └─cl‐home 253:2 0 47G 0 lvm /home
10 sdb 8:16 0 10G 0 disk
11 ├─sdb1 8:17 0 5G 0 part
12 └─sdb2 8:18 0 5G 0 part
13 sr0 11:0 1 1024M 0 rom
14
15 [root@centos mnt]# mkfs.ext4 /dev/sdb1 #创建文件系统格式
16 mke2fs 1.42.9 (28‐Dec‐2013)
17 Filesystem label=
18 OS type: Linux
19 Block size=4096 (log=2)
20 Fragment size=4096 (log=2)
21 Stride=0 blocks, Stripe width=0 blocks
22 327680 inodes, 1310720 blocks
23 65536 blocks (5.00%) reserved for the super user
24 First data block=0
25 Maximum filesystem blocks=1342177280
26 40 block groups
27 32768 blocks per group, 32768 fragments per group
28 8192 inodes per group
29 Superblock backups stored on blocks:
30 32768, 98304, 163840, 229376, 294912, 819200, 884736
31
32 Allocating group tables: done
33 Writing inode tables: done
34 Creating journal (32768 blocks): done
35 Writing superblocks and filesystem accounting information: done
36
37 [root@centos mnt]# mkfs.ext4 /dev/sdb2
38 mke2fs 1.42.9 (28‐Dec‐2013)
39 Filesystem label=
40 OS type: Linux
41 Block size=4096 (log=2)
42 Fragment size=4096 (log=2)
43 Stride=0 blocks, Stripe width=0 blocks
44 327680 inodes, 1310464 blocks
45 65523 blocks (5.00%) reserved for the super user
46 First data block=0
47 Maximum filesystem blocks=1342177280
48 40 block groups
49 32768 blocks per group, 32768 fragments per group
50 8192 inodes per group
51 Superblock backups stored on blocks:
52 32768, 98304, 163840, 229376, 294912, 819200, 884736
53
54 Allocating group tables: done
55 Writing inode tables: done
56 Creating journal (32768 blocks): done
57 Writing superblocks and filesystem accounting information: done
58
59 [root@centos mnt]# blkid
60 /dev/sda1: UUID="cbf299b0‐d76d‐4efe‐8643‐c900502683d4" TYPE="xfs"
61 /dev/sda2: UUID="L416ib‐7Z3D‐rtXt‐FqTb‐ChsW‐j6zH‐heeuF2" TYPE="LVM2_memb
er"
62 /dev/mapper/cl‐root: UUID="12c02980‐3012‐4884‐8a7d‐437195398fdb" TYPE="x
fs"
63 /dev/mapper/cl‐swap: UUID="c4ea26e2‐7424‐4a52‐aa34‐8d9fb4f3fbd2" TYPE="s
wap"
64 /dev/mapper/cl‐home: UUID="7be941f2‐fcf6‐44b7‐b673‐f999f1c876b0" TYPE="x
fs"
65 /dev/sdb1: UUID="78df7716‐e32f‐421e‐a756‐8fe89407e9ec" TYPE="ext4"
66 /dev/sdb2: UUID="c905f4d2‐ae58‐41f8‐85e6‐69d1f0237ad2" TYPE="ext4"
67 [root@centos mnt]#
68 [root@centos mnt]# mount /dev/sdb1 /mnt/boot
69 [root@centos mnt]# mount /dev/sdb2 /mnt/sysroot
70 [root@centos mnt]# df ‐h
71 Filesystem Size Used Avail Use% Mounted on
72 /dev/mapper/cl‐root 50G 27G 24G 53% /
73 devtmpfs 910M 0 910M 0% /dev
74 tmpfs 920M 0 920M 0% /dev/shm
75 tmpfs 920M 8.5M 912M 1% /run
76 tmpfs 920M 0 920M 0% /sys/fs/cgroup
77 /dev/sda1 1014M 185M 830M 19% /boot
78 /dev/mapper/cl‐home 47G 33M 47G 1% /home
79 tmpfs 184M 0 184M 0% /run/user/0
80 /dev/sdb1 4.8G 20M 4.6G 1% /mnt/boot
81 /dev/sdb2 4.8G 20M 4.6G 1% /mnt/sysroot
1 cp /usr/src/vmlinuz /mnt/boot/ #linux kernel
2 cp /usr/src/initrd.gz /mnt/boot/ #ramdisk 内存镜像(来自于busybox改造)
3 cp ‐a /usr/src/sysroot/* /mnt/sysroot/ #系统目录集合(来自于busybox改造)
4 [root@centos /]# tree mnt ‐L 2
5 mnt
6 ├── boot
7 │ ├── initrd.gz
8 │ └── vmlinuz
9 └── sysroot
10 ├── bin
11 ├── boot
12 ├── dev
13 ├── etc
14 ├── home
15 ├── lib
16 ├── mnt
17 ├── proc
18 ├── root
19 ├── sbin
20 ├── sys
21 ├── tmp
22 ├── usr
23 └── var
1 yum install grub2‐install #由于centos7以后采用的是grub2 所以直接安装了这个
2 [root@centos mnt]# grub2‐install ‐‐boot‐directory=/mnt/boot /dev/sdb #安装
到boot目录下
3 Installing for i386‐pc platform.
4 Installation finished. No error reported.
5 [root@centos boot]# ll
6 total 9248
7 drwxr‐xr‐x. 5 root root 4096 Feb 6 08:25 grub2
8 ‐rw‐r‐‐r‐‐. 1 root root 1484989 Feb 6 08:03 initrd.gz
9 ‐rw‐r‐‐r‐‐. 1 root root 7975904 Feb 6 08:04 vmlinuz
10 [root@centos boot]#grub2‐mkconfig ‐o /mnt/boot/grub2/grub.cfg #为了方便我采用了先根据系统自动生成,然后再编辑这个文件
11 [root@centos boot]# vim /mnt/boot/grub2/grub.cfg #编辑内容见下图,去掉很多用不到的内容
1 # relay display
2 set timeout=5
3 # entry
4 menuentry ‘My Linux‘ {
5 insmod gzio
6 insmod part_msdos
7 insmod xfs
8 set root=‘hd0,msdos1‘
9 linux16 /vmlinuz root=/dev/sda2
10 initrd16 /initrd.gz
11 }
1 cd /mnt/sysroot
2 cp ‐a /usr/src/modules/lib usr/ #复制modules进入这个文件夹
3 mkdir usr/lib64 #创建空文件夹,只是为了规范一点
4 ln ‐s usr/lib64 lib64
5 ln ‐s usr/lib lib
6 #initrd 同样操作
7 cd /usr/src/initrd
8 cp ‐a /usr/src/modules/lib usr/ #复制modules进入这个文件夹
9 mkdir usr/lib64 #创建空文件夹,只是为了规范一点
10 ln ‐s usr/lib64 lib64
11 ln ‐s usr/lib lib
12 # 重新生成initrd.gz 由于模块我没有精简所以耗时比较久
13 find . | cpio ‐H newc ‐‐quiet ‐o | gzip ‐9 > /usr/src/initrd.gz
14 # 替换 旧的initrd.gz
15 cp initrd.gz /mnt/boot/
1 #!/bin/sh
2
3 echo "Mounting proc and sys..."
4 mount ‐t sysfs sysfs /sys
5 mount ‐t proc proc /proc
6
7 echo "Detect and export hardware infomation..."
8 mdev ‐s
9
10 exec /bin/sh
11 把项目两句话注释掉,改成直接执行 exec /bin/sh 作为主进程
12
13 echo "Mount real rootfs to /mnt/sysroot..."
14 #mount ‐t ext4 ‐o ro /dev/sda2 /mnt/sysroot
15
16 echo "Switch to real rootfs..."
17 # exec chroot /mnt/sysroot /sbin/init
cat /proc/filesystems
Device Drivers > SCSI device Support >SCSI Disk Support
SCSI generic support
使用 linux kernel +busybox 定制linux系统
标签:rtx options 文件复制 顺序 org call relay 10g isp
原文地址:https://www.cnblogs.com/CtripDBA/p/12290071.html