**********************************************************************
如何制作一个U盘上的linux系统,并且支持启动,以下是简要过程:
1、制作成一个分区,并设置为活分区
2、制作ext3文件系统
3、安装文件系统树结构的包,filesystem,setup
4、安装grub程序包
5、kernel and initrd
6、安装程序(命令和库文件)
7、grub-install安装grub程序到U盘
**********************************************************************
1、制作成一个分区,并设置为活分区
fdisk /dev/sdb
n添加新的分区
a设置为活动分区
2、制作ext3文件系统
mkfs.ext3 /dev/sdb1
[root@server ~]# mount -t ext3 /dev/sdb1 /net
[root@server ~]# df -h /net
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 1.9G 35M 1.8G 2% /net
3、安装文件系统树结构的包,filesystem ,setup
[root@server Server]# rpm -ivh --root=/net setup-2.5.58-4.el5.noarch.rpm
[root@server Server]# rpm -ivh --root=/net filesystem-2.4.0-2.i386.rpm
[root@server Server]# ls /net
bin etc lost+found opt sbin sys var
boot home media proc selinux tmp
dev lib mnt root srv usr
4、安装grub程序包
[root@server boot]# rpm -ivh --root=/net --nodeps /var/ftp/rhel5.3/Server/grub-0.97-13.2.i386.rpm
[root@server Server]# ls /net/sbin/grub
grub grub-md5-crypt
grub-install grub-terminfo
[root@server Server]# ls /net/boot/grub/
5、kernel and initrd
[root@server boot]# cp /boot/vmlinuz-2.6.18-128.el5 /net/boot/
[root@server boot]# mkinitrd --with=usb-storage --with=ext3 --with=sd_mod --with=scsi_mod --with=ohci_hcd --with=ehci_hcd /net/boot/initrd-usb.img `uname -r`
[root@server grub]# cat /net/boot/grub/grub.conf
defaultl=0
timeout=5
title rhel5u3 usb linux for sulinux(2.6.18-128.el5)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-128.el5 ro root=/dev/sdb1 init=/bin/bash
initrd /boot/initrd-usb.img
[root@server grub]# ls /net/boot/vmlinuz-2.6.18-128.el5
/net/boot/vmlinuz-2.6.18-128.el5
[root@server grub]# ls /net/boot/initrd-usb.img
/net/boot/initrd-usb.img
-----------------------------------------
[root@server grub]# cat /boot/grub/device.map
# this device map was generated by anaconda
(hd0) /dev/sda
[root@server grub]# cp /boot/grub/device.map /net/boot/grub/
[root@server grub]# vim /net/boot/grub/device.map
[root@server grub]# cat /net/boot/grub/device.map
# this device map was generated by anaconda
(hd0) /dev/sdb
6、安装程序(命令和库文件)
+++++++++++++++++++++++++++++++++++
[root@server yum.repos.d]# pwd
/etc/yum.repos.d
[root@server yum.repos.d]# cp rhel-debuginfo.repo xx.repo
[root@server yum.repos.d]# vim xx.repo
[root@server yum.repos.d]# cat xx.repo
[base]
name=Red Hat Enterprise Linux
baseurl=file:///var/ftp/rhel5.3/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
+++++++++++++++++++++++++++++++++++
[root@server /]# yum -y install --installroot=/net coreutils bash SysVinit util-linux vim-enhanced
7、grub-install安装grub程序到U盘
[root@server yum.repos.d]# chroot /net
bash-3.2#
[root@server yum.repos.d]# chroot /net
bash-3.2# grub-install /dev/sdb
/dev/sdb: Not found or not a block device.
bash-3.2# ls /dev/sdb
ls: /dev/sdb: 没有那个文件或目录
bash-3.2# exit
exit
[root@server yum.repos.d]# mknod /net/dev/sdb b 8 16
[root@server yum.repos.d]# mknod /net/dev/sdb1 b 8 17
+++++++++++++++++++++++++
[root@server /]# rpm -q kernel-doc
kernel-doc-2.6.18-128.el5
[root@server /]# rpm -ivh /var/ftp/rhel5.3/Server/kernel-doc-2.6.18-128.el5.noarch.rpm c-2.6.18-128.el5.noarch.rpm
+++++++++++++++++++++++
[root@server /]# gedit /usr/share/doc/kernel-doc-2.6.18/Documentation/devices.txt
8 blockSCSI disk devices (0-15)
0 = /dev/sdaFirst SCSI disk whole disk
16 = /dev/sdbSecond SCSI disk whole disk
32 = /dev/sdcThird SCSI disk whole disk
++++++++++++++++++++++++++++++++++++
[root@server /]# chroot /net/
bash-3.2# grub-install /dev/sdb
df: 警告:无法读取已挂上的文件系统的目录: 没有那个文件或目录
Could not find device for
[root@server yum.repos.d]# cp /etc/mtab /net/etc/mtab
[root@server yum.repos.d]# vim /net/etc/mtab
[root@server yum.repos.d]# cat !$
cat /net/etc/mtab
/dev/sdb1 / ext3 rw 0 0
[root@server yum.repos.d]# cp /etc/fstab /net/etc/
[root@server yum.repos.d]# vim /net/etc/fstab
[root@server yum.repos.d]# cat !$
cat /net/etc/fstab
/dev/sdb1 / ext3 defaults 1 1
[root@server /]# chroot /net
bash-3.2# grub-install /dev/sdb
Could not find device for /dev/mapper/*
Could not find device for /dev/mapper/*
Could not find device for /dev/mapper/*
Installation finished. No error reported.
This is the contents of the device map /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/sdb
bash-3.2#
bash-3.2#
bash-3.2#
bash-3.2#
bash-3.2# sync
测试是否可以设置U盘启动并正常启动起来。
接下来解决init及登录
问题。
====================================================
[root@server ~]# df -h /net
文件系统 容量 已用 可用 已用% 挂载点
/dev/sdb1 1.9G 561M 1.2G 32% /net
[root@server ~]# rpm -ivh --root=/net /var/ftp/rhel5.3/Server/passwd-0.73-1.i386.rpm
error: Failed dependencies:
libuser.so.1 is needed by passwd-0.73-1.i386
cp /etc/shadow /net/etc
[root@server yum.repos.d]# yum -y install --installroot=/net passwd
[root@server yum.repos.d]# chroot /net
bash-3.2# useradd test
bash-3.2# passwd test
Changing password for user test.
New UNIX password:
BAD PASSWORD: it is WAY too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
bash-3.2#
bash-3.2# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
注意:***在/etc/yum.respos.d/目录中添加的yum配置无效时,将配置写到主配置文件中(如下)***
vim /etc/yum.conf文件,添加如下三行
[base]
name=Red Hat Enterprise Linux
baseurl=file:///var/ftp/rhel5.3/Server
enabled=1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=