首页 > 技术文章 > 定制 ISO

Tzyyviki 2021-04-19 18:29 原文

定制 ISO


0. 应用场景

目前很多整机厂商都会进行操作系统出厂预装,并根据项目或环境需求在操作系统中定制安装一些补丁以及软件或配置,且在规模较大的环境中需要进行 PXE 安装,故以下介绍下如何定制化制作出厂 ISO

此文档使用基础操作系统版本:Kylin-Desktop-V10-Release-Build1-20200710-arm64.iso,下文中简称为基础版本

U 系(ubuntu 系列)操作系统同样适用此方法


1. 创建目录

# cd /root
# mkdir mnt live tool

创建目录用途:
mnt:作为镜像挂载目录
live:作为工作目录
tool:作为工具目录


2. 上传定制系统基础镜像至 /root/tool 中,且挂载至 mnt 下

上传定制基础操作系统镜像至 /root/tool,例如:使用 U 盘拷贝基础镜像到之前创建的工具目录中( /root/tool )

挂载镜像至创建的挂载目录
# mount  /root/tool/Kylin-Desktop-V10-Release-Build1-20200710-arm64.iso  /root/mnt

3. 复制镜像中所有文件至 live 下

# cp -rp /root/mnt/.  /root/live

4. 取消挂载

# umount /root/mnt

5. 解压 filesystem.squashfs

# cd /root/live/casper
# unsquashfs filesystem.squashfs

解压后目录为:squashfs-root


6. 切换至新系统中

# chroot squashfs-root
# mount -t proc none /proc
# mount -t sysfs none /sys
# mount -t devpts none /dev/pts

7. 定制化操作系统

可根据自身需求进行定制,如:升级更新软件包,安装第三方软件,修改配置等


7.1 软件源更新

修改DNS,安装源⽂件,复制本机已经配置好的DNS和安装源给需要定制的系统机器,先退出 squashfs-root 系统

# exit
# cp  /etc/apt/sources.list  /root/live/casper/squashfs-root/etc/apt/sources.list
# cp  /etc/resolv.conf  /root/live/casper/squashfs-root/etc/resolv.conf

再次进入 squashfs-root 系统 
# chroot squashfs-root
# apt update
可使用源更新系统或安装第三方软件等

7.2 完成配置,清除系统

# apt-get clean
# apt-get autoremove
# rm -rf /tmp/*
# umount /proc
# umount /sys
# umount /dev/pts
# history -c
# history -w
# exit

8. 重新配置并压缩根文件系统

# cd /root/live/casper

删除原来的操作系统压缩文件
# rm -rf filesystem.squashfs

压缩操作系统
# mksquashfs squashfs-root filesystem.squashfs -comp xz

更新大小
# printf $(du -sx --block-size 1 squashfs-root | cut -f1) > filesystem.size

删除解压操作系统
# rm -rf squashfs-root

更新 md5 值
# cd /root/live
# rm md5sum.txt
# find -type f -print0 | xargs -0 md5sum|grep -v isolinux/boot.cat | tee md5sum.txt

9. 制作定制 ISO 镜像

# mkisofs -r -T -J -joliet-long -m lost+found -m rr_moved -quiet -c boot.catalog -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot -V 'Kylin-Desktop-V10-testyv' -sysid 'LINUX' -o '/root/Kylin-Desktop-V10-testyv' /root/live

-V:为 ISO 挂载后显示名称

-o:第一个参数为定制完的镜像生成位置以及名称,第二个参数为工作目录

通过上面的命令生成的 ISO 即可以采用 UEFI 的方式进行安装,也可以采用 leagcy 的方式进行安装

推荐阅读