AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1487504
Accepted
Mr. T
Mr. T
Asked: 2023-09-30 11:16:37 +0800 CST2023-09-30 11:16:37 +0800 CST 2023-09-30 11:16:37 +0800 CST

Ubuntu 22.04 自动安装适用于 UEFI,但不适用于 Virtualbox 中的 MBR?

  • 772

我已经阅读了 curtin 和自动安装文档,但无法理解为什么这个自动安装脚本可以在我的开发笔记本电脑上运行,但不能在我的 vbox 安装(Ubuntu 主机上的版本 7.0.8)上运行。起初我认为问题是对/dev/mmcblk0(virtualbox use /dev/sda) 的引用,但在进行了许多不同的配置之后,我认为这实际上不是问题,因为它给出了错误消息。这是autoinstall config did not create needed bootloader partition

我的理论是,此自动安装可以在笔记本电脑上运行,因为笔记本电脑是 UEFI,但不能在 Virtualbox 上运行,因为它不是。我在其他地方找到了一些关于如何在 MBR 上进行适用于 UEFI 的自动安装的建议,但没有一个能够同时做到这两点。

这是自动安装分区布局的问题吗?有什么解决办法吗?由于该项目的特定要求,我无法使用内置布局(lvm 等)。我意识到我可以将 Virtualbox 设置更改为 EFI 引导,但必须将这个 ISO 安装在各种机器上,其中一些机器可能不支持 EFI。

这是我当前的分区布局,它正在一台设备为/dev/mmcblk0

该脚本需要如何修改才能在任何系统上运行?是的,/boot 分区对于此设置确实需要那么大。

autoinstall:
  version: 1
  storage:
    config:
    - ptable: gpt
      wipe: superblock-recursive
      preserve: false
      name: ''
      grub_device: false
      type: disk
      id: disk-mmcblk0
      match:
        size: largest
    - device: disk-mmcblk0
      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-mmcblk0
      size: 5GB
      wipe: superblock
      number: 2
      preserve: false
      type: partition
      id: partition-1
    - fstype: ext4
      volume: partition-1
      preserve: false
      type: format
      id: format-1
    - device: disk-mmcblk0
      size: -1
      wipe: superblock
      number: 3
      preserve: false
      type: partition
      id: partition-2
    - volume: partition-2
      key: password
      path: /dev/mapper/dm_crypt-0
      preserve: false
      type: dm_crypt
      id: dm_crypt-0
    - name: ubuntu-vg
      devices:
      - dm_crypt-0
      preserve: false
      type: lvm_volgroup
      id: lvm_volgroup-0
    - name: ubuntu-lv
      volgroup: lvm_volgroup-0
      size: -1
      wipe: superblock
      preserve: false
      path: /dev/ubuntu-vg/ubuntu-lv
      type: lvm_partition
      id: lvm_partition-0
    - fstype: btrfs
      volume: lvm_partition-0
      preserve: false
      type: format
      id: format-2
    - path: /
      device: format-2
      type: mount
      id: mount-2
      options: 'noatime,discard,compress=zstd:1'
    - path: /boot
      device: format-1
      type: mount
      id: mount-1
    - path: /boot/efi
      device: format-0
      type: mount
      id: mount-0
autoinstall
  • 1 1 个回答
  • 178 Views

