Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1164981
  • 博文数量: 234
  • 博客积分: 5592
  • 博客等级: 大校
  • 技术积分: 1987
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-23 14:12
文章分类

全部博文(234)

文章存档

2015年(1)

2013年(4)

2012年(16)

2011年(204)

2010年(9)

分类: LINUX

2011-07-25 10:53:03

之前一直用grubinst_gui.exe 来制作安装系统的u盘,它仅限于在windows(nt/2k/xp)下, 每次都要启动虚拟机,而且还要将镜像通过虚拟机复制到u盘上。对于使用ubuntu的我,这可真是够麻烦了,很低效。我一直在找方法在linux下实现,曾经尝试过(1)直接在ubuntu下安装grub到u盘,但是ubuntu现在用的是grub2,写grub的menu.lst很复杂,而且安装过程在u盘产生很多无用的内容,于是放弃。(2)在虚拟机的rhel下安装grub,menu.lst简单了,不过也产生无用内容,而且这还不如在虚拟机xp下弄方便。。。放弃。(3)在ubuntu下重新编译grubinst,但是编译过程出错。
后来,细细读了下grubinst的文档,发现原来可以用bootlace.com代替,而且bootlace.com是完全用c写的,可以直接在linux下执行!!!!!!!于是,此方法就诞生了,经过测试,正常!如下(以下测试均在ubuntu10.04下完成):

一、格式化u盘(假设u盘识别为/dev/sdb,这个以你的计算机上实际情况为准):

null@null:~$
sudo fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): p


Disk /dev/sdb: 4013 MB, 4013948928 bytes

124 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcad4ebea

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-1019, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1019, default 1019):
Using default value 1019
Command (m for help): p

Disk /dev/sdb: 4013 MB, 4013948928 bytes

124 heads, 62 sectors/track, 1019 cylinders
Units = cylinders of 7688 * 512 = 3936256 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcad4ebea

Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1        1019     3917005   83  Linux

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

Calling ioctl() to re-read partition table.

Syncing disks.
null@null:~$ sudo mkfs.vfat /dev/sdb1
mkfs.vfat 3.0.7 (24 Dec 2009)
二、用bootlace.com安装grub到u盘mbr:
null@null:~$
sudo ./bootlace.com --no-backup-mbr --mbr-disable-osbr /dev/sdb

Disk geometry calculated according to the partition table:


Sectors per track = 62, Number of heads = 124


Success.

三、复制grldr、menu.lst到u盘根目录。
null@null:~$
mkdir /tmp/udisk
null@null:~$
mount /dev/sdb1 /tmp/udisk/
null@null:~$
sudo cp ./grub_test/grldr /tmp/udisk/
null@null:~$
sudo cp ./grub_test/menu.lst /tmp/udisk/

至此,u盘已经可以从grub引导启动了。下面尝试从u盘安装linux系统(以rhel5.3为例子)。

##########################################################
四、将rhel5.3的iso镜像中的images下的boot.iso提取复制到u盘根目录。将rhel5.3的dvd镜像复制到u盘根目录。
五、编辑menu.lst文件,添加以下内容并保存。
title RedHat Linux AS5up3 Install
find --set-root /boot.iso
map --mem /boot.iso (hd32)
map --hook
chainloader (hd32)

至此,可以将u盘插到到机器上启动,并在出现grub界面时选择“RedHat Linux AS5up3 Install“,然后就会出现linux安装光盘启动画面,此时输入linux method然后回车,出现选择安装方式的时候选择hardisk,然后选择u盘的盘符即可开始安装。



附:

bootlace.com is a DOS/Linux utility for installing grldr.mbr to MBR.
The whole grldr.mbr is embedded in the body of the bootlace.com utility, so
bootlace.com can be used independently. See below.


******************************************************************************
***        bootlace.com - Install GRLDR.MBR bootstrap code to MBR          ***
******************************************************************************

BOOTLACE.COM installs GRLDR.MBR boot record to the MBR of a harddrive or of a
harddrive image file, or to the boot sector of a floppy or a floppy image.

Usage:

bootlace.com  [OPTIONS]  DEVICE_OR_FILE

OPTIONS:

--read-only        do everything except the actual write to the
specified DEVICE_OR_FILE.

--restore-mbr        restore the previous mbr.

--mbr-no-bpb        do not copy BPB in the boot sector of the
leading FAT partition to MBR.

--no-backup-mbr        do not copy the old MBR to the second sector of
DEVICE_OR_FILE.

--force-backup-mbr    force the copy of old MBR to the second sector
of DEVICE_OR_FILE.

--mbr-enable-floppy    enable the search for GRLDR on floppy.

--mbr-disable-floppy    disable the search for GRLDR on floppy.

--mbr-enable-osbr    enable the boot of PREVIOUS MBR with invalid
partition table(usually an OS boot sector).

--mbr-disable-osbr    disable the boot of PREVIOUS MBR with invalid
partition table(usually an OS boot sector).

--duce            disable the feature of unconditional entrance
to the command-line.

Normally one can unconditionally get the
command-line console by a keypress of `C',
bypassing all config-files(including the
preset-menu). This is a security hole. So we
need this option to disable the feature.

DUCE is for Disable Unconditional Command-line
Entrance.

--chs-no-tune        disable the feature of geometry tune.

--boot-prevmbr-first    try to boot PREVIOUS MBR before the search for
GRLDR.

--boot-prevmbr-last    try to boot PREVIOUS MBR after the search for
GRLDR.

--preferred-drive=D    preferred boot drive number, 0 <= D < 255.

--preferred-partition=P    preferred partition number, 0 <= P < 255.

--serial-number=SN    setup a new serial number for the hard drive.
SN must be non-zero.

--time-out=T        wait T seconds before booting PREVIOUS MBR. if
T is 0xff, wait forever. The default is 5.

--hot-key=K        if the desired key K is pressed, start GRUB
before booting PREVIOUS MBR. K is a word
value, just as the value in AX register
returned from int16/AH=1. The high byte is the
scan code and the low byte is ASCII code. The
default is 0x3920 for space bar. See "int 16
keyboard scan codes" below.

--floppy        if DEVICE_OR_FILE is floppy, use this option.

--floppy=N        if DEVICE_OR_FILE is a partition on a hard
drive, use this option. N is used to specify
the partition number: 0,1,2 and 3 for the
primary partitions, and 4,5,6,... for the
logical partitions.

--sectors-per-track=S    specifies sectors per track for --floppy.
1 <= S <= 63, default is 63.

--heads=H        specifies number of heads for --floppy.
1 <= H <= 256, default is 255.

--start-sector=B    specifies hidden sectors for --floppy=N.

--total-sectors=C    specifies total sectors for --floppy.
default is 0.

--lba            use lba mode for --floppy. If the floppy BIOS
has LBA support, you can specify --lba here.
It is assumed that all floppy BIOSes have CHS
support. So you would rather specify --chs.
If neither --chs nor --lba is specified, then
the LBA indicator(i.e., the third byte of the
boot sector) will not be touched.

--chs            use chs mode for --floppy. You should specify
--chs if the floppy BIOS does not support LBA.
We assume all floppy BIOSes have CHS support.
So it is likely you want to specify --chs.
If neither --chs nor --lba is specified, then
the LBA indicator(i.e., the third byte of the
boot sector) will not be touched.

--fat12            FAT12 is allowed to be installed for --floppy.

--fat16            FAT16 is allowed to be installed for --floppy.

--fat32            FAT32 is allowed to be installed for --floppy.

--vfat            FAT12/16/32 are allowed to be installed for
--floppy.

--ntfs            NTFS is allowed to be installed for --floppy.

--ext2            EXT2 is allowed to be installed for --floppy.

--install-partition=I    Install the boot record onto the boot area of
partition number I of the specified hard drive
or harddrive image DEVICE_OR_FILE.

DEVICE_OR_FILE:    Filename of the device or the image file. For DOS, a BIOS drive
number(hex 0xHH or decimal DDD) can be used to access the drive. BIOS drive
number 0 is for the first floppy, 1 is for the second floppy; 0x80 is for the
first hard drive, 0x81 is for the second hard drive, etc.

Note: BOOTLACE.COM writes only the boot code to MBR. The boot code needs to
load GRLDR as the second(and last) stage of the GRUB boot process. Therefore
GRLDR should be copied to the root directory of one of the supported
partitions, either before or after a successful execution of BOOTLACE.COM.
Currently only partitions with filesystem type of FAT12, FAT16, FAT32, NTFS,
EXT2 or EXT3 are supported.

Note 2: If DEVICE_OR_FILE is a harddisk device or a harddisk image file, it
must contain a valid partition table, otherwise, BOOTLACE.COM will fail. If
DEVICE_OR_FILE is a floppy device or a floppy image file, then it must contain
a supported filesystem(i.e., either of FAT12/FAT16/FAT32/NTFS/EXT2/EXT3).

Note 3: If DEVICE_OR_FILE is a floppy device or a floppy image file, and it
was formated EXT2/EXT3, then you should specify --sectors-per-track and
--heads explicitly.


Important!! If you install GRLDR Boot Record to a floppy or a partition, the
floppy or partition will boot solely grldr, and your original
IO.SYS(DOS/Win9x/Me) and NTLDR(WinNT/2K/XP) will become unbootable. This is
because the original boot record of the floppy or partition was overwritten.
There is no such problem when installing GRLDR Boot Record onto the MBR.
Update: Some NTLDR/IO.SYS/KERNEL.SYS files can be directly chainloaded in the
latest GRUB4DOS.

Tip: If the filename begins in a dash(-) or a digit, you may prefix a dirname
(./) or (.\) to it.

Examples:

Installing GRLDR boot code to MBR under Linux:

bootlace.com  /dev/hda

Installing GRLDR boot code to MBR under DOS:

bootlace.com  0x80

Installing GRLDR boot code to a harddisk image under DOS or Linux:

bootlace.com  hd.img

Installing GRLDR boot code to floppy under Linux:

bootlace.com  --floppy --chs /dev/fd0

Installing GRLDR boot code to floppy under DOS:

bootlace.com  --floppy --chs 0x00

Installing GRLDR boot code to a floppy image under DOS or Linux:

bootlace.com  --floppy --chs floppy.img

BOOTLACE.COM cannot function well under Windows NT/2000/XP/2003. It is expected
(and designed) to run under DOS/Win9x and Linux. Update: For image FILES,
bootlace.com function well under Windows NT/2000/XP/2003. For devices,
bootlace.com will not work under Windows NT/2000/XP/2003 because bootlace.com
is a DOS utility and Windows NT/2000/XP/2003 does not allow bootlace.com to
access devices. 
阅读(4383) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~