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
    • 最新
    • 标签
主页 / computer / 问题 / 1864395
Accepted
David Anderson
David Anderson
Asked: 2024-12-10 10:15:23 +0800 CST2024-12-10 10:15:23 +0800 CST 2024-12-10 10:15:23 +0800 CST

将装有 Debian 12 的驱动器从 BIOS 启动计算机移至仅 UEFI 启动计算机所需的步骤

  • 772

我已将 Debian 12 安装在 SATA 驱动器上以通过 BIOS 启动。MBR 类型分区由 Debian 安装程序中设置的默认值决定。我希望将此 SATA 驱动器移动到另一台只能通过 UEFI 启动的计算机。目前,我可以通过执行以下操作在新计算机上安装的现有 SATA 驱动器上通过 UEFI 启动 Debian

  • 关闭安全启动。
  • 首先在外部驱动器上启动 rEFInd。
  • 让 rEFInd 指示固件执行 Debian 的 Grubless UEFI 启动。

我更愿意修改 SATA 驱动器以安装 Grub UEFI 引导 Debian。另外,我认为分区应该转换为 GPT。转换为 GPT 并安装有效的 UEFI 引导 Grub 需要哪些步骤?

旧电脑有 2048 MiB 的 RAM 内存,新电脑有 4096 MiB 的 RAM 内存。由于内存较大,因此我想相应扩大交换空间。

MBR 分区表条目

分割 设备 引导 起始
扇区
结束
区域

扇区大小
尺寸 类型 ID
第一小学 /dev/sda1 * 2048 479561485 479559438 228.7 GiB Linux 文件系统 83
第二小学 /dev/sda2 479561486 488424194 8862709 4327 MB Linux 交换 82

磁盘 /dev/sda/:232.9 GiB,250074470400 字节,488426700 个扇区 @ 512 字节/扇区

linux
  • 1 1 个回答
  • 33 Views

