制作Ubuntu/Centos自动安装 ISO

目标

1、达到系统自动安装,不需要人机交互
2、自定义操作系统(开机界面、默认账户等等)

环境和软件工具

环境:Linux Ubuntu/CentOS操作系统
软件:mkisofs,xorriso

CentOS : yum install mkisofs xorriso -y
Ubuntu: sudo apt install -y mkisofs xorriso

Ubuntu ISO

Ubuntu通过seed文件来指定安装过程,所以需要自定义seed文件,然后修改grub文件来指定执行的seed文件
如:
menuentry ‘Install Ubuntu’ {undefined
set background_color=black
linux /install/vmlinuz auto-install/enable=true file=/cdrom/preseed/ubuntu.seed
initrd /install/initrd.gz

添加自定义deb包
mkdir dists/stable/extras/binary-arm64 -p
mkdir -p pool/extras
cp …/apps-nfv_1.0_arm64.deb pool/extras/

apt-ftparchive packages ./pool/extras/ > dists/stable/extras/binary-arm64/Packages
gzip -c ./dists/stable/extras/binary-arm64/Packages | tee ./dists/stable/extras/binary-arm64/Packages.gz
rm dists/stable/extras/binary-arm64/Packages
添加dists/stable/extras/binary-arm64/Release文件
在dists/stable/Release中添加3条记录(Packages.gz、Packages、Release)
添加debian_installer目录,并更新到Release文件

Release.gpg、md5sum.txt文件可以删除,暂时没用

openssh-server unzip zip net-tools vim tcpdump

deb打包
dpkg-deb -b apps_deb/ test_1.0_all.deb

修改grub超时时间
GRUB_TIMEOUT_STYLE=ountdown
GRUB_RECORDFAIL_TIMEOUT=3
GRUB_TIMEOUT=2
update-grub

服务裁剪
systemctl disable accounts-daemon.service
systemctl disable apparmor.service
systemctl disable dbus-org.freedesktop.resolve1.service
systemctl disable irqbalance.service
systemctl disable keyboard-setup.service
systemctl disable ondemand.service
systemctl disable setvtrgb.service
systemctl disable systemd-timesyncd.service
systemctl disable ufw.service
systemctl disable remote-fs.target
systemctl disable apt-daily-upgrade.timer
systemctl disable apt-daily.timer
systemctl disable motd-news.timer
systemctl disable ua-messaging.timer

systemctl edit getty@tty1

##重新打包

打包arm64 iso
xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 -V ‘my-Server V1.0 arm64’
-o ./test.iso -J -joliet-long -cache-inodes -e boot/grub/efi.img -no-emul-boot ubx86_18-05/

打包x86_64 iso
xorriso -as mkisofs -r -checksum_algorithm_iso md5,sha1 -V ‘my-Server V1.0 x8664’ -b isolinux/isolinux.bin -c isolinux/boot.cat
-boot-load-size 4 -boot-info-table -o ./test.iso -J -joliet-long -cache-inodes -no-emul-boot testub/

参考资料:

https://blog.csdn.net/zouyee/article/details/48417775
https://help.ubuntu.com/lts/installation-guide/example-preseed.txt?_ga=2.132254985.66094557.1640253728-26264599.1623229448
http://www.javashuo.com/article/p-duplocjb-kc.html
https://blog.csdn.net/hbuxiaofei/article/details/85619021
https://help.ubuntu.com/lts/installation-guide/amd64/apb.html
https://blog.csdn.net/kyle__shaw/article/details/8938787
https://blog.csdn.net/weixin_31081677/article/details/116916754

Centos ISO

https://fedoraproject.org/wiki/Anaconda/Kickstart/zh-cn#Creating_a_Kickstart_Boot_Diskette
https://vault.centos.org/

[cdrom]
name=CentOS7 - cdrom
baseurl=file:///mnt/cdrom/
enable=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

新增软件包:
net-tools-2.0-0.52.20160912git.el8.x86_64

systemctl list-unit-files | grep enable
1、/etc/sysconfig设置静态IP
2、关闭selinux
3、拷贝unzip工具
4、ln -s python工具
3、[root@localhost ~]# yum install net-tools
7560368
7557900
[root@localhost ~]# systemctl stop NetworkManager.service
[root@localhost ~]# systemctl disable NetworkManager.service
[root@localhost ~]# systemctl stop sssd.service
[root@localhost ~]# systemctl disable sssd.service
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# systemctl list-unit-files | grep enable
[root@localhost ~]# systemctl disable selinux-autorelabel-mark.service
[root@localhost ~]# systemctl disable auditd.service
[root@localhost ~]# systemctl disable irqbalance.service
[root@localhost ~]# systemctl disable vgauthd.service
[root@localhost ~]# systemctl disable vmtoolsd.service
[root@localhost ~]# systemctl disable tuned.service
[root@localhost ~]# systemctl disable remote-fs.target
[root@localhost ~]# systemctl disable nis-domainname.service
[root@localhost ~]# systemctl disable kdump.service
[root@localhost ~]# systemctl disable dbus-org.freedesktop.nm-dispatcher.service
[root@localhost ~]# systemctl disable dbus-org.freedesktop.timedate1.service
[root@localhost ~]# systemctl disable chronyd.service //时间同步
[root@localhost ~]# systemctl disable dnf-makecache.timer //更新相关
[root@localhost ~]# systemctl disable unbound-anchor.timer //dns相关

systemctl disable irqbalance.service

设置grub nopku

mount -t hugetlbfs nodev /mnt/huge_1GB -o “pagesize=1GB”
mount -t hugetlbfs nodev /mnt/huge/ -o “pagesize=2MB”

新增软件包可以直接在ks.cfg @packages 项后面加。
createrepo --xz -g comps.xml .
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/installation_guide/s1-kickstart2-options
http://docs.fedoraproject.org/en-US/index.html
#System authorization information
auth --useshadow --passalgo=sha512
#Use graphical install
graphical 注:这里改为text即为安装时为字符界面安装
firstboot --disable
#SELinux configuration
selinux --disabled
grubby --update-kernel=/boot/vmlinuz-4.18.0-80.7.1.el8_0.x86_64 --args=console=ttyS0,115200

awk ‘{if(ARGIND==1) {val[$0]}else{if($0 in val) print $0}}’ /root/bs.log /root/install_rpm.log
awk ‘{print $0}’ /root/install.log |xargs -i cp /media/AppStream/Packages/{}.rpm /root/myiso/AppStream/Packages/
awk ‘{print $0}’ /root/install.log |xargs -i cp /media/BaseOS/Packages/{}.rpm /root/myiso/BaseOS/Packages/

grubby --update-kernel=ALL --args=“default_hugepagesz=1G hugepagesz=1G hugepages=6 nopku”
grubby --update-kernel=ALL --args=“default_hugepagesz=1G hugepagesz=1G hugepages=1 isolcpus=3-7 nohz_full=3-7 rcu_nocbs=3-7 nopku”
mkisofs -o my1.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat
-no-emul-boot -boot-load-size 4 -boot-info-table -R -J -v -T -joliet-long /root/myiso/
implantisomd5 Pan-7.3.iso




centOS操作步骤:
1、获取需要安装的包列表
rpm -qa >> /root/install.log

2、拷贝文件
awk '{print $0}' /root/install.log |xargs -i cp /home/**/AppStream/Packages/{}.rpm /home/***/AppStream/Packages/
awk '{print $0}' /home/testinstall.log |xargs -i cp /home/**/BaseOS/Packages/{}.rpm /home/**/BaseOS/Packages/

#删除多余程序
man-db

3、设置ks.cfg文件
# Firewall configuration
firewall --disabled

# SELinux configuration
selinux --disabled

# Generated using Blivet version 3.6.0
ignoredisk --only-use=sda
autopart
# Partition clearing information
clearpart --all --initlabel

timesource --ntp-disable
# System timezone
timezone Asia/Shanghai --utc

#设置安装完自动重启
reboot

#添加额外软件包
%packages
@^minimal-environment
samba
net-tools
gdb
unzip
network-scripts
iotop
tcpdump
%end

4、制作自定义rpm包,打包自己的文件或安装程序
rpmbuild -bb 1.spec
cp ../RPMS/x86_64/test-1.0-1.x86_64.rpm /home/**/BaseOS/Packages/


5、重新生产repo源
#rpm包不一定和xml文件内容完全匹配,重新生成createrepo即可。(xml文件中的包list可以大于实际存在的rpm包)
createrepo --xz  -g ../app-coms-AppStream.x86_64.xml  AppStream/
createrepo --xz  -g ../base-coms-BaseOS.x86_64.xml  BaseOS/
#用mkisofs生成ISO时加上-T参数,即可给所有目录下生成TRANS.TBL文件,此文件可有可无

6、修改isolinux.cfg
#myOS与打包iso时的参数-V对应, 需要一致。inst.stage2为安装介质位置,hd:LABEL为介质标签
append initrd=initrd.img linux inst.ks=cdrom:/isolinux/dp.cfg inst.stage2=hd:LABEL=myOS quiet

7、打包iso文件
mkisofs -o test.iso -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot  -b image/efiboot.img  -no-emul-boot -R -J -v -T -joliet-long -V myOS /home/**/ 
//同时支持uefi和bios方式的话需要增加-eltorito-alt-boot  -b image/efiboot.img  -no-emul-boot
8#计算md5
implantisomd5 test.iso


#其他
1、reboot时的标题菜单可以在安装完/boot/loader/entries/*.conf配置文件中修改。(未找到安装时如何修改)
2、如果将iso再制作为usb启动盘,需要做如下修改:
》修改grub.cfg或isolinux.cfg中的盘符名字,将cdrom修改为具体盘符(盘符在生成的usb盘符文件中可以看到)
》修改cfg文件installation media
》修改repo路径
例如:
repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-hdd-device/AppStream

# Use hard drive installation media(删除原来的cdrom  installation media cdrom)
harddrive --dir= --partition=LABEL=CENTOS-STRE








参考资料

https://blog.csdn.net/vic_qxz/article/details/100263801

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值