1 復(fù)制光盤文件
1)掛載iso鏡像
創(chuàng)建目錄用于掛載光盤:
mkdir /root/centos7
掛載iso鏡像
mount -o loop CentOS-7.0-1406-x86_64-DVD.iso/root/centos7
2)復(fù)制光盤文件到編輯目錄進(jìn)行編輯
因?yàn)閽燧d上iso鏡像是只讀的,如果要編輯,需要將文件復(fù)制出來,再編輯。
首先創(chuàng)建編輯目錄:
mkdir /root/centos7_iso
復(fù)制光盤文件:
cp -rf /root/centos7/* /root/centos7_iso/
diskinfo文件需求單獨(dú)拷貝下:
cp /root/centos7/.discinfo /root/iso
2 編輯ks.cfg文件
系統(tǒng)安裝的時(shí)候,按照ks.cfg文件的內(nèi)容進(jìn)行安裝,我們把ks.cfg文件放到isolinux目錄下:
cd /root/centos7_iso/isolinux
vim ks.cfg
我的ks.cfg文件內(nèi)容如下:
#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)因?yàn)镃entOS7系統(tǒng)網(wǎng)卡規(guī)則更復(fù)雜,為了ks.cfg更通用,最好ks.cfg不用制定網(wǎng)卡配置。
2)為了兼容mbr方式和EFI方式,同時(shí)創(chuàng)建了/boot和/boot/efi分區(qū)。
3配置mbr引導(dǎo)方式
編輯isoliuux目錄下的isolinux.cfg文件,添加自己的內(nèi)容,在isolinux.cfg文件中l(wèi)abel 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
注意點(diǎn):
1)memu label 后面的內(nèi)容是在光盤引導(dǎo)起來菜單的內(nèi)容,^后面的字母是菜單的快捷鍵;
2)通過inst.ks關(guān)鍵字指明ks.cfg文件位置;
3)inst.stages2標(biāo)識(shí)的是系統(tǒng)按照介質(zhì)位置,這里使用hd:LABEL表明尋找的是label為CENTOS7的安裝介質(zhì),使用LABEL關(guān)鍵字的好處是可以精確指定安裝介質(zhì),為什么label是CENTOS7,是因?yàn)槲以谥谱鞴獗P鏡像的時(shí)候指定的,方法在后面有介紹。
4 配置EFI引導(dǎo)方式
1)EFI簡(jiǎn)介
EFI可擴(kuò)展固件接口(ExtensibleFirmware Interface 的縮寫),是英特爾主導(dǎo)推出的一種替代BIOS的升級(jí)方案。最早由英特爾開發(fā),于2005年將此規(guī)范格式交由UEFI論壇來推廣與發(fā)展,后來并更改名稱為Unified EFI(UEFI)。UEFI論壇于2007年1月7日釋出并發(fā)放2.1版本的規(guī)格,其中增加與改進(jìn)了加密編碼(cryptography)、網(wǎng)絡(luò)認(rèn)證(network authentication)與用戶接口架構(gòu)(User Interface Architecture)。
EFI是用模塊化,C語言風(fēng)格的參數(shù)堆棧傳遞方式,動(dòng)態(tài)鏈接的形式構(gòu)建的系統(tǒng),較BIOS而言更易于實(shí)現(xiàn),容錯(cuò)和糾錯(cuò)特性更強(qiáng),縮短了系統(tǒng)研發(fā)的時(shí)間。
EFI在概念上非常類似于一個(gè)低階的操作系統(tǒng),并且具有操控所有硬件資源的能力。
2)配置EFI引導(dǎo)
進(jìn)入光盤目錄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鏡像
經(jīng)過我踩過多個(gè)坑,成功的生成鏡像,并且能在EFI和mbr環(huán)境安裝的鏡像生成命令如下:
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)中間踩過的幾個(gè)坑:
1)制作鏡像要使用CentOS7的系統(tǒng),不要使用CentOS6的系統(tǒng),因?yàn)閮烧呦到y(tǒng)的genisoimage命令的版本不一樣,6的系統(tǒng)制作出來的iso不能在efi環(huán)境啟動(dòng);
2)如果要在efi啟動(dòng),需要添加如下參數(shù):
-eltorito-alt-boot -bimages/efiboot.img -no-emul-boot
3)通過-V參數(shù)指定光盤label
(2)genisoimage命令參數(shù)簡(jiǎn)介
-o 指定映像文件的名稱。
-b指定在制作可開機(jī)光盤時(shí)所需的開機(jī)映像文件。
-c 制作可開機(jī)光盤時(shí),會(huì)將開機(jī)映像文件中的no-eltorito-catalog全部?jī)?nèi)容作成一個(gè)文件。
-no-emul-boot 非模擬模式啟動(dòng)。
-boot-load-size 4 設(shè)置載入部分的數(shù)量。
-boot-info-table 在啟動(dòng)的圖像中現(xiàn)實(shí)信息。
-joliet-long 使用 joliet 格式的目錄與文件名稱,長(zhǎng)文件名支持。
-R 或 -rock 使用 Rock RidgeExtensions 。
-J 或 -joliet 使用 Joliet 格式的目錄與文件名稱。
-v 或 -verbose 執(zhí)行時(shí)顯示詳細(xì)的信息。
-T 或-translation-table 建立文件名的轉(zhuǎn)換表,適用于不支持 Rock Ridge Extensions 的系統(tǒng)上。
(3)genisoimage、mkisofs、xorrios幾個(gè)命令的區(qū)別
說起genisoimage和mkisofs,其實(shí)里面是有點(diǎn)故事的。
最早的時(shí)候,Linux系統(tǒng)使用cdrtools工具來管理iso及光盤,mkisofs是cdrtools里面的一個(gè)工具,后來cdrtools更好了了授權(quán)許可,從GPL修改為CDDL許可,開源社區(qū)又推出了一套基于GPL的工具,cdrkit,mkisofs也被genisoimage去掉,現(xiàn)在系統(tǒng)中的mkisofs實(shí)際是genisoimage的軟連接:
ls -l /usr/bin/mkisofs
/usr/bin/mkisofs ->/etc/alternatives/mkisofs
ls -l /etc/alternatives/mkisofs
/etc/alternatives/mkisofs ->/usr/bin/genisoimage
xorrios是另外一個(gè)比較流行的制作iso鏡像的工具,并且有一個(gè)參數(shù)-asmkisofs可以和mkiso命令兼容。