--
光盘里的diskboot文件做引导
dd if=diskboot.img of=/dev/sdb
usblinux
livecd 不用安装,直接可以使用系统的CD,DVD
回顾开机启动的过程:
开机-->bios(配置主板的程序,basic input and output system,加电自检,找到启动设备的编号)-->找到mbr(master bootloader record,它是属于硬盘的0磁盘0扇区)-->grub-->通过grub找到vmlinuz和initrd(驱动硬件)--> 内核启动,产生init进程-->/etc/inittab(确定系统的启动级别)-->/etc/rc.sysinit(获取主机的网络环境和主机类型,测试与载入设备,是否启动selinux,模块的加载,设置系统时间.................)-->/etc/rc.local
规划一下U盘
比如说两G
可以分两个区:一个根分区,一个swap分区
也可以分三个区:一个根分区,一个swap分区,还有空间可以格式成fat32储存资料
这里的分区实例为:
1G 为根
512M 为swap
512M FAT32,继续当U盘使用
1,首先删除U盘里原有分区
第一种:用fdisk /dev/sdb,然后用d命令去删除
第二种:dd if=/dev/zero of=/dev/sdb bs=1024 count=1 --删除磁盘分区信息
2,开始按规划的分区方式分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1008, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1008, default 1008): +1000M --分一G大小给linux的根分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (494-1008, default 494):
Using default value 494
Last cylinder or +size or +sizeM or +sizeK (494-1008, default 1008): +512M --分512M给linux的swap分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (747-1008, default 747):
Using default value 747
Last cylinder or +size or +sizeM or +sizeK (747-1008, default 1008): --最后的空间全部留给U盘格式化成windows分区使用
Using default value 1008
Command (m for help): a
Partition number (1-4): 1 --把第一个分区设置为引导分区
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris) --把第二个分区的ID改成swap分区格式
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): b
Changed system type of partition 3 to b (W95 FAT32) --把第三个分区改为FAT32的分区格式
Command (m for help): p --打印查看最后结果
Disk /dev/sdb: 2048 MB, 2048901120 bytes
64 heads, 62 sectors/track, 1008 cylinders
Units = cylinders of 3968 * 512 = 2031616 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 493 978081 83 Linux
/dev/sdb2 494 746 501952 82 Linux swap / Solaris
/dev/sdb3 747 1008 519808 b W95 FAT32
Command (m for help): w --保存退出
3,格式化分区,并挂载
[root@li www]# partprobe --fdisk分区后,都要用此命令刷新
[root@li www]# mkfs -t ext3 /dev/sdb1
[root@li www]# mkswap /dev/sdb2
[root@li www]# mkfs -t vfat /dev/sdb3 --把刚分的三个分区分别格式化
[root@li www]# mkdir /usb
[root@li www]# mount /dev/sdb1 /usb/ --建立一个目录,挂载/dev/sdb1
四,安装基本的目录结构
准备光盘iso文件,挂载到一个目录去
[root@li www]# mount /share/iso/rhel-5.4-server-i386-dvd.iso /yum/ -o loop
[root@li www]# cd /yum/Server/
[root@li Server]# rpm -qip filesystem-2.4.0-2.i386.rpm
Description :
filesystem 软件包是安装在红帽 Linux 系统上的一个基本
软件包。filesystem 含有一个 Linux 操作系统的基本目录布局,
包括各目录的正确许可权限。
要使用--nodeps脱离依赖性才可以安装
[root@li Server]# rpm -ivh --root=/usb/ --nodeps filesystem-2.4.0-2.i386.rpm
[root@li Server]# ls /usb --安装过后可以看到基本目录,但目录内并没有文件
bin dev home lost+found mnt proc sbin srv tmp var
boot etc lib media opt root selinux sys usr
5,安装相应的软件包,也就是定制功能
下面最主要的一步就是安装系统的软件包,首先要思考安装的这个USB系统需要什么功能,比如最基本的命令ls,cd等
cd命令属于内部命令
man type里有50来个内部命令
[root@li Server]# rpm -ql bash
[root@li Server]# rpm -qf /bin/ls
coreutils-5.97-23.el5
[root@li Server]# rpm -qf `which mount`
util-linux-2.13-0.52.el5
[root@li Server]# rpm -qf `which passwd`
passwd-0.73-1
[root@li Server]# rpm -qf `which ifconfig`
net-tools-1.60-78.el5
[root@li Server]# rpm -qf `which iptables`
iptables-1.3.5-5.3.el5
[root@li Server]# rpm -qf `which top`
procps-3.2.7-11.1.el5
[root@li Server]# rpm -qf `which vi`
vim-minimal-7.0.109-6.el5
[root@li Server]# rpm -qf `which vim`
vim-enhanced-7.0.109-6.el5
[root@li Server]# rpm -qf `which ssh`
openssh-clients-4.3p2-36.el5
[root@li Server]# rpm -qf `which ping`
iputils-20020927-46.el5
[root@li Server]# rpm -qf `which tar`
tar-1.15.1-23.0.1.el5
[root@li Server]# rpm -qf `which bzip2`
bzip2-1.0.3-4.el5_2
[root@li Server]# rpm -qf `which gzip`
gzip-1.3.5-10.el5
[root@li Server]# rpm -qf `which init`
SysVinit-2.86-15.el5
[root@li ~]# rpm -qf `which grep`
grep-2.5.1-55.el5
[root@li ~]# rpm -qf `which awk`
gawk-3.1.5-14.el5
[root@li ~]# rpm -qf `which sed`
sed-4.1.5-5.fc6
[root@li ~]# rpm -qf `which portmap`
portmap-4.0-65.2.2.1
[root@li ~]# rpm -qf `which mount.nfs`
nfs-utils-1.0.9-42.el5
配置好yum程序
安装定制好的功能包,下面的包可以按照需要来增减
[root@li Server]# yum install --installroot=/usb bash coreutils util-linux passwd net-tools shadow-utils iptables procps vim-minimal vim-enhanced openssh-clients iputils tar bzip2 gzip SysVinit sed grep gawk portmap nfs-utils
6,安装引导文件
[root@li Server]# chroot /usb --使用此命令,就是以/usb目录为根目录了
bash-3.2# ls /boot/ --可以看到现在usblinux里的/boot目录没有任何文件
bash-3.2# exit --用exit退出chroot模式
exit
定制支持usb存储启动的ramdisk(initrd文件)
[root@li Server]# mkinitrd --with usb_storage /usb/boot/initrd.img `uname -r`
从真机上拷贝vmlinuz到usblinux对应目录
[root@li Server]# cp /boot/vmlinuz-2.6.18-164.el5 /usb/boot/vmlinuz
从真机上拷贝内核模块到usblinux对应目录
[root@li Server]# cp /lib/modules/2.6.18-164.el5/ /usb/lib/modules/ -rf
7,安装并手动写grub
安装grub包,用--nodeps脱离依赖性
[root@li Server]# rpm -ivh --nodeps --root=/usb grub-0.97-13.5.i386.rpm
grub-install安装到/dev/sdb
[root@li Server]# grub-install --root-directory=/usb --recheck /dev/sdb
修改device.map
[root@li Server]# vim /usb/boot/grub/device.map
(hd0) /dev/sdb
手动写grub.conf文件
[root@li Server]# vim /usb/boot/grub/grub.conf
default=2
timeout=-1
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
title usblinux
root (hd0,0)
kernel /boot/vmlinuz ro root=/dev/sdb1
initrd /boot/initrd.img
从真实机上把grub背景图版拷到usblinux的对应目录
[root@li ~]# cp /boot/grub/splash.xpm.gz /usb/boot/grub/
---------------------------------------
引申:自己DIYgrub背景图片
[root@li ~]# yum install ImageMagick -y
[root@li ~]# convert -resize 640*480 image.jpg -colors 14 splash.xpm && gzip splash.xpm
[root@li ~]# cp splash.xpm /boot/grub/
最后去修改grub
--------------------------------------------------
8,拷贝密码文件,拷贝环境变量
[root@li Server]# cp /etc/passwd /usb/etc/passwd
[root@li Server]# chroot /usb/
bash-3.2# cp /etc/skel/.bash* /root/ --拷贝环境变量的模版
bash-3.2# exit
exit
[root@li Server]# chroot /usb/ --再次chroot到/usb目录,提示符就变了
[root@li /]# pwconv --同步/etc/passwd和/etc/shadow
[root@li /]# passwd root --修改root的密码,到时候登录需要
9,手动编写fstab文件
[root@li /]# vim /etc/fstab --注意这里是usblinux系统里的fstab,因为已经chroot进来了
/dev/sdb1 / ext3 defaults 0 0
/dev/sdb2 swap swap defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
10,让usblinux支持网络
从真机拷贝eth0的配置文件到usblinux对应目录中:
[root@li Server]# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /usb/etc/sysconfig/network-scripts/
修改网络配置文件,可以改成静态IP
[root@li Server]# vim /usb/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
从真机拷贝全局网络配置文件到usblinux对应目录中
[root@li Server]# cp /etc/sysconfig/network /usb/etc/sysconfig/
从真机拷贝modprobe.conf到usblinux对应目录中
[root@li Server]# cp /etc/modprobe.conf /usb/etc/
alias eth0 8139too --注意这一句在不同的系统里可能要修改,现在这里的网卡模块是8139too,所以这里是8139too就可以
-----------------------------------------------------------
做完后,reboot系统
在bios里改成usb启动
登录上去验证功能
exec01_usblinux.txt
最新推荐文章于 2024-12-16 07:00:00 发布