1 个回答

  • Voted
  1. Best Answer
    mpboden
    2023-10-03T11:12:30+08:002023-10-03T11:12:30+08:00

    正如@AndrewLowther 在答案中指出的那样,他的评论指出:

    正式而言,您无法创建同时支持 BIOS 和 UEFI 的单个存储配置。grub_device 设置不兼容。

    所以你有两个选择:

    1. user-data使用安德鲁建议的解决方法修改您的
    2. 创建单独的user-data文件。一种用于 BIOS,一种用于 UEFI

    我将在下面概述第一个选项,这就是您想要的。这意味着它适用于 BIOS 或 UEFI 计算机。


    首先,您user-data提供的文件缺少#cloud-config第一行和该identity部分。两者都是必需的,因此我在下面的示例中添加了它们。该identity部分使用默认用户名ubuntu和密码进行定义ubuntu。此外,加密驱动器配置有密码ubuntu。相应地改变。

    下面的文件有几处与user-data您的不同。

    1. grub_device: true为磁盘设置而不是grub_device: false

      - type: disk
        id: disk-mmcblk0
        ptable: gpt
        match:
          size: largest
        preserve: false
        name: ''
        grub_device: true
        wipe: superblock-recursive
      
    2. flag: bios_grub添加一个小的未格式化分区。

      - type: partition
        id: partition-0
        device: disk-mmcblk0
        size: 4194304
        wipe: superblock
        flag: bios_grub
        number: 1
        preserve: false
        grub_device: false
      

    来自科廷文档:bios_grub

    如果 curtin 的主机系统已使用 UEFI 启动,则 curtin 会将 grub 安装到 esp 分区。如果系统安装介质已使用 MBR 引导,则 grub 将安装到磁盘的 MBR 上。但是,在具有 gpt 分区表的磁盘上,MBR 之后没有足够的空间供 grub 存储其第二阶段 core.img,因此需要一个带有 bios_grub 标志的未格式化的小分区。该分区应放置在磁盘的开头,大小应为 1MB。它不应包含文件系统或安装在系统上的任何位置。

    1. grub_device: false为除 UEFI 安装使用的 ESP 分区之外的所有分区设置。对于此分区,grub_device: UEFI设置为相反。目前这实际上只是一个占位符,将使用 进行编辑early-commands,如下所述。

      - type: partition
        id: partition-1
        device: disk-mmcblk0
        size: 111149056
        wipe: superblock
        flag: boot
        number: 2
        preserve: false
        grub_device: UEFI
      
    2. early-commands在文件中使用user-data会autoinstall.yaml根据计算机是 UEFI 还是 BIOS 来修改文件。这将修改grub_device: UEFI上面定义的设置。

    看看以下内容:

      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
    

    这是autoinstall.yaml根据条件编辑文件。据我了解,该autoinstall.yaml文件是在安装过程中创建的,位于实时安装的根目录中。user-data这是您的文件和安装程序填写的默认自动安装未回答/未配置问题的组合。

    这会检查文件是否/sys/firmware/efi存在:

    • if [ -e "/sys/firmware/efi" ]; then

    如果属实:

    • 表明系统是UEFI

    • 替换grub_device: UEFI为grub_device: true使用sed:

      sed -i -e "s/grub_device: UEFI/grub_device: true/" /autoinstall.yaml

    否则:

    • 表示系统是BIOS

    • 替换grub_device: UEFI为grub_device: false使用sed:

      sed -i -e "s/grub_device: UEFI/grub_device: false/" /autoinstall.yaml


    就是这样。运行后early-commands,安装将继续。

    这是完整的user-data文件:

    #cloud-config
    autoinstall:
      version: 1
      identity:
        hostname: ubuntu-server
        password: $6$5lpwCLsKLEzMkSJc$keOAhA6aO/5RocGThmhVA7LSNuW911Rx5HHXFEa75oGK20cEdAAgn14H5f5nGeq6QgcSyLPrWcg1.JvjXbhrN/
        realname: Ubuntu User
        username: ubuntu
      storage:
        config:
        - type: disk
          id: disk-mmcblk0
          ptable: gpt
          match:
            size: largest
          preserve: false
          name: ''
          grub_device: true
          wipe: superblock-recursive
    
        - type: partition
          id: partition-0
          device: disk-mmcblk0
          size: 4194304
          wipe: superblock
          flag: bios_grub
          number: 1
          preserve: false
          grub_device: false
    
        - type: partition
          id: partition-1
          device: disk-mmcblk0
          size: 111149056
          wipe: superblock
          flag: boot
          number: 2
          preserve: false
          grub_device: UEFI
    
        - type: format
          id: format-0
          volume: partition-1
          fstype: fat32
          preserve: false
    
        - type: partition
          id: partition-2
          device: disk-mmcblk0
          size: 5GB
          wipe: superblock
          number: 3
          preserve: false
          grub_device: false
    
        - type: format
          id: format-1
          volume: partition-2
          fstype: ext4
          preserve: false
    
        - type: partition
          id: partition-3
          device: disk-mmcblk0
          size: -1
          wipe: superblock
          number: 4
          preserve: false
          grub_device: false
    
        - type: dm_crypt
          id: dm_crypt-0
          volume: partition-3
          preserve: false
          key: 'ubuntu'
    
        - type: lvm_volgroup
          id: lvm_volgroup-0
          devices:
          - dm_crypt-0
          preserve: false
          name: ubuntu-vg
    
        - type: lvm_partition
          id: lvm_partition-0
          volgroup: lvm_volgroup-0
          size: -1
          preserve: false
          wipe: superblock
          name: ubuntu-lv
    
        - type: format
          id: format-2
          volume: lvm_partition-0
          fstype: btrfs
          preserve: false
    
        - type: mount
          id: mount-0
          device: format-0
          path: /boot/efi
    
        - type: mount
          id: mount-1
          device: format-1
          path: /boot
    
        - type: mount
          id: mount-2
          device: format-2
          path: /
      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
          
    

    如果您在 UEFI 和 BIOS 计算机上安装然后进行比较,您会发现分区方案是相同的。UEFI 安装将有一个未使用的bios_grub分区,BIOS 安装将有一个未使用的 ESP 分区安装在/boot/efi。在 BIOS 安装中该文件/boot/efi将为空,而在 UEFI 安装中将包含文件。

    以下安装是使用 ISO 完成的:ubuntu-22.04.3-live-server-amd64.iso。user-data将其解压并添加上述文件/nocloud,然后重新打包。

    电喷安装:

    $ sudo parted /dev/sda
    GNU Parted 3.4
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sda: 26.8GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name  Flags
     1      1049kB  5243kB  4194kB                     bios_grub
     2      5243kB  116MB   111MB   fat32              boot, esp
     3      116MB   5485MB  5369MB  ext4
     4      5485MB  26.8GB  21.4GB
    
    
    
    $ lsblk -o name,fssize,fsused,fsavail,fstype,mountpoint
    NAME                        FSSIZE FSUSED FSAVAIL FSTYPE      MOUNTPOINT
    loop0                        53.4M  53.4M       0 squashfs    /snap/snapd/19457
    loop1                         112M   112M       0 squashfs    /snap/lxd/24322
    loop2                        63.5M  63.5M       0 squashfs    /snap/core20/1974
    sda                                                           
    ├─sda1                                                        
    ├─sda2                      104.3M     6M   98.3M vfat        /boot/efi
    ├─sda3                        4.8G 129.6M    4.4G ext4        /boot
    └─sda4                                            crypto_LUKS 
      └─dm_crypt-0                                    LVM2_member 
        └─ubuntu--vg-ubuntu--lv  19.9G     3G     16G btrfs       /
    
    
    
    $ df -h
    Filesystem                         Size  Used Avail Use% Mounted on
    tmpfs                              491M  1.1M  490M   1% /run
    /dev/mapper/ubuntu--vg-ubuntu--lv   20G  3.0G   17G  16% /
    tmpfs                              2.4G     0  2.4G   0% /dev/shm
    tmpfs                              5.0M     0  5.0M   0% /run/lock
    /dev/sda3                          4.9G  130M  4.5G   3% /boot
    /dev/sda2                          105M  6.1M   99M   6% /boot/efi
    tmpfs                              491M  4.0K  491M   1% /run/user/1000
    
    
    $ ls /boot/efi
    EFI
    

    BIOS安装:

    $ sudo parted /dev/sda
    GNU Parted 3.4
    Using /dev/sda
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print                                                            
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sda: 26.8GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name  Flags
     1      1049kB  5243kB  4194kB                     bios_grub
     2      5243kB  116MB   111MB   fat32              boot, esp
     3      116MB   5485MB  5369MB  ext4
     4      5485MB  26.8GB  21.4GB
    
    
    
    $ lsblk -o name,fssize,fsused,fsavail,fstype,mountpoint
    NAME                        FSSIZE FSUSED FSAVAIL FSTYPE      MOUNTPOINT
    loop0                        63.5M  63.5M       0 squashfs    /snap/core20/1974
    loop1                        53.4M  53.4M       0 squashfs    /snap/snapd/19457
    loop2                         112M   112M       0 squashfs    /snap/lxd/24322
    sda                                                           
    ├─sda1                                                        
    ├─sda2                      104.3M   512B  104.3M vfat        /boot/efi
    ├─sda3                        4.8G 128.6M    4.4G ext4        /boot
    └─sda4                                            crypto_LUKS 
      └─dm_crypt-0                                    LVM2_member 
        └─ubuntu--vg-ubuntu--lv  19.9G     3G     16G btrfs       /
    
    
    
    $ df -h
    Filesystem                         Size  Used Avail Use% Mounted on
    tmpfs                              492M  1.1M  491M   1% /run
    /dev/mapper/ubuntu--vg-ubuntu--lv   20G  3.0G   17G  16% /
    tmpfs                              2.4G     0  2.4G   0% /dev/shm
    tmpfs                              5.0M     0  5.0M   0% /run/lock
    /dev/sda3                          4.9G  129M  4.5G   3% /boot
    /dev/sda2                          105M   512  105M   1% /boot/efi
    tmpfs                              492M  4.0K  492M   1% /run/user/1000
    
    
    
    $ ls /boot/efi
    
    • 2

相关问题

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve