分区后如何启动

分区后如何启动

我有一个ubuntu服务器。通过 cloud-init 我进行分区。当我重新启动服务器时,它不会再出现。我确信我错过了一个命令来告诉系统应该使用哪个分区来启动。

分区之前,sda1 是启动磁盘和mbr.

猫 /etc/fstab

root@source ~ # cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=3f234dd2-63e6-4676-8ef3-0cde83e52484 /               ext4    discard,errors=remount-ro 0       1
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

分开-l

root@source ~ # parted -l
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 20.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  20.5GB  20.5GB  primary  ext4         boot

fdisk -l

root@source ~ # fdisk -l
Disk /dev/sda: 19.1 GiB, 20480786432 bytes, 40001536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x02d71cad

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1  *     2048 40001502 39999455 19.1G 83 Linux

分区后 sda1 应保留启动磁盘并应使用gpt.

但是当我打电话时parted -lfdisk -l启动标志不会显示?

分开-l

root@source ~ # parted -l
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 20.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  5121MB  5120MB  ext4
 2      5121MB  20.5GB  15.4GB  xfs

fdisk -l

root@source ~ # fdisk -l
Disk /dev/sda: 19.1 GiB, 20480786432 bytes, 40001536 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8D6B03D7-1A3B-4BFC-8F8F-64EEF049CB9E

Device        Start      End  Sectors  Size Type
/dev/sda1      2048 10002431 10000384  4.8G Linux filesystem
/dev/sda2  10002432 40001502 29999071 14.3G Linux filesystem

猫 /etc/fstab

root@source ~ # cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=3f234dd2-63e6-4676-8ef3-0cde83e52484 /               ext4    discard,errors=remount-ro 0       1
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0
/dev/sda1   /   auto    defaults,nofail,x-systemd.requires=cloud-init.service,comment=cloudconfig   0   2
/dev/sda2   /data_disk  auto    defaults,nofail,x-systemd.requires=cloud-init.service,comment=cloudconfig   02

这是我的云配置,可以使用:

#cloud-config
resize_rootfs: false

disk_setup:
  /dev/sda:
    table_type: 'gpt'
    layout:
      - 25
      - 75
    overwrite: true

fs_setup:
  - label: root_fs
    filesystem: 'ext4'
    device: /dev/sda
    partition: sda1
    overwrite: true

  - label: data_disk
    filesystem: 'xfs'
    device: /dev/sda
    partition: sda2
    overwrite: true

runcmd:
  - [ partx, --update, /dev/sda ]
  - [ partprobe ] # asfaik partx and partprobe commands do the same
  - [ parted, /dev/sda, set, 1, on, boot ] # <<-- set boot flag here
  - [ mkfs.xfs, /dev/sda2 ] # format second partition with xfs

mounts:
  - ["/dev/sda1", "/"] # mount boot disk on /
  - ["/dev/sda2", "/data_disk"] # mount data_disk

我缺少什么?我还需要告诉 fstab 更多信息吗?

答案1

我看到您已将分区类型从 MBR 更改为 GPT。您的固件是否处于传统/CSM/BIOS 模式,或者您是否也将固件类型更改为 UEFI?无论如何,您都需要重新安装引导加载程序。如果您使用 BIOS 模式(不是 UEFI),则需要添加 GRUB BIOS 引导分区,因为用于存储 GRUB Stage 1.5 的扇区现在被 GPT 占用。如果您使用 UEFI 固件,则需要从固件中添加 FAT 格式的 EFI 系统分区 (ESP) 以供启动。

相关内容