Ubuntu镜像定制化安装实操指南
一、方案总览
二、命令行方式定制可启动 ISO(通用且可脚本化)
sudo apt update && sudo apt install -y squashfs-tools genisoimage isolinux xorrisomkdir -p ~/iso && sudo mount -o loop ubuntu-22.04-live-server-amd64.iso ~/isomkdir -p ~/livecd && cp -rT ~/iso ~/livecdsudo unsquashfs -d ~/squashfs ~/livecd/casper/filesystem.squashfssudo mount --bind /dev ~/squashfs/dev
sudo mount --bind /run ~/squashfs/run
sudo chroot ~/squashfs
mount -t proc proc /proc
mount -t sysfs sys /sys
mount -t devpts devpts /dev/pts
apt update && apt install -y vim htop openssh-server curlapt purge -y somepkg/etc/hostname、/etc/apt/sources.list、时区 timedatectl set-timezone Asia/Shanghai)apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*exit && sudo umount ~/squashfs/{proc,sys,dev/pts,dev,run}sudo rm ~/livecd/casper/filesystem.squashfs && sudo mksquashfs ~/squashfs ~/livecd/casper/filesystem.squashfs -comp xzmd5sum.txt,新版本可能使用 SHA256SUMS,按需处理):(cd ~/livecd && find . -type f -print0 | xargs -0 md5sum | sudo tee md5sum.txt)
sudo xorriso -as mkisofs \
-D -r -V "Custom Ubuntu" \
-cache-inodes -J -l \
-b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot \
-e boot/grub/efi.img -no-emul-boot \
-o custom-ubuntu.iso ~/livecd
三、使用 Cubic 图形化定制 ISO(更快上手)
sudo add-apt-repository ppa:cubic-wizard/releasessudo apt update && sudo apt install -y cubic四、实现无人值守安装 Preseed 示例
custom.seed)preseed/file=/cdrom/preseed/custom.seedLABEL autoinstall
menu label ^Auto Install Ubuntu Server
kernel /install/vmlinuz
append preseed/file=/cdrom/preseed/custom.seed debian-installer/locale=en_US console-setup/layoutcode=us initrd=/install/initrd.gz quiet ---
# Locale and keyboard
d-i debian-installer/locale string en_US.UTF-8
d-i keyboard-configuration/xkb-keymap select us
# Network (use DHCP by default)
d-i netcfg/choose_interface select auto
# Mirror
d-i mirror/country string manual
d-i mirror/http/hostname string mirrors.tuna.tsinghua.edu.cn
d-i mirror/http/directory string /ubuntu
d-i mirror/http/proxy string
# Clock and time zone
d-i clock-setup/utc boolean true
d-i time/zone string Asia/Shanghai
# Partitioning (use entire disk with LVM)
d-i partman-auto/method string lvm
d-i partman-lvm/device_remove_lvm boolean true
d-i partman-auto/purge_lvm_from_device boolean true
d-i partman-auto/choose_recipe select atomic
d-i partman-partitioning/confirm_write_new_label boolean true
d-i partman/confirm boolean true
d-i partman/confirm_nooverwrite boolean true
# User account
d-i passwd/user-fullname string Ubuntu User
d-i passwd/username string ubuntu
d-i passwd/user-password password your_password
d-i passwd/user-password-again password your_password
d-i user-setup/allow-password-weak boolean true
d-i user-setup/encrypt-home boolean false
# Packages
tasksel tasksel/first multiselect ubuntu-server
d-i pkgsel/include string openssh-server vim htop
d-i pkgsel/upgrade select none
# Boot loader
d-i grub-installer/only_debian boolean true
d-i grub-installer/with_other_os boolean true
# Finish
d-i finish-install/reboot_in_progress note
五、验证与常见问题
apt clean 瘦身。boot/grub/efi.img),并在生成 ISO 时使用 -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot 参数。DEBCONF_DEBUG=5 获取调试输出)。