1. 鏡像源
歷史版本下載地址:http://old-releases.ubuntu.com/releases/
選擇服務(wù)器版本64位adm架構(gòu)的鏡像作為安裝源,例如:ubuntu-18.04.4-server-amd64.iso。(此種版本無需連公網(wǎng)末贾,安裝源包含所有安裝信息)
如果想使用最新版本作為安裝源,只能找到live版构回,例如ubuntu-20.04-live-server-amd64.iso。(此種版本需要連公網(wǎng)绣张,或是能訪問到軟件源地址惕蹄,以便裝機過程中安裝必要的軟件)
2. 引導(dǎo)文件
- 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環(huán)境中
解壓安裝源中的/install/netboot/ubuntu-installer/amd64/initrd.gz文件,在解壓后的根目錄下創(chuàng)建preseed.cfg裂问、
# 解壓命令參考
gzip -d initrd.gz
cpio -ivmd < ../initrd
# 添加文件內(nèi)容參考
[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. 應(yīng)答文件
僅供參考
# 安裝前將debconf命令的優(yōu)先級調(diào)高侧啼,這樣可防止不必要的彈窗
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
# 選擇訪問公網(wǎng)時的代理服務(wù)
#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āng)本文件讀取后痊乾,先運行如下命令
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,然后再包含到本文件中來椭更,被包含的內(nèi)容如下
#(這里也需要注意下哪审,如果安裝Ubuntu最新版,將此處配置為公網(wǎng)的軟件源)
#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虑瀑,其內(nèi)容如下
#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.
# 安裝完成之后執(zhí)行初始化腳本
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
# 遠程執(zhí)行腳本
#d-i preseed/run string http://192.168.192.8/scripts/ubuntu_preseed_run_script.sh
# 相當(dāng)于ks的include湿滓,但是它訪問的是網(wǎng)絡(luò)上的文件,而不是本地文件
#d-i preseed/include_command string debconf-set grub-installer/bootdev `cat /tmp/os_disk`
# 使用的盤符和分區(qū)方法
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
# 安裝系統(tǒng)的版本和軟件
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叽奥,執(zhí)行
update-grub
- 設(shè)置默認啟動級別,執(zhí)行
systemctl set-default multi-user.target
5. 其它常用設(shè)置
允許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環(huán)境添加工具
dpkg -X 軟件包名稱.deb ./rootfs