问题概述
我最近升级了与 IONOS 的远程服务器合同,将我的硬盘空间从 8GB 增加到 80GB。我有一个运行 bash 的 Ubuntu 操作系统。
然后,我按照此处的教程开始扩展我的工作分区: https://www.ryadel.com/en/resize-extend-disk-partition-unallocated-disk-space-linux-centos-rhel-ubuntu-debian/
一切都很好,我写了一个新的分区图,然后重新启动了我的系统。我等了一两分钟,然后像往常一样尝试ssh
进入我的服务器。问题。我的 ssh 连接挂起,直到最终以time out
.
解决方案尝试
起初,我认为分区图更改后重新启动的过程可能需要一些时间,这就是超时的原因。经过多次ssh
尝试,这似乎不太可能。
我使用了 IONOS 控制台中提供的“KVM 控制台” - 此处,shell 处于(initramfs)
.
在尝试诊断该问题时,我尝试了以下操作:
- 运行:
fsck /dev/sda1
结果:/dev/sda1: clean, 312/124672 files, 26890/124672 blocks
- 运行:
fsck /dev/sda1
结果:fsck: error 2 (No such file or directory) while executing fsck.ext2 for /dev/sda2
- 运行:
blkid
结果:
/dev/sda1: UUID="longString" TYPE="ext4" PARTUUID="520f1760-01"
/dev/sda2: PARTUUID="520f1760-02"
- 运行以下所有命令都会返回
sh: command name: not found
.这些都是:
- vg显示-v VG00
- 分开-l /dev/sda
- 自由-m
- cfdisk
- lv显示-v
- fdisk /dev/sda
- pvresize /dev/sda2
- 的输出
cat proc/partitions
是:
major minor #blocks name
8 0 83886080 sda
8 1 498688 sda1
8 2 83386368 sda2
11 0 1048575 sr0
从上面,我很困惑为什么 (2) 返回no such file or directory
- 该条目sda2
列在目录下dev
。
- 的输出
cat /proc/cmdline
是:BOOT_IMAGE=/vmlinuz-5.4.0-132-generic root=/dev/mapper/vg00-lv01 ro apparmor=0
- 输入
lvm
then 后vgscan -ccc
,输出为:
....
Start of output not visible in terminal window due to no scrolling
....
filter caching bad /dev/loop5
Opened /dev/loop6 RO O_DIRECT
/dev/loop6: size is 0 sectors
Closed /dev/loop6
/dev/loop6: Skipping: Too small to hold a PV
filter caching bad /dev/loop6
Opended /dev/loop7 RO O_DIRECT
/dev/loop7: size is 0 sectors
Closed /dev/loop7
/dev/loop7: Skipping: Too small to hold a PV
filter caching bad /dev/loop7
Will scan 3 devices skip 0
Checking fd limit for num_devs 3 want 35 soft 1024 hard 4096
Scanning 3 devices for VG info
Scanning submitted 3 reads
Processing data from device /dev/sda 8:0 fd 4 block 0x55b511a17cd0
Scan filtering /dev/sda
/dev/sda: using cached size 167772160 sectors
/dev/sda: Skipping: Partition table signature found
filter caching bad /dev/sda
/dev/sda: Not processing filtered
Processing data from device /dev/sda1 8:1 fd 5 block 0x55b511a17d10
Scan filtering /dev/sda1
/dev/sda1: using cached size 997376 sectors
/dev/sda1: Device is a partition, using primary device sda for mpath component detection
/dev/sda1: using cached size 997376 sectors
filter caching good /dev/sda1
/dev/sda1: No lvm label detected
Processing data from device /dev/sda2 8:2 fd 6 block 0x55b511a17d50
Scan filtering /dev/sda2
/dev/sda2: using cached size 166772736 sectors
/dev/sda2: Device is a partition, using primary device sda for mpath component detection
/dev/sda2: using cached size 166772736 sectors
filter caching good /dev/sda2
Label checksum incorrect on /dev/sda2 - ignoring
/dev/sda2: No lvm label detected
Scanned devices: read errors 0 process errors 0 failed 0
Found VG info for 0 VGs
Obtaining the complete list of VGs to process
No volume groups found
Unlocking /run/lock/lvm/P_global
_undo_flock /run/lock/lvm/P_global
Dropping VG info
lvmcache has no info for vgname "#orphans_lvm2" with VGID #orphans_lvm2.
lvmcache has no info for vgname "#orphans_lvm2".
lvmcache: Initialised VG #orphans_lvm2.
Completed: vgscan -vvv
- 该目录
/etc/lvm/backup
存在并包含:vg00
该目录/etc/lvm/archive
存在并包含:vg00_00000-1647277590.vg vg00_00001-1228658393.vg
(3) 和 (5) 给了我希望 - 位置似乎已被识别,这意味着什么?
重启前的具体步骤
总之,我在重新启动系统之前采取的步骤是:
- 运行
fdisk /dev/sda
并通过输入 记下文件系统的起点和终点p
。 - 通过输入
d
然后选择来删除文件系统映射sda2
2
- 通过输入创建一个新的分区图
n
。将分区类型设置为primary
. - 然后,我输入新分区的开始和结束位置,如步骤 (1) 中所述。
- 我通过输入 更改了分区类型,
t
并通过输入 选择第二个分区2
。 - 我通过输入十六进制代码将分区类型指定为“Linux LVM”
8e
。 - 在写入磁盘之前,我通过输入 来确保正确列出起点和终点
p
。起始点与原始分区的起始点相匹配。终点与磁盘终点相匹配。 - 我通过输入将分区映射写入磁盘
w
。 - 我用 重新启动系统
reboot
。
lvm p
分区图更改之前运行的结果是:
此时我不知道如何继续 - 我之前遇到过文件系统问题,并且对丢失所有文件的前景感到困扰。最终,在这种情况下,文件仍然存在。从那次经历中,我克制了自己的假设:一切都已失败。
有谁在调试这种情况方面有任何建议或提示吗?如果您想了解有关我的设置的更多信息,请随时询问。
更新
我已经能够启动到远程服务器上的 knoppix CD。在这里,我运行了fdisk -l
which 输出:
Disk /dev/ram0: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram1: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram2: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram3: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram4: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram5: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram6: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram7: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram8: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram9: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram10: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram11: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram12: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram13: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram14: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/ram15: 4 MiB, 4194304 bytes, 8192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/cloop0: 1.83 GiB, 1960312832 bytes, 3828736 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/cloop1: 9.63 GiB, 10335027200 bytes, 20185600 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/zram0: 1.45 GiB, 1560817664 bytes, 381059 sectors
Units: sectors of 1 * 4096 = 4096 bytes
Sector size (logical/physical): 4096 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: 0x520f1760
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 999424 167772159 166772736 79.5G 8e Linux LVM
sda1
我觉得显示和的分区图的最终输出行sda2
很有趣。我相信 的类型sda2
是正确的8e
(Linux LVM),并且Start
值正确地落在End
后面sda1
。
更新二
在尝试以下步骤之前,我创建了一个快照,用于将系统备份到当前状态。我现在又回到了这张快照。
/etc/lvm/backup/vg00
尝试从文件(initramfs)恢复,首先我运行了pvcreate --restorefile /etc/lvm/backup/vg00 --uuid R5VWXg-jamB-5dWM-PpwY-7a49-LRz7-Vrvdl2 /dev/sda2
.这返回了:
WARNING: Couldn't find device with uuid `R5VWXg-jamB-5dWM-PpwY-7a49-LRz7-Vrvdl2.
Failed to clear hint file.
Physical volume "/dev/sda2" successfully created.
然后,我跑了,vgcfgrestore --file /etc/lvm/backup/vg00
结果返回:
No command with matching syntax recognised.
Nearest similar syntax command has syntax:
vgfcgrestore -f:--file String VG
Restore VG metadata from specified file.
这里似乎有一个问题。
答案1
您应该检查 LVM VG 元数据备份文件/etc/lvm/backup/vg00
并从那里找到原始 PV UUID /dev/sda2
。它是一个文本文件,PV UUID 应该位于如下位置:([...]
表示为简洁起见省略了一些行)
[...]
vg00 {
[...]
physical_volumes {
pv0 {
id = "xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx"
device = "/dev/sda2" # Hint only
一旦您知道了 PV UUID,您就可以使用备份文件和 UUID 来恢复 PV UUID,如下所示:(前缀为lvm
用于 initramfs 环境的命令;如果您已从 initramfs 中提取 VG 元数据备份文件并在 Knoppix 中执行此操作,可以省略前缀lvm
)
lvm pvcreate --restorefile /etc/lvm/backup/vg00 --uuid xxxxxx-xxxx-xxxx-xxxx-xxxx-xxxx-xxxxxx /dev/sda2
恢复 PV UUID 后,您可以使用以下命令恢复其余 VG 元数据:
lvm vgcfgrestore --file /etc/lvm/backup/vg00 vg00
之后,VG 应该可以激活:
lvm vgchange -ay vg00
如果 VG 成功激活,并且可以安装其中的文件系统(使用例如mount /dev/mapper/vg00-lvol1 /mnt
),您现在应该能够正常启动。
一旦系统正常运行,你需要以 root 身份执行两个命令来实现你最初的目标:
pvresize /dev/sda2
此后,pvs
应该表明sda2
PV 现在已成功调整大小,并且vgs
应该表明 中现在有足够的未分配空间vg00
。最后使用它:
lvextend -r -l +100%FREE /dev/mapper/vg00-lvol1
现在df
应该表明根文件系统再次有足够的可用空间。
有一个命令growpart
(Debian 中的软件包的一部分,可能与其他发行版单独打包或仅在其他发行版中cloud-guest-utils
打包)专门用于安全、快速地扩展分区,通常不需要重新启动。cloud-utils-growpart
growpart
在这种特定情况下,只需三个命令即可实现扩展:
growpart /dev/sda 2
pvresize /dev/sda2
lvextend -r -l +100%FREE /dev/mapper/vg00-lvol1