歡迎您光臨本站 註冊首頁

Linux U盤系統(學習系統啟動過程)

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0
本文描述了Red Hat Enterprise Linux 5環境下製作U盤系統,旨在了解linux操作系統的系統啟動過程.
系統啟動過程
1、加電自檢(POST代碼)
2、boot loader
GRUB -- /boot/grub/grub.conf
kernel
initrd.img
3、INIT
/sbin/init ----- /etc/inittab
/etc/rc.d/rc.sysinit
/etc/rc.d/rc RUNLEVEL
/etc/rc$runlevel.d/S* start
/etc/rc$runlevel.d/K* stop
/etc/X11/prefdm

4、登錄
文本 login
圖形 gdm/kdm
自製一個U盤系統
準備工作:在真實機中把yum配置好
[root@localhost /]# ls /mnt/Server/ 這是軟體包所處的目錄
[root@localhost /]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
rhel-debuginfo.repo
[root@localhost yum.repos.d]# cp rhel-debuginfo.repo pg.repo
[root@localhost yum.repos.d]# vim pg.repo
[root@localhost yum.repos.d]# cat pg.repo
[rhel-server]
name=Red Hat Enterprise Linux
baseurl=file:///mnt/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release






1、準備U盤,並分區,格式化成ext3(可選)文件系統[root@localhost pg]# fdisk -l
[root@localhost pg]# fdisk -l
Disk /dev/sda: 4003 MB, 4003463168 bytes
84 heads, 20 sectors/track, 4654 cylinders
Units = cylinders of 1680 * 512 = 860160 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 5 4655 3905600 c W95 FAT32 (LBA)

[root@localhost pg]# fdisk /dev/sda

The number of cylinders for this disk is set to 4654.


There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sda: 4003 MB, 4003463168 bytes
84 heads, 20 sectors/track, 4654 cylinders
Units = cylinders of 1680 * 512 = 860160 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-4654, default 1):
Using default value 1
Last cylind[root@localhost pg]# mount -t ext3 /dev/sda1 /neter or size or sizeM or sizeK (1-4654, default 4654):
Using default value 4654

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost pg]# partprobe /dev/sda
[root@localhost pg]# ls /dev/sda1
/dev/sda1
--------------
[root@localhost pg]# mkfs.ext3 /dev/sda1


2、

掛載U盤,並把相關文件拷到U盤中
[root@localhost pg]# mount -t ext3 /dev/sda1 /net

把/目錄樹結構在u盤創建好
]# yum --installroot=/net -y install filesystem

/boot
這個目錄應該有vmlinuz-x.x.x initrd-x.x.x.img
/boot/grub
這個目錄中應該有grub的相關文件
grub還要安裝到u盤的首扇區中(grub-install)
/bin /sbin /lib /usr/lib
這些個目錄下應該有一些命令和庫文件
bash ls cp mv
mount
ifconfig
fdisk
mkfs.ext3


基本上你需要的程序比較多,大概有以下一些常用的:
coreutils setup grub vim-enhanced
vim-common gpm perl iptables
openssh openssh-clients
module-init-tools iputils grep awk sed
procps tar bash gcc make rp-pppoe
passwd libuser e2fsprogs util-linux
net-tools SysVinit kernel


-----------------------
a.關於vmlinuz文件:
]# cp /boot/vmlinuz-2.6.18-194.el5 /net/boot/
b.關於initrd.img文件: 為了包含u盤的驅動,需要手動生成initrd.img(包含usb-storage)
]# modinfo -F filename usb-storage

]# mkinitrd --with=usb-storage /net/boot/initrd-usb-2.6.18-194.img `uname -r`
c. 使用此命令grub-install將grub安裝到u盤的首扇區中
grub-install 需要安裝grub軟體包生成
]# yum --installroot=/net -y install grub
]# grub-install /dev/sda 最后執行這一步,還有一些必要工作沒做



d. ]# cat /net/boot/grub/grub.conf
default=0
timeout=5
title RHEL5U5 usb linux for pg
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-194.el5 ro root=/dev/sda1
initrd /boot/initrd-usb-2.6.18-194.img

e. 為了生成以下這些常用的命令,裝包
bash ls cp mv
mount
ifconfig
fdisk
mkfs.ext3

yum bash ls cp mv
mount
ifconfig
fdisk
mkfs.ext3
yum --installroot=/net -y install coreutils setup grub vim-enhanced vim-common gpm perl iptables openssh openssh-clients module-init-tools iputils grep awk sed procps tar bash gcc make rp-pppoe passwd libuser e2fsprogs util-linux net-tools SysVinit kernel pam

f.在U盤系統啟動的時候,需要讀fstab文件,掛載文件系統
]# cp /etc/fstab /net/etc

]# vim /net/etc/fstab
]# cat /net/etc/fstab
/dev/sda1 / ext3 defaults 0 0

開始安裝GRUB程序
]# chroot /net/
bash-3.2#
]# chroot /net/
bash-3.2# grub-install /dev/sda
Probing devices to guess BIOS drives. This may take a long time.
No suitable drive was found in the generated device map. 這個錯誤意味著需要去寫

devices.map文件
bash-3.2# ls /dev/sda
ls: /dev/sda: 沒有那個文件或目錄
bash-3.2# ls /dev/sda1
ls: /dev/sda1: 沒有那個文件或目錄
bash-3.2# mknod /dev/sda b 8 0
bash-3.2# mknod /dev/sda1 b 8 1
bash-3.2# cat /etc/mtab
/dev/sda1 / ext3 rw 0 0
bash-3.2# cat /boot/grub/device.map
(fd0) /dev/fd0
(hd0) /dev/sda

bash-3.2# grub-install /dev/sda
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/sda


]# chroot /net/
bash-3.2# passwd root 修改密碼不成功,將導致 u盤系統啟動后,用root登錄不成功.
Changing password for user root.
passwd: Authentication token manipulation error
解決方法:
vim /net/etc/passwd
root:*:0:0:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
這樣再把root密碼設置為你想要的!




檢查 以下過程是否正確:
/boot/grub/grub.conf
/etc/inittab ---默認運行級別應該是3
/etc/fstab
/etc/passwd
/etc/shadow
pam程序包做驗證的
ls /dev/sda /dev/sda1
]# chroot /net/
bash-3.2# passwd root 這一步必須能成功

本文出自 「大將軍繼華」 博客,請務必保留此出處http://jeffreylee.blog.51cto.com/3085837/564563


[火星人 ] Linux U盤系統(學習系統啟動過程)已經有822次圍觀

http://coctec.com/docs/linux/show-post-48604.html