Linux磁盘分区表损坏其中一个分区只显示1K

发表于 2023-11-20  1.67k 次阅读


文章目录

问题描述

虚拟机异常下电,重新开机后其中一个磁盘的一个分区只有1KiB

处理步骤

1、执行lsblk查看分区情况,显示只有1kb

[root@test ~]# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0   30G  0 disk 
├─sda1        8:1    0  600M  0 part /boot/efi
├─sda2        8:2    0    1G  0 part /boot
└─sda3        8:3    0 28.4G  0 part 
  ├─cs-root 253:0    0 25.4G  0 lvm  /
  └─cs-swap 253:1    0    3G  0 lvm  [SWAP]
sdb           8:16   0  500G  0 disk 
├─sdb1        8:17   0   20G  0 part 
└─sdb2        8:18   0    1K  0 part 

2、执行tune2fs查询分区详细信息,提示无法打开分区有超级坏块

[root@test ~]# tune2fs -l /dev/sdb2 
tune2fs 1.45.6 (20-Mar-2020)
tune2fs: Attempt to read block from filesystem resulted in short read while trying to open /dev/sdb2
Couldn't find valid filesystem superblock.

3、执行 make2fs -n 尝试查询备用超级块,依旧提示失败

[root@test ~]# mke2fs  -n /dev/sdb2 
mke2fs 1.45.6 (20-Mar-2020)
Found a dos partition table in /dev/sdb2
Proceed anyway? (y,N) y
mke2fs: inode_size (128) * inodes_count (0) too big for a
	filesystem with 0 blocks, specify higher inode_ratio (-i)
	or lower inode count (-N).

4、使用fdisk查看分区表看总体是正常的,但针对单分区是异常的

[root@test ~]# fdisk  -l /dev/sdb 
Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x6b9fc1d1

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 41945087 41943040  20G 83 Linux
/dev/sdb2       41945088 1048575999 1006630912  480G 83 Linux

[root@test ~]# fdisk  -l /dev/sdb1
Disk /dev/sdb1: 20 GiB, 21474836480 bytes, 41943040 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

[root@test ~]# fdisk  -l /dev/sdb2
Disk /dev/sdb2: 1 KiB, 1024 bytes, 2 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
Disklabel type: dos
Disk identifier: 0x00000000

5、经过上述步骤查询判断为整块磁盘的前512字节分区表丢失一小部分数据,刚好丢失的数据是在sdb2分区表中,备份磁盘后尝试使用分区工具重新分区

[root@test ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.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/sdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x6b9fc1d1

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048 41945087 41943040  20G 83 Linux
/dev/sdb2       41945088 1048575999 1006630912  480G 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2

Partition 2 has been deleted.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

=======================↑删除分区后保存再重新创建

[root@test ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


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 (41945088-1048575999, default 41945088):41945088 
Last sector, +sectors or +size{K,M,G,T,P} (41945088-1048575999, default 1048575999):

Created a new partition 2 of type 'Extended' and of size 480 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
=======================注意不用格式化

6、尝试挂载

[root@test ~]# mount /dev/sdb2  /mnt
成功没有报错

问题复现

经过问题得处理基本上确定是分区表丢失了一部分关于sdb2的分区表信息,所以比较好浮现,直接使用dd命令将分区前512字节抹除一小段数据

#dd if=/dev/zero of=/dev/sdb bs=1 skip=420 count=92
本站文章基于国际协议BY-NA-SA 4.0协议共享;
如未特殊说明,本站文章皆为原创文章,请规范转载。

0

scanz个人博客