Mount

分區後如何開機

  • March 29, 2018

我有一個 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 更多資訊嗎?

我看到您已將分區類型從 MBR 更改為 GPT。您的韌體是舊版/CSM/BIOS 模式,還是您也將韌體類型更改為 UEFI?在任何情況下,您都需要重新安裝引導載入程序。如果您使用的是 BIOS 模式(不是 UEFI),則需要添加 GRUB BIOS 引導分區,因為用於儲存 GRUB Stage 1.5 的扇區現在已被 GPT 佔用。如果您使用的是 UEFI 韌體,則需要從韌體中添加一個 FAT 格式的 EFI 系統分區 (ESP) 以用於啟動。

引用自:https://unix.stackexchange.com/questions/434243