wget https://releases.ubuntu.com/20.04/ubuntu-20.04.2-live-server-amd64.iso
sudo mount /home/www/ubuntu-20.04.2-live-server-amd64.iso /mnt
拷贝/mnt目录中的所有内容到/home/www/ubuntu/目录下
mkdir -p /home/www/ubuntu/ cp -rf /mnt/* /mnt/.disk/ /home/www/ubuntu/
#查看 cat /var/log/installer/autoinstall-user-data
适当进行修改如对磁盘分区大小修改
#cloud-config autoinstall: apt: geoip: true preserve_sources_list: false primary: - arches: [amd64, i386] uri: http://cn.archive.ubuntu.com/ubuntu - arches: [default] uri: http://ports.ubuntu.com/ubuntu-ports identity: {hostname: www, password: $6$FqFvANIIt7lD3d4V$j06NXAbMpjJqdxR/l9jcDXjJl/bULXT9W8EMneB4djvZt3TF5hOr399AThq/3T6efVttZKfz8r2Tp2cqF1xDt0, realname: www, username: www} keyboard: {layout: us, toggle: null, variant: ''} locale: en_US network: ethernets: enp0s3: {dhcp4: true} enp0s8: {dhcp4: true} version: 2 ssh: allow-pw: true authorized-keys: [] install-server: true storage: config: - {ptable: gpt, serial: VBOX_HARDDISK_VB8c6ac1fe-c81d121d, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda} - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false, grub_device: false, type: partition, id: partition-0} - {device: disk-sda, size: 107371036672, 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-0} - {device: format-0, path: /, type: mount, id: mount-0} version: 1
#删除了磁盘序列号参数 serial: VBOX_HARDDISK_VB8c6ac1fe-c81d121d, #修改磁盘容量(大小为byte),避免出现磁盘总容量不一样导致的自动安装错误 {device: disk-sda, size: 53687091200, wipe: superblock, flag: '', number: 2,
#cloud-config autoinstall: apt: geoip: true preserve_sources_list: false primary: - arches: [amd64, i386] uri: http://cn.archive.ubuntu.com/ubuntu - arches: [default] uri: http://ports.ubuntu.com/ubuntu-ports identity: {hostname: www, password: $6$FqFvANIIt7lD3d4V$j06NXAbMpjJqdxR/l9jcDXjJl/bULXT9W8EMneB4djvZt3TF5hOr399AThq/3T6efVttZKfz8r2Tp2cqF1xDt0, realname: www, username: www} keyboard: {layout: us, toggle: null, variant: ''} locale: en_US network: ethernets: enp0s3: {dhcp4: true} enp0s8: {dhcp4: true} version: 2 ssh: allow-pw: true authorized-keys: [] install-server: true storage: config: - {ptable: gpt, path: /dev/sda, wipe: superblock-recursive, preserve: false, name: '', grub_device: true, type: disk, id: disk-sda} - {device: disk-sda, size: 1048576, flag: bios_grub, number: 1, preserve: false, grub_device: false, type: partition, id: partition-0} - {device: disk-sda, size: 53687091200, 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-0} - {device: format-0, path: /, type: mount, id: mount-0} version: 1
cat > meta-data << EOF instance-id: focal-autoinstall EOF
将meta-data 、user-data文件拷贝到/home/www/ubuntu/目录下
文件路径:
/home/www/ubuntu/isolinux/txt.cfg
原文件:
default live label live menu label ^Install Ubuntu Server kernel /casper/vmlinuz append initrd=/casper/initrd quiet --- label hwe-live menu label ^Install Ubuntu Server with the HWE kernel kernel /casper/hwe-vmlinuz append initrd=/casper/hwe-initrd quiet --- label memtest menu label Test ^memory kernel /install/mt86plus label hd menu label ^Boot from first hard disk localboot 0x80
修改后文件:
default live label live menu label ^Install Ubuntu Server kernel /casper/vmlinuz append initrd=/casper/initrd quiet autoinstall ds=nocloud;s=/cdrom/ --- label hwe-live menu label ^Install Ubuntu Server with the HWE kernel kernel /casper/hwe-vmlinuz append initrd=/casper/hwe-initrd quiet --- label memtest menu label Test ^memory kernel /install/mt86plus label hd menu label ^Boot from first hard disk localboot 0x80
配置完成。
进入/home/www/目录执行如下命令对ubuntu/目录进行打包
#安装mkisofs sudo apt install mkisofs -y sudo mkisofs -R -J -T -v -no-emul-boot -boot-load-size 4 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat -o auto-ubuntu-20.04.4-server-amd64.iso ubuntu/