您的位置:首页 > 运维架构 > Linux

自己制作的小型linux 系统

2012-08-05 20:45 267 查看
Linux 的启动流程:
加载BIOS的硬件信息与进行自我测试,并依据设置取得第一个可启动的设备。
读取并执行第一个可启动设备内MBR的boot Loader。(即是GRUB,spfdisk)
依据boot loader的设置加载Kernel 会主动调用init进程,而init会取得run-level信息
init执行/etc/rc.d/rc.sysinit文件来准备软件执行的操作环境(如网络、时区等)
init执行run-level的各个服务的启动(script方式)
init执行/etc/rc.d/rc.local文件
init执行终端机模拟程序mingetty来启动login进程,最后就等待用户登录
一.基本配置:
示意图:



1. 宿主机的配置:












 






2.查看已添加的第二个磁盘
[root@gjp99 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1353 522112+ 82 Linux swap / Solaris
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition tabl
3.对第二个磁盘进行分区
[root@gjp99 ~]# fdisk /dev/sdb
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1 //第一个主分区作为启动盘
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): +100m
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2 // 作为根分区
First cylinder (14-2610, default 14):
Using default value 14
Last cylinder or +size or +sizeM or +sizeK (14-2610, default 2610): +500m
Command (m for help): a //设置启动盘
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 13 104391 83 Linux
/dev/sdb2 14 75 498015 83 Linux
Command (m for help): w //保存
4.查看分区情况:
[root@gjp99 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 104391 sda1
8 2 10241437 sda2
8 3 522112 sda3
8 16 20971520 sdb
8 17 104391 sdb1
8 18 498015 sdb2
5. 对第二个磁盘进行格式化
[root@gjp99 ~]# mkfs -t ext3 /dev/sdb1
[root@gjp99 ~]# mkfs -t ext3 /dev/sdb2
[root@gjp99 ~]# mkdir /mnt/boot
[root@gjp99 ~]# mkdir /mnt/sysroot
[root@gjp99 ~]# mount /dev/sdb1 /mnt/boot
[root@gjp99 ~]# mount /dev/sdb2 /mnt/sysroot
6.自动生成MBR 和 GRUB 第一部分的配置文件
[root@gjp99 ~]# grub-install --root-directory=/mnt/ /dev/sdb
//MBR 和 GRUB的第二段的BOOT都生成了
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt//boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
7.拷贝宿主机的内核和镜像到第二个硬盘上
[root@gjp99 ~]# cp /boot/vmlinuz-2.6.18-164.el5 /mnt/boot/
[root@gjp99 ~]# cp /boot/initrd-2.6.18-164.el5.img /mnt/boot/
8.在根目录下建立比较重要的目录
[root@gjp99 sysroot]# mkdir bin boot dev etc home lib proc root sbin sys tmp usr var
[root@gjp99 sysroot]# chmod o+t tmp //需注意
9.查看init命令所在的位置
[root@gjp99 sysroot]# which init
/sbin/init
[root@gjp99 sysroot]# cp /sbin/init sbin/ //拷贝init文件到第二个磁盘相同的目录下
[root@gjp99 sysroot]#cd /mnt/sysroot
[root@gjp99 sysroot]# ldd /sbin/init //查看init所使用到的相关系统调用
linux-gate.so.1 => (0x00788000)
libsepol.so.1 => /lib/libsepol.so.1 (0x008a7000)
libselinux.so.1 => /lib/libselinux.so.1 (0x0088d000)
libc.so.6 => /lib/libc.so.6 (0x00110000)
libdl.so.2 => /lib/libdl.so.2 (0x0084e000)
/lib/ld-linux.so.2 (0x006bf000)
例如: 拷贝最后一行:(其实需全部拷贝)
[root@gjp99 sysroot]# cp /lib/libdl.so.2 lib/
10.进入第二个磁盘的根目录:
[root@gjp99 ~]#cd /mnt/sysroot/etc
[root@gjp99 etc]# cp /etc/inittab . //拷贝inittab到当前目录
[root@gjp99 etc]# ls //显示
Inittab
[root@gjp99 etc]# vim inittab //编辑inittab文件
si::sysinit:/etc/rc.d/rc.sysinit //只要这一条
11.新建rc.d 目录 ,配置 rc.sysconfig
[root@gjp99 etc]# mkdir rc.d
[root@gjp99 etc]# ll
total 2
-rw-r--r-- 1 root root 638 Aug 3 19:13 inittab
drwxr-xr-x 2 root root 1024 Aug 3 19:29 rc.d
[root@gjp99 etc]# cd rc,d
[root@gjp99 rc.d]# vim rc.sysinit
#!/bin/bash //命令解释器
/bin/bash
[root@gjp99 ~]# cp /bin/bash /mnt/sysroot/bin/ //拷贝bash目录
[root@gjp99 ~]# ldd /bin/bash //bash相关的系统调用文件
linux-gate.so.1 => (0x009e6000)
libtermcap.so.2 => /lib/libtermcap.so.2 (0x00854000)
libdl.so.2 => /lib/libdl.so.2 (0x0084e000)
libc.so.6 => /lib/libc.so.6 (0x006dd000)
/lib/ld-linux.so.2 (0x006bf000)
必须全拷贝过去,这里是两个实例 (必须全部拷贝到/bin下)
[root@gjp99 sysroot]# cp /lib/libtermcap.so.2 /mnt/sysroot/bin/
[root@gjp99 sysroot]# cp /lib/libdl.so.2 /mnt/sysroot/bin/
12.修改rc.sysinit的权限
[root@gjp99 sysroot]# cd etc/rc.d
[root@gjp99 rc.d]# ll
total 1
-rw-r--r-- 1 root root 22 Aug 3 19:32 rc.sysinit
[root@gjp99 rc.d]# chmod a+x sysinit //给它执行的权限
[root@gjp99 rc.d]# cd
13.拷贝ls命令的相关文件
[root@gjp99 ~]# which ls //查找ls文件所在的位置
alias ls='ls --color=tty'
/bin/ls
[root@gjp99 ~]# cp /bin/ls /mnt/sysroot/bin/ //拷贝到第二个磁盘的bin下
[root@gjp99 ~]# ldd /bin/ls //显示相关的系统调用
linux-gate.so.1 => (0x00f33000)
librt.so.1 => /lib/librt.so.1 (0x0086d000)
libacl.so.1 => /lib/libacl.so.1 (0x00878000)
libselinux.so.1 => /lib/libselinux.so.1 (0x0088d000)
libc.so.6 => /lib/libc.so.6 (0x006dd000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00854000)
/lib/ld-linux.so.2 (0x006bf000)
libattr.so.1 => /lib/libattr.so.1 (0x00b9a000)
libdl.so.2 => /lib/libdl.so.2 (0x0084e000)
libsepol.so.1 => /lib/libsepol.so.1 (0x008a7000)
全部拷贝,实例如下:
[root@gjp99 ~]# cp /lib/librt.so.1 /mnt/sysroot/lib/
14.配置grub.conf
[root@gjp99 ~]# cd /mnt/boot/grub
[root@gjp99 ~]# vim /mnt/boot/grub/grub.conf
default=0  //默认输入的是Linux 可以修改
timeout=5   //超时时间
splashimage=(hd0,0)/grub/welce.xpm.gz //加载的图片
#hiddenmenu   //隐藏GRUB菜单
title Red Hat Enterprise liunx 5.4 (gjp create) // GRUB菜单的标题
root(hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=/dev/sda2 quiet  //内核驱动  只读   硬盘   静默模式
initrd /initrd-2.6.18-164.el5.img  //镜像文件
15.加载图片时应注意一下
   用xftp上传文件时,要保证ftp的vsftpd.conf文件的UPLOAD 功能已打开
[root@gjp99 ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd.log
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
/etc/vsftpd/vsftpd_conf_migrate.sh
     保证/var/ftp/pub的权限增加可写
     上传后安装gimp绘图工具
[root@gjp99 Server]#ll gimp*
[root@gjp99 Server]#yum install gimp –y
[root@gjp99 ~]#gimp
进入编辑状态,FILE ----open 


  enter键






gzip  lzw.xpm   得到xpm.gz 格式的文件
把lzw.xpw.gz格式的文件存放在grub目录下
二、测试
1.先新建虚拟机
2.删除已存在的硬盘
3.增加新硬盘,添加过程,注意如下:




选择用一个已存在的虚拟盘(我们事先建好的)






增加宿主机上的第二块硬盘后的效果
 
4.1启动时的GRUB菜单:




4.2 启动起来的界面:


 

(注意,在测试时,必须把宿主机暂停掉),因为我们用的是宿主机的第二块硬盘
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux target blank border