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