1. 镜像源
历史版本下载地址:http://old-releases.ubuntu.com/releases/
选择服务器版本64位adm架构的镜像作为安装源,例如:ubuntu-18.04.4-server-amd64.iso。(此种版本无需连公网,安装源包含所有安装信息)
如果想使用最新版本作为安装源,只能找到live版,例如ubuntu-20.04-live-server-amd64.iso。(此种版本需要连公网,或是能访问到软件源地址,以便装机过程中安装必要的软件)
2. 引导文件
- pxe的菜单可参考如下:
label Ubuntu 18.X
menu label Ubuntu 18.X
kernel http://192.168.8.101/iso/ubuntu-18.04/install/netboot/ubuntu-installer/amd64/linux
append initrd=http://192.168.8.101/iso/ubuntu-18.04/install/netboot/ubuntu-installer/amd64/initrd.gz preseed/url=http://192.168.8.101/ks/preseed.cfg ksdevice=bootif net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe ip=dhcp
ipappend 2
- 自动选择语言、键盘、国家
方法1:如下三项添加到pxe菜单中
debian-installer/locale=en_US
keyboard-configuration/layoutcode=us
netcfg/get_hostname=unassigned-hostname
方法2:添加到pxe环境中
解压安装源中的/install/netboot/ubuntu-installer/amd64/initrd.gz文件,在解压后的根目录下创建preseed.cfg、
# 解压命令参考
gzip -d initrd.gz
cpio -ivmd < ../initrd
# 添加文件内容参考
[root@pxe-01 rootfs]# ls
bin dev etc init initrd lib lib64 media mnt preseed.cfg proc run sbin sys tmp usr var
[root@pxe-01 rootfs]# cat preseed.cfg
d-i debian-installer/locale string en_US
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/xkb-keymap select us
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string ubuntu18
d-i netcfg/get_domain string localdomain
# 压缩
find .|cpio -o -H newc |gzip > ../initrd.gz
3. 应答文件
仅供参考
# 安装前将debconf命令的优先级调高,这样可防止不必要的弹窗
d-i auto-install/enable boolean true
d-i debconf/priority string critical
# 选择语言
d-i debian-installer/locale string en_US
d-i localechooser/supported-locales multiselect en_US.UTF-8
# 选择键盘
d-i console-setup/ask_detect boolean false
d-i keyboard-configuration/layoutcode string us
d-i keyboard-configuration/xkb-keymap select us
# 选择获取ip地址的方式和主机名
d-i netcfg/choose_interface select auto
d-i netcfg/get_hostname string unassigned-hostname
d-i netcfg/get_domain string localdomain
d-i netcfg/wireless_wep string
# 选择国家,这里可以为空
d-i mirror/country string manual
# 选择访问公网时的代理服务
#d-i mirror/http/proxy string http://192.168.192.8:8088
d-i mirror/http/proxy string
# 选择镜像所在国家,最好选上中国的
d-i mirror/http/mirror select cn.archive.ubuntu.com
# 账号密码的一些配置
d-i passwd/root-login boolean true
d-i passwd/make-user boolean false
d-i passwd/root-password-crypted password $6$EBSccHsW$DuRH3N5t9UEYjuICQ7Q1eAHDCF68zHHcnN5P0QSWDyPVcaTMKhXsgZ2o0Ly7iwSgSo7f3tz9G9tqbgxXK2vQl/
#d-i passwd/root-password password r00tme
#d-i passwd/root-password-again password r00tme
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
# 是否时间同步
d-i time/zone string Asia/Shanghai
d-i clock-setup/ntp-server string ntp.ubuntu.com
d-i clock-setup/utc boolean true
d-i clock-setup/ntp boolean true
# This first command is run as early as possible, just after preseeding is read.
# 当本文件读取后,先运行如下命令
d-i preseed/early_command string \
echo $(grep dhcp-server-identifier /var/lib/dhcp/dhclient* |tail -n1 |egrep -o '([0-9]{1,3}\.){3}[0-9]{1,3}') > /tmp/pxe_server;\
wget -O /tmp/ubuntu_preseed_early_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_preseed_early_script.sh ;\
sh /tmp/ubuntu_preseed_early_script.sh ;\
debconf-set-selections /tmp/preseed_early.cfg
#ubuntu_preseed_early_script.sh脚本用于生成/tmp/preseed_early.cfg,然后再包含到本文件中来,被包含的内容如下
#(这里也需要注意下,如果安装Ubuntu最新版,将此处配置为公网的软件源)
#d-i mirror/http/hostname string 192.168.192.8
#d-i mirror/http/directory string /iso/ubuntu-18.04
#d-i live-installer/net-image string http://192.168.192.8/iso/ubuntu-18.04/install/filesystem.squashfs
# This command is run immediately before the partitioner starts.
d-i partman/early_command string \
wget -O /tmp/ubuntu_partman_early_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_partman_early_script.sh ;\
sh /tmp/ubuntu_partman_early_script.sh ;\
debconf-set-selections /tmp/partman_early.cfg
#ubuntu_partman_early_script.sh脚本用于生成/tmp/partman_early.cfg,其内容如下
#d-i partman-auto/disk string /dev/sdb
#d-i grub-installer/bootdev string /dev/sdb
#d-i partman-auto/expert_recipe string \
# boot-root :: \
# 2 4 2 free \
# $iflabel{ gpt } \
# method{ biosgrub } \
# . \
# 1536 3 1536 ext4 \
# $primary{ } $bootable{ } \
# method{ format } format{ } \
# use_filesystem{ } filesystem{ ext4 } \
# mountpoint{ /boot } \
# . \
# 8192 2 8192 linux-swap \
# method{ swap } format{ } \
# . \
# 10240 1 -1 ext4 \
# $primary{ } \
# method{ format } format{ } \
# use_filesystem{ } filesystem{ ext4 } \
# mountpoint{ / } \
# .
# This command is run just before the install finishes.
# 安装完成之后执行初始化脚本
d-i preseed/late_command string \
cp /tmp/pxe_server /target/opt/pxe_server; \
in-target wget -O /opt/ubuntu_preseed_late_script.sh http://$(cat /tmp/pxe_server)/scripts/ubuntu_preseed_late_script.sh; \
in-target bash /opt/ubuntu_preseed_late_script.sh
# 远程执行脚本
#d-i preseed/run string http://192.168.192.8/scripts/ubuntu_preseed_run_script.sh
# 相当于ks的include,但是它访问的是网络上的文件,而不是本地文件
#d-i preseed/include_command string debconf-set grub-installer/bootdev `cat /tmp/os_disk`
# 使用的盘符和分区方法
d-i partman-auto/disk string default
d-i partman-auto/method string regular
d-i partman/unmount_active boolean true
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-md/device_remove_md boolean true
d-i partman-lvm/confirm boolean true
d-i partman-basicfilesystems/choose_label string gpt
d-i partman-basicfilesystems/default_label string gpt
d-i partman-partitioning/choose_label string gpt
d-i partman-partitioning/default_label string gpt
d-i partman/choose_label string gpt
d-i partman/default_label string gpt
d-i partman-partitioning/choose_label select gpt
d-i partman-auto/choose_recipe select boot-root
d-i partman-partitioning/confirm_write_new_label boolean true
#d-i partman/choose_partition select finish
d-i partman/choose_partition select Finish partitioning and write changes to disk
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# Use the following option to add additional boot parameters for the installed system
d-i debian-installer/add-kernel-opts string nousb net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe
# The kernel image (meta) package to be installed; "none" can be used if no kernel is to be installed.
d-i base-installer/kernel/image string linux-generic
# 最终也会配置到/etc/apt/sources.list里面
d-i apt-setup/security_host string 192.168.192.8
d-i apt-setup/security_path string /iso/ubuntu-18.04
# 安装时是否验证,注释与否好像影响不大
d-i debian-installer/allow_unauthenticated boolean true
# 安装系统的版本和软件
tasksel tasksel/first multiselect standard system utilities, OpenSSH server
d-i pkgsel/include string openssh-server vim
# 是否自动升级
d-i pkgsel/upgrade select none
d-i pkgsel/language-packs multiselect en, zh
d-i pkgsel/update-policy select none
# 安装grub
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean false
d-i finish-install/reboot_in_progress note
4. 启动画面
将图形界面启动改成文本启动
修改:/etc/default/grub
- 将
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
改为GRUB_CMDLINE_LINUX_DEFAULT="text"
- 取消注释
GRUB_TERMINAL=console
- 更新grub,执行
update-grub
- 设置默认启动级别,执行
systemctl set-default multi-user.target
5. 其它常用设置
允许root登录
sed -i s/prohibit-password/yes/g /etc/ssh/sshd_config
sed -i s/\#PermitRootLogin/PermitRootLogin/g /etc/ssh/sshd_config
取消重启清空/tmp
echo 'd /tmp 1777 root root 30d' >> /etc/tmpfiles.d/tmp.conf
6. pxe环境添加工具
dpkg -X 软件包名称.deb ./rootfs