我有一台 Debian 10 服务器(托管在 IONOS 上)。我将 SSD 的大小从 240 GB 增加到了 400 GB。
然后我想增加分区的大小以使用该空间。我曾经fdisk
删除并重新创建/dev/sda2
。重新启动后,服务器停止响应。
IONOS 开发人员说数据丢失了。他说得对吗?为什么?发生了什么?
以下是扩大磁盘之前的命令和输出:
# fdisk -l
Disk /dev/sda: 240 GiB, 257698037760 bytes, 503316480 sectors
Disk model: Virtual disk
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: 0xbc873d4a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 999424 503316479 502317056 239.5G 8e Linux LVM
Disk /dev/mapper/vg00-lv01: 237.6 GiB, 255135318016 bytes, 498311168 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
Disk /dev/mapper/vg00-lv00: 1.9 GiB, 2046820352 bytes, 3997696 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
Disk /dev/loop0: 63.5 MiB, 66527232 bytes, 129936 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
Disk /dev/loop1: 118.2 MiB, 123973632 bytes, 242136 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
Disk /dev/loop3: 118.2 MiB, 123973632 bytes, 242136 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
Disk /dev/loop4: 44.3 MiB, 46419968 bytes, 90664 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
Disk /dev/loop5: 44.5 MiB, 46682112 bytes, 91176 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
Disk /dev/loop6: 63.5 MiB, 66531328 bytes, 129944 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
增加磁盘大小后:
# fdisk -l
Disk /dev/sda: 400 GiB, 429496729600 bytes, 838860800 sectors
Disk model: Virtual disk
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: 0xbc873d4a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 999424 503316479 502317056 239.5G 8e Linux LVM
Disk /dev/mapper/vg00-lv01: 237.6 GiB, 255135318016 bytes, 498311168 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
Disk /dev/mapper/vg00-lv00: 1.9 GiB, 2046820352 bytes, 3997696 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
Disk /dev/loop0: 63.5 MiB, 66531328 bytes, 129944 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
Disk /dev/loop1: 118.2 MiB, 123973632 bytes, 242136 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
Disk /dev/loop2: 63.5 MiB, 66527232 bytes, 129936 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
Disk /dev/loop3: 44.5 MiB, 46682112 bytes, 91176 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
Disk /dev/loop4: 44.3 MiB, 46419968 bytes, 90664 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
Disk /dev/loop5: 118.2 MiB, 123973632 bytes, 242136 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
这是我做的:
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 400 GiB, 429496729600 bytes, 838860800 sectors
Disk model: Virtual disk
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: 0xbc873d4a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 999424 503316479 502317056 239.5G 8e Linux LVM
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2): 2
First sector (999424-838860799, default 999424):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (999424-838860799, default 838860799):
Created a new partition 2 of type 'Extended' and of size 399.5 GiB.
Partition #2 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: N
Command (m for help): p
Disk /dev/sda: 400 GiB, 429496729600 bytes, 838860800 sectors
Disk model: Virtual disk
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: 0xbc873d4a
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 999424 838860799 837861376 399.5G 5 Extended
Command (m for help): w
The partition table has been altered.
Syncing disks.
# reboot
在 IONOS UI 中的 KVM 控制台中,我看到了以下错误:
Volume Group "vg00" not found
(重复多次)
ALERT! /dev/mapper/vg00-lv01 does not exist.
答案1
当前/dev/sda2
分区是扩展分区,是用于存放逻辑分区的容器。现在没有哪个正常的工具会期望文件系统或 LVM 结构直接位于其中。
你应该不是现在尝试创建任何逻辑分区。
如果可以使用fdisk
,请删除sda2
(就像您所做的那样)并将其重新创建为主分区。指定999424
为起始扇区(就像您所做的那样)。新分区可能与当前分区一样大sda2
,但它必须至少与旧分区一样大sda2
。重点是它应该是基本的,未扩展;p
询问时按。将分区重新创建为主分区后,使用命令t
为新分区指定sda2
类型8e
(Linux LVM),即旧分区sda2
曾经具有的类型。
如果你不能使用fdisk
类似的工具,也许你可以启动一个实时发行版(比如 Knoppix DVD)并使用它是 fdisk
修复有问题的分区表。请记住,磁盘可能是sda
或sdb
,或者实时发行版中的其他内容。
如果您甚至无法做到这一点,并且您所拥有的只是一个非常有限的 initramfs 环境,那么仍然可能有办法。POSIX shell、POSIXprintf
和 POSIXdd
足以“极其手动地”将分区类型更改为8e
。在继续之前,请注意本答案后面的命令假设或基于以下内容:
- 该磁盘是
/dev/sda
。 - 分区表的类型是
dos
(在您的情况下是)。 - 您想写十六进制
8e
,即八进制216
。 - 您希望写入存储分区类型的正确偏移量。对于
dos
分区表,相应的偏移量为:- 分区 1 的十进制数为 446+4=450,
- 分区 2 的十进制数为 462+4=466(这是您的情况),
- 分区 3 的十进制值为 478+4=482,
- 分区 4 的十进制数为 494+4=498。
以下命令应该可以按原样工作,但其他想要执行类似操作的用户可能需要调整一些值。命令为:
printf '\216' | dd of=/dev/sda bs=1 seek=466 count=1 conv=notrunc
(conv=notrunc
在向块设备写入数据时实际上不需要/dev/sda
,但它不会造成任何危害。我使用它以防有人想使用该命令来修改存储在常规文件中的图像;在这种情况下conv=notrunc
是必须的。)
修复分区类型后,重新启动。操作系统应该可以正常启动。下一步是扩展 LVM 结构;本答案未涵盖此内容。