1 个回答

  • Voted
  1. Best Answer
    David Anderson
    2024-12-10T10:15:23+08:002024-12-10T10:15:23+08:00

    此答案需要从 Debian 12.7.0 安装程序启动。这可以是 USB 闪存驱动器或 DVD。此答案使用 DVD。从 Debian 下载的安装文件是debian-live-12.7.0-amd64-gnome.iso。

    步骤如下。

    1. UEFI 启动安装程序以运行实时 Debian。

    2. 打开终端应用程序窗口。输入以下命令成为 root 用户。

      sudo -s
      
    3. 将 MBR 分区表转换为 GPT。

      在安装 BIOS 启动 Debain 时,安装程​​序不会在 MBR 后和驱动器末尾的大约 1 MiB 空间中创建任何分区。这样可以通过输入以下命令轻松地从 MBR 分区表转换为 GPT

      sgdisk -g /dev/sda
      

      如果成功,则输出将如下所示。如果输出不同,则可能是之前进行了修改,在 GPT 所需的空间中分配了分区。

      
      ***************************************************************
      Found invalid GPT and valid MBR; converting MBR to GPT format
      in memory.
      ***************************************************************
      
      The operation has completed successfully.
      
    4. 创建 EFI 系统分区。

      此步骤还会创建一个 BIOS 启动分区,以便还可以安装 BIOS 启动 Grub。(创建 GPT 时会覆盖以前的 Grub BIOS 启动代码。)

      注意:安装程序附带的磁盘应用程序可代替 GParted 应用程序使用。磁盘应用程序不会对 EFI 系统分区进行 FAT32 格式化。因此,如果需要,mkfs.vfat -F 32 /dev/sda3可以在退出磁盘应用程序后使用该命令。

      输入以下命令来安装 GParted 应用程序。

      apt update
      apt install gparted dosfstools mtools
      

      GParted 应用程序将用于执行以下操作。

      • 删除现有的 4327 MiB 交换分区
      • 缩小根分区以将以下可用空间增加到 8914 MiB
      • 添加 1 MiB BIOS 启动分区
      • 添加 300 MiB 的 EFI 系统分区
      • 添加新的 8613 MiB 交换分区

      输入以下内容以打开 GParted 应用程序。

      gparted
      

      删除/dev/sda2下面显示的突出显示的分区。

      选择/dev/sda1分区,如下所示。

      调整卷大小,以便保留 8914 MiB 的可用空间,如下所示。

      选择分区后立即的未分配空间/dev/sda1,如下所示。

      创建一个新的 1 MiB 分区,如下所示。

      选择“新分区#1”后面立即未分配的空间,如下所示。

      创建一个新的 300 MiB 分区,如下所示。

      选择“新分区#2”后面立即未分配的空间,如下所示。

      创建一个新的 8613 MiB 交换分区,如下所示。

      选择绿色复选标记“应用所有操作”,如下所示。

      为 设置标志,如下所示/dev/sda2。这会将分区类型更改为 BIOS 启动。

      设置 的标志,如下所示/dev/sda3。这会将分区类型更改为 EFI 系统。

      结果如下所示。退出 GParted 应用程序。

      如果需要,请输入以下命令以按升序重新编号 GPT 分区。在答案中,省略了此命令,因为分区已经按升序排列。

      sgdisk -s /dev/sda
      
    5. 挂载根分区和 EFI 分区。

      输入下面给出的命令。

      mount /dev/sda1 /mnt
      for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do mount -B $i /mnt/$i; done
      chroot /mnt
      mkdir -p /boot/efi
      mount /dev/sda3 /boot/efi
      
    6. 更新fstab文件。

      输入以下命令来查看该fstab文件。

      cat /etc/fstab
      

      下面是一个示例。根 ( /) 和交换 UUID 的形式为xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,其中每个x都是十六进制数字。下面的根和交换 UUID 分别被替换为{root partition UUID}和{original swap UUID}。

      cat /etc/fstab
      # /etc/fstab: static file system information.
      #
      # Use 'blkid' to print the universally unique identifier for a device; this may
      # be used with UUID= as a more robust way to name devices that works even if
      # disks are added and removed. See fstab(5).
      #
      # <file system>             <mount point>  <type>  <options>  <dump>  <pass>
      UUID={root partition UUID} /              ext4    defaults,noatime 0 1
      UUID={original swap UUID} swap           swap    defaults,noatime 0 0
      

      需要更新交换 UUID,并添加 EFI 卷的 UUID。以下命令输出新的 UUID。EFI UUID 的形式为XXXX-XXXX,每个 UUIDX都是一个十六进制数字。

      blkid -s UUID /dev/sda3 /dev/sda4
      

      示例输出如下所示。EFI 和 swap UUID 分别被{EFI UUID}和替换{new swap UUID}。

      /dev/sda3: UUID="{EFI UUID}"
      /dev/sda4: UUID="{new swap UUID}"
      

      要对 进行更改/etc/fstab,您可以使用nano、其他编辑器或输入以下命令。输入以下命令时,将{original swap UUID}、{new swap UUID}和替换{EFI UUID}为相应的实际 UUID。

      sed 's/{original swap UUID}/{new swap UUID}/' /etc/fstab >fstab
      echo UUID={EFI UUID} /boot/efi vfat umask=0077 0 1 >>fstab
      mv fstab /etc/fstab
      

      完成后,可以使用以下命令查看新fstab文件。注意:{root partition UUID}应该保持不变。

      cat /etc/fstab
      

      下面是一个例子。

      cat /etc/fstab
      # /etc/fstab: static file system information.
      #
      # Use 'blkid' to print the universally unique identifier for a device; this may
      # be used with UUID= as a more robust way to name devices that works even if
      # disks are added and removed. See fstab(5).
      #
      # <file system>             <mount point>  <type>  <options>  <dump>  <pass>
      UUID={root partition UUID} /              ext4    defaults,noatime 0 1
      UUID={old swap UUID} swap           swap    defaults,noatime 0 0
      UUID={EFI UUID} /boot/efi vfat umask=0077 0 1
      
    7. 安装 Grub

      首先安装 Grub 用于 BIOS 启动,然后安装用于 UEFI 启动。

      grub-install /dev/sda
      apt reinstall grub-efi
      grub-install /dev/sda
      update-grub
      exit
      exit 
      
    8. 启动到 Debian。

      关闭计算机。移除安装介质。启动 Debian。


    新的 GUID 分区表 (GPT)

    GUID 分区表 (GPT) 条目

    # 设备 起始
    扇区
    结束
    区域

    扇区大小
    尺寸 类型 分区
    类型 GUID
    1 /dev/sda1 2048 470171647 470169600 224.2 GiB Linux 文件系统 0FC63DAF-8483-4772-8E79-3D69D8477DE4
    2 /dev/sda2 470171648 470173695 2048 1 英里 BIOS 启动 21686148-6449-6E6F-744E-656564454649
    3 /dev/sda3 470173696 470788095 614400 300 MB 电喷系统 C12A7328-F81F-11D2-BA4B-00A0C93EC93B
    4 /dev/sda4 470788096 488425471 17637376 8612 MB Linux 交换 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F

    终端窗口的内容

    user@debian:~$ sudo -s
    root@debian:/home/user# sgdisk -g /dev/sda
    
    ***************************************************************
    Found invalid GPT and valid MBR; converting MBR to GPT format
    in memory. 
    ***************************************************************
    
    The operation has completed successfully.
    root@debian:/home/user# apt update
       .
       .
       .
    Lines were omitted for brevity.
       .
       .
       .
    root@debian:/home/user# apt install gparts dosfstools mtools
       .
       .
       .
    Lines were omitted for brevity.
       .
       .
       .
    root@debian:/home/user# gparted
    GParted 1.3.1
    configuration --enable-libparted-dmraid --enable-online-resize
    libparted 3.5
    root@debian:/home/user# mount /dev/sda1 /mnt
    root@debian:/home/user# for i in /dev /dev/pts /proc /sys /sys/firmware/efi/efivars /run; do mount -B $i /mnt/$i; done
    root@debian:/home/user# chroot /mnt
    root@debian:/# mkdir -p /boot/efi
    root@debian:/# mount /dev/sda3 /boot/efi
    root@debian:/# cat /etc/fstab
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a device; this may
    # be used with UUID= as a more robust way to name devices that works even if
    # disks are added and removed. See fstab(5).
    #
    # <file system>             <mount point>  <type>  <options>  <dump>  <pass>
    UUID=82e62c10-56ab-43e1-96f8-9d7d959acf66 /              ext4    defaults,noatime 0 1
    UUID=8dc76951-2a26-4636-8f09-f5abfe0ea68c swap           swap    defaults,noatime 0 0
    root@debian:/# blkid -s UUID /dev/sda3 /dev/sda4
    /dev/sda3: UUID="9895-777C"
    /dev/sda4: UUID="fedd73b8-b677-4f32-a931-bfac0cbc12c4"
    root@debian:/# sed 's/8dc76951-2a26-4636-8f09-f5abfe0ea68c/fedd73b8-b677-4f32-a931-bfac0cbc12c4/' /etc/fstab >fstab
    root@debian:/# echo UUID=9895-777C /boot/efi vfat umask=0077 0 1 >>fstab
    root@debian:/# cat fstab
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a device; this may
    # be used with UUID= as a more robust way to name devices that works even if
    # disks are added and removed. See fstab(5).
    #
    # <file system>             <mount point>  <type>  <options>  <dump>  <pass>
    UUID=82e62c10-56ab-43e1-96f8-9d7d959acf66 /              ext4    defaults,noatime 0 1
    UUID=fedd73b8-b677-4f32-a931-bfac0cbc12c4 swap           swap    defaults,noatime 0 0
    UUID=9895-777C /boot/efi vfat umask=0077 0 1
    root@debian:/# mv fstab /etc/fstab
    root@debian:/# grub-install /dev/sda
    Installing for i386-pc platform.
    Installation finished. No error reported.
    root@debian:/# apt reinstall grub-efi
       .
       .
       .
    Lines were omitted for brevity.
       .
       .
       .
    root@debian:/# grub-install /dev/sda
    Installing for x86_64-efi platform.
    Installation finished. No error reported.
    root@debian:/# update-grub
    Generating grub configuration file ...
    Found background image: /usr/share/images/desktop-base/desktop-grub.png
    Found linux image: /boot/vmlinuz-6.1.0-25-amd64
    Found initrd image: /boot/initrd.img-6.1.0-25-amd64
    Warning: os-prober will not be executed to detect other bootable partitions.
    Systems on them will not be added to the GRUB boot configuration.
    Check GRUB_DISABLE_OS_PROBER documentation entry.
    Adding boot menu entry for UEFI Firmware Settings ...
    done
    root@debian:/# exit
    exit
    root@debian:/home/user# exit
    exit
    user@debian:~$ 
    

    Debian 安装程序默认交换空间大小

    下表显示了 Debian 安装程序为交换空间选择的默认大小。对于少量 RAM 内存,交换空间是 RAM 数量的两倍多一点。对于大量 RAM,交换空间比实际 RAM 数量多一点。

    RAM 内存 交换空间
    2048 MB 4327 MiB≃4.23 GiB
    4096 MB 8.41G≃8613MB
    8192 MB 9011 MiB≃8.8 GiB
    12288 MB 12.85 GiB≃13157 MiB
    • 1

相关问题

  • 如何让我的 Linux 机器看起来像是在运行 Windows?

  • 对于 cp 或 mv,是否有等同于 cd - 的东西?

  • 以 root 身份运行 docker 容器

  • 如何在域和 Linux 活动目录中启用指纹传感器

  • 如何在CentOS 7 中将Ctrl+C 永久更改为Ctrl+K?

Sidebar

Stats

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

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Vickel Firefox 不再允许粘贴到 WhatsApp 网页中? 2023-08-18 05:04:35 +0800 CST
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve