需求
通常在安装ubuntu操作系统时,需要手工去选择安装过程中出现的问题,如地区、网络、分区等的设置。但是当需要大批量安装操作系统时,手工的方式就会很繁琐,效率低下,因此就有了自动化安装的需求。
ubuntu提供的方案是通过设置preseed文件对上述问题直接设置答案或者直接跳过的方式实现全自动化安装(注:官方下载的ubuntu-18.04.5-server-amd64.iso安装时如无特殊情况就是自动安装的,是因为内置了preseed文件)
本次制作主要解决的问题:
- 1、多网卡自动选择
- 2、多硬盘自动选择
- 3、自定义shell脚本执行
- 4、grub自动选择安装
- 其他配置不做特殊说明,属于常规内容
看下preseed文件所在iso中的位置

这是对iso镜像中包含的内容

除了custom.seed,其他均是自带的
注:本次安装是通过添加preseed文件后重新构建iso镜像(也就是通过CD的方式)实现自动化安装系统
环境
1、服务器一台(虚拟机),可联网
2、操作系统: ubuntu-18.04.5-server-amd64
3、iso镜像:ubuntu-18.04.5-server-amd64.iso
4、vmware-15.5
5、制作系统架构:amd64(下一步制作arm)
实现
定制过程说明
1、将ISO中内容复制出来
2、创建 custom.seed 文件,名称自定
3、修改 isolinux.cfg,让其识别自定义的preseed文件
4、修改 grub.cfg,让其识别自定义的preseed文件
5、apt离线源制作及shell脚本编写
6、制作ISO,使用的工具为mkisofs
具体实现
1、拷贝ubuntu-18.04.5-server-amd64.iso镜像至服务器任意路径,本文全部以 /home/hy 目录为准
2、挂载拷贝iso文件
mkdir /home/hy/mnt # 用于挂载iso镜像
mkdir /home/hy/livecd # 将iso内容拷贝到这里
mount ubuntu-18.04.5-server-amd64.iso /home/hy/mnt # 挂载之后可以看到mnt内有文件了
cp -rT /home/hy/mnt/ /home/hy/livecd # 拷贝出来到livecd目录内,便于后边修改
3、编辑custom.seed文件 重点
vim /home/hy/livecd/preseed/custom.seed
涉及内容如下:
# Language:
d-i debian-installer/locale string en_US.UTF-8
# Keyboard selection.
d-i console-setup/ask_detect boolean false
d-i console-setup/layoutcode string us
# Suggest LVM by default.
d-i partman-auto/init_automatically_partition string some_device_lvm
d-i partman-auto/init_automatically_partition seen false
# 多硬盘情况下,这里设置选择 /dev/sda,即第一个硬盘
d-i partman-auto/disk string /dev/sda
# 可供设置参数有lvm、regular(常规)、crypto(加密)
d-i partman-auto/method string lvm
d-i partman-lvm/confirm boolean true
d-i partman/choose_partition select finish
d-i partman-lvm/confirm_nooverwrite boolean true
d-i partman-auto-lvm/guided_size string max
# 可选参数,atomic(所有文件在一个分区)、home、multi
d-i partman-auto/choose_recipe select atomic
# 下述配置使得partman无需确认即可自动分区
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/choose_partition select finish
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# Install the Ubuntu Server seed.
tasksel tasksel/force-tasks string server
# Only install basic language packs. Let tasksel ask about tasks.
d-i pkgsel/language-pack-patterns string
# No language support packages.
d-i pkgsel/instal

这篇博客详细介绍了如何通过预seed文件自动化安装Ubuntu Server操作系统,包括多网卡和多硬盘的选择、自定义shell脚本执行等。文中列举了custom.seed文件的具体配置内容,并提供了挂载ISO、编辑isolinux.cfg和grub.cfg的步骤,以及制作ISO镜像的命令。此外,还提到了apt离线源制作和避免安装过程中卡死的问题。

4467

被折叠的 条评论
为什么被折叠?



