And*_*her 16 server pxe netinstall 20.04 subiquity
如何使用 PXE 和实时服务器映像进行全自动 Ubuntu 20.04 服务器安装?
随着 20.04 版本的发布,Ubuntu 似乎正在进一步推动实时服务器安装程序 ( subiquity ) 选项。debian-installer (di) 映像已重命名为 legacy。我通常更喜欢的网络引导安装程序也是如此。20.04 版本还为实时服务器安装程序引入了一个新的自动安装选项。
And*_*her 25
这些是使用 PXE 和实时服务器映像执行全自动 Ubuntu 20.04 服务器安装的步骤。我发现这个过程被简单地记录下来并且充满了问题。在这些步骤中,我在基于UEFI的服务器上安装 20.04 。
(编辑:我在通过 pxelinux 在裸机或虚拟机 VM 上部署 Ubuntu 20.04 时针对基于BIOS的服务器调整了这些步骤,cloud-init 不会获取用户数据文件)
这些步骤可能有许多变化。它们可以定制和定制以满足一个人的需求。目标是提供一个示例,说明如何实现这一目标并帮助其他用户克服遇到的问题。
以下所有步骤均以 root 身份运行。这些是在 Ubuntu 18.04 服务器上测试的。
安装 tftp 服务器和 web 服务器
apt-get -y install tftpd-hpa apache2
Run Code Online (Sandbox Code Playgroud)
配置 apache 以提供 tftp 目录中的文件
cat > /etc/apache2/conf-available/tftp.conf <<EOF
<Directory /var/lib/tftpboot>
Options +FollowSymLinks +Indexes
Require all granted
</Directory>
Alias /tftp /var/lib/tftpboot
EOF
a2enconf tftp
systemctl restart apache2
Run Code Online (Sandbox Code Playgroud)
下载实时服务器iso
wget http://old-releases.ubuntu.com/releases/20.04/ubuntu-20.04-live-server-amd64.iso -O /var/lib/tftpboot/ubuntu-20.04-live-server-amd64.iso
Run Code Online (Sandbox Code Playgroud)
从实时服务器iso中提取内核和initramfs
mount /var/lib/tftpboot/ubuntu-20.04-live-server-amd64.iso /mnt/
cp /mnt/casper/vmlinuz /var/lib/tftpboot/
cp /mnt/casper/initrd /var/lib/tftpboot/
umount /mnt
Run Code Online (Sandbox Code Playgroud)
下载 grub 镜像以通过 PXE 加载
wget http://archive.ubuntu.com/ubuntu/dists/focal/main/uefi/grub2-amd64/current/grubnetx64.efi.signed -O /var/lib/tftpboot/pxelinux.0
Run Code Online (Sandbox Code Playgroud)
配置 grub。此配置将提供全自动启动选项以及手动启动选项
mkdir -p /var/lib/tftpboot/grub
cat > /var/lib/tftpboot/grub/grub.cfg <<'EOF'
default=autoinstall
timeout=30
timeout_style=menu
menuentry "Focal Live Installer - automated" --id=autoinstall {
echo "Loading Kernel..."
# make sure to escape the ';' or surround argument in quotes
linux /vmlinuz ip=dhcp url=http://${pxe_default_server}/tftp/ubuntu-20.04-live-server-amd64.iso autoinstall ds="nocloud-net;s=http://${pxe_default_server}/tftp/" root=/dev/ram0 cloud-config-url=/dev/null
echo "Loading Ram Disk..."
initrd /initrd
}
menuentry "Focal Live Installer" --id=install {
echo "Loading Kernel..."
linux /vmlinuz ip=dhcp url=http://${pxe_default_server}/tftp/ubuntu-20.04-live-server-amd64.iso root=/dev/ram0 cloud-config-url=/dev/null
echo "Loading Ram Disk..."
initrd /initrd
}
EOF
Run Code Online (Sandbox Code Playgroud)
使用自动安装配置配置cloud-init。我首先手动运行安装以获取生成的/var/log/installer/autoinstall-user-data文件作为基础。然后我根据我的需要和遇到的错误进行了修改。
cat > /var/lib/tftpboot/meta-data <<EOF
instance-id: focal-autoinstall
EOF
Run Code Online (Sandbox Code Playgroud)
cat > /var/lib/tftpboot/user-data <<'EOF'
#cloud-config
autoinstall:
version: 1
# use interactive-sections to avoid an automatic reboot
#interactive-sections:
# - locale
apt:
# even set to no/false, geoip lookup still happens
#geoip: no
preserve_sources_list: false
primary:
- arches: [amd64, i386]
uri: http://us.archive.ubuntu.com/ubuntu
- arches: [default]
uri: http://ports.ubuntu.com/ubuntu-ports
# r00tme
identity: {hostname: focal-autoinstall, password: $6$.c38i4RIqZeF4RtR$hRu2RFep/.6DziHLnRqGOEImb15JT2i.K/F9ojBkK/79zqY30Ll2/xx6QClQfdelLe.ZjpeVYfE8xBBcyLspa/,
username: ubuntu}
keyboard: {layout: us, variant: ''}
locale: en_US.UTF-8
# interface name will probably be different
network:
network:
version: 2
ethernets:
ens192:
critical: true
dhcp-identifier: mac
dhcp4: true
ssh:
allow-pw: true
authorized-keys: []
install-server: true
# this creates an efi partition, /boot partition, and root(/) lvm volume
storage:
grub:
reorder_uefi: False
swap:
size: 0
config:
- {ptable: gpt, path: /dev/sda, 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-sda1}
- {fstype: fat32, volume: partition-sda1, preserve: false, type: format, id: format-2}
- {device: disk-sda, size: 1073741824, wipe: superblock, flag: linux, number: 2,
preserve: false, grub_device: false, type: partition, id: partition-sda2}
- {fstype: ext4, volume: partition-sda2, preserve: false, type: format, id: format-0}
- {device: disk-sda, size: -1, flag: linux, number: 3, preserve: false,
grub_device: false, type: partition, id: partition-sda3}
- name: vg-0
devices: [partition-sda3]
preserve: false
type: lvm_volgroup
id: lvm-volgroup-vg-0
- {name: lv-root, volgroup: lvm-volgroup-vg-0, size: 100%, preserve: false,
type: lvm_partition, id: lvm-partition-lv-root}
- {fstype: ext4, volume: lvm-partition-lv-root, preserve: false, type: format,
id: format-1}
- {device: format-1, path: /, type: mount, id: mount-2}
- {device: format-0, path: /boot, type: mount, id: mount-1}
- {device: format-2, path: /boot/efi, type: mount, id: mount-3}
write_files:
# override the kernel package
- path: /run/kernel-meta-package
content: |
linux-virtual
owner: root:root
permissions: "0644"
# attempt to also use an answers file by providing a file at the default path. It did not seem to have any effect
#- path: /subiquity_config/answers.yaml
# content: |
# InstallProgress:
# reboot: no
# owner: root:root
# permissions: "0644"
EOF
Run Code Online (Sandbox Code Playgroud)
根据 DHCP 服务器的文档设置 DHCP 选项 66,67。
此时,您应该能够启动基于 UEFI 的服务器并执行完全自动安装。
cloud-config-url=/dev/null内核参数将防止cloud-init不必要地下载iso,从而减少所需的内存、减少网络流量并加快启动时间。/var/log/installer/autoinstall-user-data文件通过以下方式被破坏
version属性,导致验证失败。我添加了属性network部分需要另一层嵌套。配置参考中提到了这个错误preserve每个项目的属性storage config设置为false。否则curtin不会安装在空白磁盘上keyboard属性toggle设置为 null,导致验证失败。我只是删除了属性reorder_uefi。幸运的是,subiquity恰好将这个配置传递给了curtinapt配置选项geoip似乎没有工作时。总是有 geoip 请求的日志size: 512M)会导致大小存储为浮点数,从而导致在按百分比调整 LVM 卷大小时出错。避免人类可读的值似乎可以解决这个问题我没有深入研究这些。它们基于我的预置文件会做什么。他们中的大多数很可能被固定巧妙利用early-commands,late-commands以及云计算的初始化。我可能也错过了一些东西
apt-cacher-ng用于 apt,但它不能用作通用代理。安装程序假定您配置的任何代理都适用interactive-sections,但这会导致 3 次暂停late-commands,但我没有尝试/run/kernel-meta-package。这是linux-generic在 initramfs 中硬编码的。我更喜欢将linux-virtual软件包用于 VM。我能够使用cloud-init配置覆盖文件/target/var/lib/cloud/seed/nocloud-net/user-datacloud-init 在首次启动期间使用的结果文件。回复表明该lock-passwd属性有一个错字,可能会影响到一些用户
#cloud-config
growpart: {mode: 'off'}
locale: en_US.UTF-8
preserve_hostname: true
resize_rootfs: false
ssh_pwauth: true
users:
- gecos: ubuntu
groups: [adm, cdrom, dip, plugdev, lxd, sudo]
lock-passwd: false
name: ubuntu
passwd: $6$.c38i4RIqZeF4RtR$hRu2RFep/.6DziHLnRqGOEImb15JT2i.K/F9ojBkK/79zqY30Ll2/xx6QClQfdelLe.ZjpeVYfE8xBBcyLspa/
shell: /bin/bash
Run Code Online (Sandbox Code Playgroud)