歡迎您光臨本站 註冊首頁

U盤啟動linux系統的製作

←手機掃碼閱讀     火星人 @ 2014-03-09 , reply:0
********************************************************************** 如何製作一個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 block

SCSI disk devices (0-15) 0 = /dev/sda First SCSI disk whole disk 16 = /dev/sdb Second SCSI disk whole disk 32 = /dev/sdc Third 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 =

本文出自 「linux」 博客,請務必保留此出處http://sulinux.blog.51cto.com/2557454/529716


[火星人 ] U盤啟動linux系統的製作已經有586次圍觀

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