歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> CentOS 7.0全自動安裝光盤制作詳解

CentOS 7.0全自動安裝光盤制作詳解

日期:2017/2/28 14:22:03   编辑:Linux教程

CentOS 7.0全自動安裝光盤制作詳解

1 復制光盤文件

1 )掛載 iso 鏡像

創建目錄用於掛載光盤:
mkdir /root/centos7

掛載 iso 鏡像
mount -o loop CentOS-7.0-1406-x86_64-DVD.iso/root/centos7

2 )復制光盤文件到編輯目錄進行編輯

因為掛載上 iso 鏡像是只讀的,如果要編輯,需要將文件復制出來,再編輯。

首先創建編輯目錄:
mkdir /root/centos7_iso

復制光盤文件:
cp -rf /root/centos7/* /root/centos7_iso/

diskinfo 文件需求單獨拷貝下:
cp /root/centos7/.discinfo /root/iso

2 編輯 ks.cfg 文件

系統安裝的時候,按照 ks.cfg 文件的內容進行安裝,我們把 ks.cfg 文件放到 isolinux 目錄下:
cd /root/centos7_iso/isolinux
vim ks.cfg

我的 ks.cfg 文件內容如下:
#version=RHEL/CentOS7 by xiaoli110
install
# Keyboard layouts
keyboard 'us'
# Reboot after installation
reboot
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
#network --bootproto=dhcp --device=enp2s0 --onboot=off --ipv6=auto
#network --bootproto=dhcp --device=enp3s0 --onboot=off --ipv6=auto
#network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted 111111111111111111111111111
# System timezone
timezone Asia/Shanghai
# System language
lang zh_CN
# Firewall configuration
firewall --enabled --ssh

# System authorization information
auth --useshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="xfs"--size=500
part /boot/efi --fstype="xfs"--size=500
part swap --fstype="swap"--size=16000
part / --fstype="xfs" --grow--size=1

%packages
@base
@core
@development
@hardware-monitoring
@performance
@remote-system-management
%end

注意:

1 )因為 CentOS7 系統網卡規則更復雜,為了 ks.cfg 更通用,最好 ks.cfg 不用制定網卡配置。

2 )為了兼容 mbr 方式和 EFI 方式,同時創建了 /boot 和 /boot/efi 分區。

3 配置 mbr 引導方式

編輯 isoliuux 目錄下的 isolinux.cfg 文件,添加自己的內容,在 isolinux.cfg 文件中 label linux 下面添加自己的 label :
label linux
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 quiet

label custom
menu label ^Custom CentOS 7 by xiaoli110
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CENTOS7 inst.ks=cdrom:/isolinux/ks.cfg

注意點:

1 ) memu label 後面的內容是在光盤引導起來菜單的內容, ^ 後面的字母是菜單的快捷鍵;

2 )通過 inst.ks 關鍵字指明 ks.cfg 文件位置;

3 ) inst.stages2 標識的是系統按照介質位置,這裡使用 hd:LABEL 表明尋找的是 label 為 CENTOS7 的安裝介質,使用 LABEL 關鍵字的好處是可以精確指定安裝介質,為什麼 label 是 CENTOS7 ,是因為我在制作光盤鏡像的時候指定的,方法在後面有介紹。

4 配置 EFI 引導方式

1 ) EFI 簡介

EFI 可擴展固件接口( ExtensibleFirmware Interface 的縮寫),是英特爾主導推出的一種替代 BIOS 的升級方案。最早由英特爾開發,於 2005 年將此規范格式交由 UEFI 論壇來推廣與發展,後來並更改名稱為 Unified EFI(UEFI) 。 UEFI 論壇於 2007 年 1 月 7 日釋出並發放 2.1 版本的規格,其中增加與改進了加密編碼( cryptography )、網絡認證( network authentication )與用戶接口架構( User Interface Architecture )。

EFI 是用模塊化, C 語言風格的參數堆棧傳遞方式,動態鏈接的形式構建的系統,較 BIOS 而言更易於實現,容錯和糾錯特性更強,縮短了系統研發的時間。

EFI 在概念上非常類似於一個低階的操作系統,並且具有操控所有硬件資源的能力。

2 )配置 EFI 引導

進入光盤目錄 EFI/BOOT/ ,編輯 grub.cfg 文件,添加自己的菜單:
menuentry 'Install CentOS 7' --class Fedora--class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CENTOS7 quiet
initrdefi /images/pxeboot/initrd.img
}
menuentry 'Install CentOS 7 custom byxiaoli110' --class fedora --class gnu-linux --class gnu --class os {
linuxefi /images/pxeboot/vmlinuz inst.ks=cdrom:/isolinux/ks.cfginst.stage2=hd:LABEL=CENTOS7 quiet
initrdefi /images/pxeboot/initrd.img
}


和 mbr 方式類似,指明 ks.cfg 文件位置和安裝源位置。

5 生成 iso 鏡像

經過我踩過多個坑,成功的生成鏡像,並且能在 EFI 和 mbr 環境安裝的鏡像生成命令如下:
genisoimage -v -cache-inodes -joliet-long -R -J -T -V CENTOS7 -o /root/centos7.iso \
-c isolinux/boot.cat -bisolinux/isolinux.bin \
-no-emul-boot -boot-load-size 4-boot-info-table \
-eltorito-alt-boot -b images/efiboot.img -no-emul-boot .

( 1 )中間踩過的幾個坑:

1 )制作鏡像要使用 CentOS7 的系統,不要使用 CentOS6 的系統,因為兩者系統的 genisoimage 命令的版本不一樣, 6 的系統制作出來的 iso 不能在 efi 環境啟動;

2 )如果要在 efi 啟動,需要添加如下參數:
-eltorito-alt-boot -bimages/efiboot.img -no-emul-boot

3 )通過 -V 參數指定光盤 label

( 2 ) genisoimage 命令參數簡介

-o 指定映像文件的名稱。

-b 指定在制作可開機光盤時所需的開機映像文件。

-c 制作可開機光盤時,會將開機映像文件中的 no-eltorito-catalog 全部內容作成一個文件。

-no-emul-boot 非模擬模式啟動。

-boot-load-size 4 設置載入部分的數量。

-boot-info-table 在啟動的圖像中現實信息。

-joliet-long 使用 joliet 格式的目錄與文件名稱,長文件名支持。

-R 或 -rock 使用 Rock RidgeExtensions 。

-J 或 -joliet 使用 Joliet 格式的目錄與文件名稱。

-v 或 -verbose 執行時顯示詳細的信息。

-T 或 -translation-table 建立文件名的轉換表,適用於不支持 Rock Ridge Extensions 的系統上。

( 3 ) genisoimage 、 mkisofs 、 xorrios 幾個命令的區別

說起 genisoimage 和 mkisofs ,其實裡面是有點故事的。

最早的時候, Linux 系統使用 cdrtools 工具來管理 iso 及光盤, mkisofs 是 cdrtools 裡面的一個工具,後來 cdrtools 更好了了授權許可,從 GPL 修改為 CDDL 許可,開源社區又推出了一套基於 GPL 的工具, cdrkit , mkisofs 也被 genisoimage 去掉,現在系統中的 mkisofs 實際是 genisoimage 的軟連接:
ls -l /usr/bin/mkisofs
/usr/bin/mkisofs ->/etc/alternatives/mkisofs
ls -l /etc/alternatives/mkisofs
/etc/alternatives/mkisofs ->/usr/bin/genisoimage

xorrios 是另外一個比較流行的制作 iso 鏡像的工具,並且有一個參數 -asmkisofs 可以和 mkiso 命令兼容。

更多CentOS相關信息見CentOS 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=14

Copyright © Linux教程網 All Rights Reserved