萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

刀片伺服器硬碟啟動 Linux 自動化安裝實戰(下):自動安裝配置與最終部署

承接上集,完成硬碟分區、格式化、GRUB 安裝與核心準備後,本文介紹自動安裝配置檔建立、安裝媒體複製、GRUB 選單配置與最終部署驗證。

第六步:準備安裝映像檔

mkdir -p /mnt/sdb/SUSE
cp -r /path/to/SUSE-ISO/* /mnt/sdb/SUSE/

關鍵:必須解壓 ISO 內容至目錄,**不可直接放置 ISO 檔案**,SLES 10 不支援從 ISO 直接安裝。

第七步:建立 autoinst.xml 自動安裝配置

使用 YaST「自動安裝」模組生成 autoinst.xml,重點修改兩段:

A. 啟動管理器區段:新增安裝選單項

<bootloader>
  <sections config:type="list">
    <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>
      <name>SUSE Linux Enterprise Server 10 Installation</name>
      <original_name>install</original_name>
      <root>/dev/sda1</root>
      <type>image</type>
    </section>
  </sections>
</bootloader>

警告:選擇此項將格式化使用者分區並重新安裝,資料全失。

B. 分區區段:保護第一分區不被格式化

<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>
        <size>7402719232</size>
      </partition>
      <partition>  <!-- swap -->
        <filesystem config:type="symbol">swap</filesystem>
        <format config:type="boolean">true</format>
        <mount>swap</mount>
        <partition_nr config:type="integer">2</partition_nr>
        <size>auto</size>
      </partition>
      <partition>  <!-- 根分區 -->
        <filesystem config:type="symbol">reiser</filesystem>
        <format config:type="boolean">true</format>
        <mount>/</mount>
        <partition_nr config:type="integer">3</partition_nr>
        <size>max</size>
      </partition>
    </partitions>
    <use>all</use>
  </drive>
</partitioning>

核心原則:**create=false + format=false 保護安裝分區資料**。

第八步:複製自動安裝配置檔

cp autoinst.xml /mnt/sdb/

安裝時系統會將第一分區掛載至 /mounts/extra,故 autoyast=file:///mounts/extra/autoinst.xml 能正確找到配置。

第九步:建立 GRUB 選單配置

vi /mnt/sdb/boot/grub/menu.lst
color white/blue black/light-gray
default 0
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

關鍵點:

  • install=hd://sda1/SUSE:硬碟安裝來源協議
  • autoyast 協議用 file:// 而非裝置路徑(SUSE 已知問題)
  • 不使用 append 關鍵字,直接在 kernel 行傳參數

最終部署與驗證

  1. 關機,將硬碟 B 移回系統 B 作為啟動碟
  2. 開機,系統 B 從硬碟 B 啟動 GRUB → 選擇安裝項目 → 自動安裝 SLES 10
  3. 安裝過程中會重啟一次,最終進入完整系統

災難恢復功能

用戶若需重置系統,重啟時選擇 GRUB 選單中的「SUSE Linux Enterprise Server 10 Installation」,系統將自動格式化使用者分區並重裝,實現「一鍵恢復出廠狀態」。

結語

此流程比手動安裝更靈活,實現從啟動即自動完成硬體偵測、分區、軟體安裝、配置的全自動化部署,適合批量刀片伺服器初始化場景。

copyright © 萬盛學電腦網 all rights reserved