您的位置:首页 > 运维架构 > Linux

用自引导驱动简化 Linux 安装

2008-05-28 09:13 260 查看
起步

我们从两个系统开始:

System A 预装 SLES10,并装了 grub 作为引导加载程序。它有两个 SCSI 磁盘接口,但只使用第一个。

System B 是个裸系统,只有一块硬盘,没有预装操作系统。

我们将用 System A 为 System B 准备自安装硬盘。

第一步是制作一个自引导硬盘。请将这个硬盘格式化成两个分区:

第一个(小一些)分区包含 SUSE 安装介质;我们称之为安装分区。

第二个(大一些)分区保留给操作系统使用;我们称之为 OS 分区.

第 1 步. 正确连接硬盘线

关闭两个系统的电源,从 System B 拔下硬盘(硬盘 B)将硬盘 B 插入 System A 的第二个 SCSI 硬盘接口。然后用 System A 自己的硬盘(硬盘 A)引导 System A。

第 2 步. 对硬盘 B 分区

使用
fdisk
命令对硬盘 B 分区。如果使用 SCSI 硬盘,那么硬盘名称是 /dev/sdb(如果使用其他类型的硬盘,例如 IDE 硬盘,请相应地调整硬盘名称。可以使用
fdisk -l
查看硬盘的设备名)。

运行
fdisk /dev/sdb
命令。

输入
d
删除现有的任何分区。如果硬盘是空的,可以跳过这步。

输入
n
添加新分区。创建新分区并将它安装为第一个主分区:选择 primary partition 并选择编号 1 作分区编号。接下来,分配从 1 到 900 个扇区(大约 6.3 GB 就够了,因为 SUSE 的安装介质需要大约 4.3GB),如清单 1 所示。可以根据需要进行调整。

清单 1. 创建安装分区

blade8:~ # fdisk /dev/sdb

The number of cylinders for this disk is set to 8924.
There is nothing wrong with that, but this is larger that 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): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4) : 1
First cylinder (1-8924, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-8924, default 8924) : 900
Command (m for help):

输入
n
创建另一个分区(操作系统分区),如清单 2 所示:

清单 2. 创建操作系统分区

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4) : 2
First cylinder (901-8924, default 901):
Using default value 901
Last cylinder or +size or +sizeM or +sizeK (1-8924, default 8924) :
Using default value 8924

Command (m for help):

不要在这个分区上放任何数据;在 SUSE 安装期间会格式化这个分区。

输入
a
启用第一个分区(安装分区)的可引导标志,如清单 3 所示。选择将分区 1 设置为可引导分区。

清单 3. 将安装分区设置为可引导分区

Command (m for help): a
Partition number (1-4) : 1

输入
w
将所有分区信息写入分区表,并退出分区程序,如清单 4 所示:

清单 4. 写入分区信息

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

Calling ioctl() to re-read partition table.
Syncing disks.

这会将修改提交到硬盘。

现在已经成功划分了硬盘 B 的分区。

第 3 步. 格式化分区

用 ext3 文件系统格式化硬盘 B 的第一个分区:

清单 5. 格式化第一个分区

blade8:~ # mkfs.ext3 /dev/sdb1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
904960 inodes, 1807304 blocks
90365 blocks (5.00%) reserved for the super user
First data block=0
56 block groups
32768 blocks per group, 32768 fragments per group
16160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

The filesystem will be automatically checked every 37 mounts or 180 days,
whichever comes first. Use tune2fs -c or -I to override.

第 4 步. 安装 grub 加载程序

按照以下步骤在硬盘 B 的第一个分区上安装 grub 加载程序:

将第一个分区装载为一个文件夹,例如 /mnt/sdb。请运行
mount /dev/sdb1 /mnt/sdb


将 grub 引导文件从 /boot/grub 文件夹复制到 /mnt/sdb/boot/ 文件夹;包括 grub stage 文件和 grub 配置文件。

输入以下命令在硬盘 B 的第一个分区上安装 grub,如清单 6 所示:
grub-install --root-directory=/mnt/sdb /dev/sdb1 -recheck
:

清单 6. 安装 grub

blade8:~ # grub-install -root-directory=/mnt/sdb /dev/sdb1 -recheck
Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /mnt/sdb/boot/grub/device.map.
Check if this is correct or not. If any of the line is incorrect,
Fix it and re-run the script 'grub-install'.

(fd0)   /dev/fd0
(hd0)   /dev/sda
(hd1)   /dev/sdb

现在已经成功地使硬盘 B 的安装分区能够利用 grub 引导。下面,需要对 grub 进行配置,让它在硬盘引导的时候启动 SUSE 的安装程序。首先要将安装程序的内核和 initrd 文件复制到安装分区,然后准备 grub 的配置文件。

第 5 步. 准备安装内核

安装内核的准备操作就是从 SUSE 的安装 ISO 文件中复制安装内核。请创建文件夹 /mnt/sdb/boot,然后将文件 linux 和 initrd 从 ISO 文件夹 /boot/i386/loader/ 复制到新建的文件夹。

第6 步. 准备 Linux 安装映像文件

