ubuntu server制作系统镜像自动安装-附加自定义安装包
制作自定义镜像包使用工具:UltraISO软碟通
系统镜像:ubuntu-20.04.6-live-server-amd64-2.iso、ubuntu-22.04.2-live-server-amd64.iso
具体制作方法参考:
Ubuntu server版本无人值守安装自动安装
Ubuntu 自动安装修改的文件下载:
链接:https://pan.baidu.com/s/1j6c39x7TL9fpH9uxDhOhyQ?pwd=3d4b
打开软碟通挂载原版ISO,然后将user-data和meta-data添加到ISO的根目录,txt.cfg添加并覆盖isolinux/txt.cfg,grub.cfg添加并覆盖/boot/grub/grub.cfg。Ubuntu 20.04有txt.cfg(传统模式启动)、grub.cfg(UEFI模式启动)两个文件,Ubuntu 22.04只有grub.cfg一个文件控制传统和UEFI模式启动。cfg文件修改的内容为开机自动从cdrom引导安装系统,并取消fsck过程。
Ubuntu 20.04 txt.cfg:
label live
menu label ^Install Ubuntu Server
kernel /casper/vmlinuz
append initrd=/casper/initrd fsck.mode=skip quiet autoinstall ds=nocloud;s=/cdrom/ ---
grub.cfg:
menuentry "Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz quiet fsck.mode=skip autoinstall ds='nocloud;s=/cdrom/' ---
initrd /casper/initrd
}
Ubuntu 22.04 grub.cfg:
menuentry "Try or Install Ubuntu Server" {
set gfxpayload=keep
linux /casper/vmlinuz fsck.mode=skip autoinstall ds='nocloud;s=/cdrom/' ---
initrd /casper/initrd
}
附加自定义安装包方法:
提前在一台Ubuntu虚拟机中使用apt install -d *.deb命令将安装包下载至/var/cache/apt/archives下,需要该虚拟机未安装目标软件包。
比如要按照net-tools、sysstat、gcc、make等
#apt install -d net-tools sysstat gcc make
将下载的deb包放至ISO镜像根下linshi目录
在user-data文本文件中添加如下内容使系统安装成功后执行安装命令
late-commands:
- "lvextend -l +100%FREE -r /dev/ubuntu-vg/ubuntu-lv"
- "sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /target/etc/ssh/sshd_config"
- "cp -r /cdrom/linshi /target/root"
- echo "@reboot sleep 60 && /usr/bin/sh /root/linshi.sh" > /target/var/spool/cron/crontabs/root
- 'chmod 600 /target/var/spool/cron/crontabs/root'
- 'chown root:crontab /target/var/spool/cron/crontabs/root'
- 'echo "#!/bin/bash" > /target/root/linshi.sh'
- echo "> /etc/apt/sources.list" >> /target/root/linshi.sh
- 'echo "apt-get install -y /root/linshi/*" >> /target/root/linshi.sh'
- 'echo "crontab -r" >> /target/root/linshi.sh'
网盘中的user-data文件关于分区,我使用的是自动LVM分区,传统模式及UEFI模式安装均可以。如想要自定义分区,可取消注释修改测试
# storage: //使用自动分区,legacy及uefi都可以安装
# config:
# - {ptable: gpt, path: /dev/sda, wipe: superblock, preserve: false, name: '', grub_device: false,
# type: disk, id: disk-sda}
# - {device: disk-sda, size: 536870912, wipe: superblock, flag: boot, number: 1,
# preserve: false, grub_device: true, type: partition, id: partition-0}
# - {fstype: fat32, volume: partition-0, preserve: false, type: format, id: format-0}
# - {device: disk-sda, size: 1073741824, wipe: superblock, flag: '', number: 2,
# preserve: false, grub_device: false, type: partition, id: partition-1}
# - {fstype: ext4, volume: partition-1, preserve: false, type: format, id: format-1}
# - {device: disk-sda, size: -1, wipe: superblock, flag: '', number: 3,
# preserve: false, grub_device: false, type: partition, id: partition-2}
# - name: ubuntu-vg
# devices: [partition-2]
# preserve: false
# type: lvm_volgroup
# id: lvm_volgroup-0
# - {name: ubuntu-lv, volgroup: lvm_volgroup-0, size: -1, wipe: superblock,
# preserve: false, type: lvm_partition, id: lvm_partition-0}
# - {fstype: ext4, volume: lvm_partition-0, preserve: false, type: format, id: format-2}
# - {path: /, device: format-2, type: mount, id: mount-2}
# - {path: /boot, device: format-1, type: mount, id: mount-1}
# - {path: /boot/efi, device: format-0, type: mount, id: mount-0}
基本上就是上面的关键点了,自动安装过程需要多测试排错。