我正在尝试使用安装 Ubuntu 22.04自动安装我生成的 ISO 包含 userdata.yml(主自动安装文件),storage
其中有一个部分,应该支持两个都EFI 和 Legacy 启动,但我找不到实现它的方法。
userdata.yml 中的存储部分支持仅有的EFI 启动:
storage:
config:
- ptable: gpt
path: /dev/sda
wipe: superblock-recursive
preserve: false
name: ''
grub_device: false
type: disk
id: disk-sda
- device: disk-sda
size: 1127219200
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: 54760833024
wipe: superblock
flag: ''
number: 3
preserve: false
grub_device: false
type: partition
id: partition-2
- name: myvg
devices:
- partition-2
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- name: slashlv
volgroup: lvm_volgroup-0
size: 53687091200B
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
userdata.yml 中的存储部分支持仅有的传统启动:
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: 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: 54760833024
wipe: superblock
flag: ''
number: 3
preserve: false
grub_device: false
type: partition
id: partition-2
- name: myvg
devices:
- partition-2
preserve: false
type: lvm_volgroup
id: lvm_volgroup-0
- name: slashlv
volgroup: lvm_volgroup-0
size: 53687091200B
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-1
- path: /boot
device: format-1
type: mount
id: mount-0
当我尝试使用仅支持传统启动(以及相反的启动)的 userdata.yml 安装 EFI 时失败了 -
2022-11-03 09:48:37,448 ERROR root:39 finish: subiquity/Filesystem/apply_autoinstall_config: FAIL: autoinstall config did not create needed bootloader partition
2022-11-03 09:48:37,448 ERROR root:39 finish: subiquity/apply_autoinstall_config: FAIL: autoinstall config did not create needed bootloader partition
再次,我需要支持两个都EFI 和 Legacy 启动,在相同的userdata.yml 文件。
谢谢!
答案1
官方说法是,您无法创建同时支持 BIOS 和 UEFI 的单个存储配置。这些grub_device
设置不兼容。引用自安装程序(subiquity)开发人员
是的,可能吧。我其实想把这整个区域清理干净,让配置更合理(例如,真的应该可以安装一个可以同时启动传统和 UEFI 的系统),但看起来我近期不会这么做……
作为一种解决方法,early-commands
可用于使单个配置工作。这是user-data
我使用的示例代码片段。它将/autoinstall.yaml
根据是否存在来修改文件/sys/firmware/efi
。
#cloud-config
autoinstall:
storage:
config:
- type: disk
match:
size: largest
ptable: gpt
preserve: false
name: ''
grub_device: true
id: disk-sda
- type: partition
device: disk-sda
size: 4194304
wipe: superblock
flag: bios_grub
number: 14
preserve: false
grub_device: false
id: partition-14
- type: partition
device: disk-sda
size: 111149056
wipe: superblock
flag: boot
number: 15
preserve: false
grub_device: UEFI
id: partition-15
- type: partition
device: disk-sda
size: -1
wipe: superblock
number: 1
preserve: false
grub_device: false
id: partition-1
- type: format
fstype: ext4
volume: partition-1
preserve: false
id: format-1
- type: mount
path: /
device: format-1
id: mount-1
- type: format
fstype: fat32
volume: partition-15
preserve: false
id: format-15
- type: mount
path: /boot/efi
device: format-15
id: mount-15
early-commands:
- |
if [ -e "/sys/firmware/efi" ]; then
sed -i -e "s/grub_device: UEFI/grub_device: true/" /autoinstall.yaml
else
sed -i -e "s/grub_device: UEFI/grub_device: false/" /autoinstall.yaml
fi
true
使用此代码片段,所有设备最终都会具有相同的分区布局,这可能会造成混淆。例如,基于 BIOS 的机器最终仍会有一个不必要的 ESP 分区挂载在/boot/efi
,而基于 UEFI 的机器将有一个不必要的bios_grub
分区。
这云图像有一个分区布局这是此配置的灵感来源。云映像支持 BIOS 和 UEFI,我想复制这一点。生成的分区表如下所示,其中最后一个分区填满了磁盘。
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 5.00MiB 4.00MiB bios_grub
2 5.00MiB 111MiB 106MiB fat32 boot, esp
3 111MiB 20479MiB 20368MiB ext4
答案2
解决方案:
我删除了整个storage
部分user-data
;默认自动安装“知道”如何处理它,无论您是在 UEFI 系统还是 Legacy BIOS 中运行。
注意:它默认创建以下内容 -
/boot - 2g
(If UEFI) /boot/efi - 1g±
/ - as LVM - 100g, or if your disk is less than 100g, it creates it with about 70% of the disk's size.
VG name - ubuntu-vg
LV name (that mounted to /) - ubuntu-lv
答案3
下面是我为 ubuntu22.04 创建自动安装的示例:
early-commands:
- |
cat << EOF | python3
import yaml
import os
mbr_disk0 = {'id': 'root-disk', 'ptable': 'gpt', 'type': 'disk', 'match': {'size': 'largest'}, 'wipe': 'superblock-recursive', 'preserve': False, 'grub_device': True, 'name': 'rnxtdisk'}
mbr_part0 = {'id': 'partition-0', 'type': 'partition', 'device': 'root-disk', 'size': '1M', 'flag': 'bios_grub', 'number': 1, 'preserve': False}
efi_disk0 = {'id': 'root-disk', 'ptable': 'gpt', 'type': 'disk', 'match': {'size': 'largest'}, 'wipe': 'superblock-recursive', 'preserve': False, 'grub_device': False, 'name': 'rnxtdisk'}
efi_part0 = {'id': 'partition-0', 'type': 'partition', 'device': 'root-disk', 'grub_device': True, 'size': '1G', 'flag': 'boot', 'number': 1, 'preserve': False}
part1 = {'id': 'partition-1', 'type': 'partition', 'device': 'root-disk', 'size': '1G', 'wipe': 'superblock', 'number': 2, 'preserve': False}
part2 = {'id': 'partition-2', 'type': 'partition', 'device': 'root-disk', 'size': -1, 'wipe': 'superblock', 'number': 3, 'preserve': False}
vg0 = {'name': 'vg0', 'devices': ['partition-2'], 'preserve': False, 'id': 'lvm_volgroup-0', 'type': 'lvm_volgroup'}
lv_root = {'name': 'lv-root', 'volgroup': 'lvm_volgroup-0', 'size': '10G', 'wipe': 'superblock', 'preserve': False, 'id': 'lvm_partition-0', 'type': 'lvm_partition'}
fmt_root = {'fstype': 'xfs', 'volume': 'lvm_partition-0', 'preserve': False, 'id': 'format-2', 'type': 'format'}
mnt_root = {'path': '/', 'device': 'format-2', 'id': 'mount-2', 'type': 'mount'}
lv_home = {'name': 'lv-home', 'volgroup': 'lvm_volgroup-0', 'size': '5G', 'wipe': 'superblock', 'preserve': False, 'id': 'lvm_partition-1', 'type': 'lvm_partition'}
fmt_home = {'fstype': 'xfs', 'volume': 'lvm_partition-1', 'preserve': False, 'id': 'format-3', 'type': 'format'}
mnt_home = {'path': '/home', 'device': 'format-3', 'id': 'mount-3', 'type': 'mount'}
lv_data = {'name': 'lv-data', 'volgroup': 'lvm_volgroup-0', 'size': '10G', 'wipe': 'superblock', 'preserve': False, 'id': 'lvm_partition-2', 'type': 'lvm_partition'}
fmt_data = {'fstype': 'xfs', 'volume': 'lvm_partition-2', 'preserve': False, 'id': 'format-4', 'type': 'format'}
mnt_data = {'path': '/data', 'device': 'format-4', 'id': 'mount-4', 'type': 'mount'}
fmt_boot = {'fstype': 'xfs', 'volume': 'partition-1', 'preserve': False, 'id': 'format-1', 'type': 'format'}
mnt_boot = {'path': '/boot', 'device': 'format-1', 'id': 'mount-1', 'type': 'mount'}
fmt_efi = {'fstype': 'fat32', 'volume': 'partition-0', 'preserve': False, 'id': 'format-0', 'type': 'format'}
mnt_efi = {'path': '/boot/efi', 'device': 'format-0', 'id': 'mount-0', 'type': 'mount'}
lv_docker = {'name': 'lv-lib-docker', 'volgroup': 'lvm_volgroup-0', 'size': '10G', 'wipe': 'superblock', 'preserve': False, 'id': 'lvm_partition-3', 'type': 'lvm_partition'}
fmt_docker = {'fstype': 'xfs', 'volume': 'lvm_partition-3', 'preserve': False, 'id': 'format-6', 'type': 'format'}
mnt_docker = {'path': '/var/lib/docker', 'device': 'format-6', 'id': 'mount-6', 'type': 'mount'}
boot_fs = [fmt_boot, mnt_boot]
root_fs = [lv_root, fmt_root, mnt_root]
home_fs = [lv_home, fmt_home, mnt_home]
data_fs = [lv_data, fmt_data, mnt_data]
docker_fs = [lv_docker, fmt_docker, mnt_docker]
common_storage_part = [part1, part2, vg0] + boot_fs + root_fs + home_fs + data_fs + rlog_fs + docker_fs
with open('/autoinstall.yaml') as reader:
autoinstall = yaml.safe_load(reader)
autoinstall['storage'].clear()
with open('/autoinstall.yaml', 'w') as writer:
if os.path.exists('/sys/firmware/efi'):
autoinstall['storage'].update({'config': [efi_disk0, efi_part0, fmt_efi, mnt_efi] + common_storage_part })
else:
autoinstall['storage'].update({'config': [mbr_disk0, mbr_part0] + common_storage_part })
yaml.dump(autoinstall, writer)
EOF