Linux 安装映射文件的准备方法是:创建文件夹 /mnt/sdb/SUSE,然后将 SUSE ISO 映像中的所有文件复制到新文件夹。

注意:必须将 ISO 映射中的内容复制到目录内。SUSE 10 似乎不支持直接在这里使用 ISO 文件。如果只将 ISO 文件放在这里,系统就无法找到安装的源文件。

第 7 步. 准备 SUSE 安装

现在为 SUSE 安装准备 autoinst.xml 文件。请用 yast 自动安装创建 autoinst.xml 文件。需要对该文件的以下两部分做修改:

在 bootloader 部分添加一节,让用户能够选择引导系统的引导菜单。系统会再次安装操作系统,并回到初状态。请在 bootloader 部分添加以下代码:

清单 7. 更新 bootloader 区

<bootloader>
<sections>
...
<section>
<append>ramdisk_size=8192 install=hd://sda1/SUSE
autoyast=file:///mounts/extra/autoinst.xml splash=silent showopts</append>
<initrd>(hd0,0)/boot/initrd</initrd>
<kernel>(hd0,0)/boot/linux</kernel>
<lines_cache_id>3</lines_cache_id>
<name>SUSE Linux Enterprise Server 10 Installation</name>
<original_name>install</original_name>
<root>/dev/sda1</root>
<type>image</type>
</section>
...
</sections>
</bootloader>

注意:如果用户选择从这个菜单引导,那么硬盘上的所有数据都会丢失,因为安装过程会格式化用户分区。

修改文件的 partitioning 部分,确保安装过程不会创建并格式化分区 1;也可以在系统中隐藏该分区。下面是我使用的 autoinst.xml 文件的 partitioning 部分:

清单 8. 更新 partitioning 区

<partitioning config:type="list">
<drive>
<device>/dev/sda</device>
<partitions config:type="list">
<partition>
<create config:type="boolean">false</create>
<filesystem config:type="symbol">ext3</filesystem>
<format config:type="boolean">false</format>
<partition_id config:type="integer">131</partition_id>
<partition_nr config:type="integer">1</partition_nr>
<partition_type>primary</partition_type>
<size>7402719232</size>
</partition>
<partition>
<filesystem config:type="symbol">swap</filesystem>
<format config:type="boolean">true</format>
<mount>swap</mount>
<partition_id config:type="integer">130</partition_id>
<partition_nr config:type="integer">2</partition_nr>
<partition_type>primary</partition_type>
<size>auto</size>
</partition>
<partition>
<filesystem config:type="symbol">reiser</filesystem>
<format config:type="boolean">true</format>
<mount>/</mount>
<partition_id config:type="integer">131</partition_id>
<partition_nr config:type="integer">3</partition_nr>
<partition_type>primary</partition_type>
<size>max</size>
</partition>
</partitions>
<use>all</use>
</drive>
</partitioning>

我们要使用整个硬盘,但是不想创建并格式化第一个分区。可以自定义分区的配置,但是请记住:不要创建并格式化第一个分区。

第 8 步. 复制安装配置文件

将 SUSE 的静默安装的配置文件 autoinst.xml 复制到加载硬盘 B 的文件夹 /mnt/sdb。

第 9 步. 创建并修改 grub 配置文件

创建 grub 配置文件 /mnt/sdb/boot/grub/menu.lst,添加以下内容:

清单 9. 更新 grub 配置文件

color white/blue black/light-gray
default
timeout 30

title SUSE Linux Enterprise Server 10 Installation
root (hd0,0)
kernel /boot/linux root=/dev/sda1 ramdisk_size=8192
install=hd://sda1/SUSE autoyast=file:///mounts/extra/autoinst.xml
splash=silent showopts
initrd /boot/initrd

在第 9 步中需要注意

系统将从该硬盘上寻找安装映像,安装映像的位置协议是 hd,它代表硬盘。

autoyast 的协议应该是 file 而不是 device(虽然 autoyast 的文档说支持 device,但实际上这个协议不工作:我认为这是 SUSE 的一个 bug。)

在安装过程中,系统会将第一个分区加载到文件夹 /mounts/extra,所以系统需要在文件夹 /mounts/extra 中找到 autoyast 文件。

在这里我们不能使用
append
添加内核参数。

第 9 步完成之后

关闭 System A 的电源,拔下硬盘 B。

将硬盘 B 插入 System B,作为第一块硬盘。

打开 System B 电源,System B 将开始安装 SUSE。等待 System B 安装操作系统。System B 在安装期间会自动重启一次并完成安装。

System B 现在就可以使用了。

如果用户希望系统恢复到初始状态,用户在系统引导期间可以选择菜单项 SUSE Linux Enterprise Server 10 Installation,系统会格式化用户的分区并在用户分区上安装 SUSE。

操作完成!

结束语

以上这些步骤完整地描述了准备可引导的自安装硬盘驱动的过程。使用这块硬盘的系统在系统引导时会自动开始安装操作系统,安装过程会自动检测硬件并做需要的修改。这个过程要比单纯地在硬盘上安装 SUSE 然后从硬盘引导系统更加灵活。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: