CentOS 7.0全自動安裝光碟片製作詳解

來源:互聯網
上載者:User

CentOS 7.0全自動安裝光碟片製作詳解

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 命令相容。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.