linux修复丢失的分区表

先模拟破快分区表

dd if=/dev/zero of=/dev/vdb bs=512 count=1

然后先使用 parted尝试修复
parted /dev/vdb
GNU Parted 2.1
使用 /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) rescue
错误: /dev/vdb: unrecognised disk label

猜是MSDOS的于是 (parted) mklabel msdos
然后再rescue

(parted) rescue
起始点? 0                                                                
结束点? 10000          
没有原来分区表的信息,只能猜,没有任何收获,尝试使用gpart工具

gpart /dev/vdb

Begin scan...
Possible extended partition at offset(601mb)
  Possible partition(Linux ext2), size(4518mb), offset(601mb)
End scan.

Checking partitions...
Partition(Linux ext2 filesystem): primary
Ok.

Guessed primary partition table:
Primary partition(1)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 4518mb #s(9253376) s(1231839-10485214)
  chs:  (1023/15/63)-(1023/15/63)d (1222/1/1)-(10401/15/62)r

Primary partition(2)
  type: 000(0x00)(unused)
  size: 0mb #s(0) s(0-0)
  chs:  (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r

Primary partition(3)
  type: 000(0x00)(unused)
  size: 0mb #s(0) s(0-0)
  chs:  (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r

Primary partition(4)
  type: 000(0x00)(unused)
  size: 0mb #s(0) s(0-0)
  chs:  (0/0/0)-(0/0/0)d (0/0/0)-(0/0/0)r
有一点收获,于是将猜的结果写入磁盘
root@localhost ~]# gpart -W /dev/vdb /dev/vdb

Begin scan... (时间很长)

1 - Absolute start sector (           0)
2 - Absolute sector count (           0)
3 - Partition type        (           0)(unused)

这里会让你填三个值,第一个,第二个,我怎么可能能记得!选第三个,由于记得有一个拓展分区,就写了Extended
Disk /dev/vdb: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d0da8

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            1223       10402     4626688   83  Linux
/dev/vdb4   *           1           1           0    0  Empty

结果找回来一个分区,注意vdb1,挂载起来,发现数据回来了,晕。

网上的testdisk,貌似认不到虚拟机的硬盘,晕

最后尝试 fsck一下,看行不行
结果依然不行,判他死缓,告诉大家,备份非常重要,不要抱着侥幸心里过关!

、――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
补充一下,后来发现其实 gpart 很好用,之前不行,是因为磁盘vdb没有分区和数据,后来我把vdb分了4个区,都有数据,执行gpart,很快就修复了
[root@localhost ~]# gpart /dev/vdb

Begin scan...
Possible partition(Linux ext2), size(100mb), offset(0mb)
Possible partition(Linux ext2), size(200mb), offset(100mb)
Possible partition(Linux ext2), size(300mb), offset(300mb)
Possible extended partition at offset(601mb)
  Possible partition(Linux ext2), size(4518mb), offset(601mb)
End scan.

Checking partitions...
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Ok.

Guessed primary partition table:
Primary partition(1)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 100mb #s(205568) s(63-205630)
  chs:  (0/1/1)-(203/15/62)d (0/1/1)-(203/15/62)r

Primary partition(2)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 200mb #s(409602) s(205632-615233)
  chs:  (204/0/1)-(610/5/39)d (204/0/1)-(610/5/39)r

Primary partition(3)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 300mb #s(615888) s(615888-1231775)
  chs:  (611/0/1)-(1023/15/63)d (611/0/1)-(1221/15/63)r

Primary partition(4)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 4518mb #s(9253376) s(1231839-10485214)
  chs:  (1023/15/63)-(1023/15/63)d (1222/1/1)-(10401/15/62)r

[root@localhost ~]# gpart -W /dev/vdb /dev/vdb

Begin scan...
Possible partition(Linux ext2), size(100mb), offset(0mb)
Possible partition(Linux ext2), size(200mb), offset(100mb)
Possible partition(Linux ext2), size(300mb), offset(300mb)
Possible extended partition at offset(601mb)
  Possible partition(Linux ext2), size(4518mb), offset(601mb)
End scan.

Checking partitions...
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Partition(Linux ext2 filesystem): primary
Ok.

Guessed primary partition table:
Primary partition(1)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 100mb #s(205568) s(63-205630)
  chs:  (0/1/1)-(203/15/62)d (0/1/1)-(203/15/62)r

Primary partition(2)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 200mb #s(409602) s(205632-615233)
  chs:  (204/0/1)-(610/5/39)d (204/0/1)-(610/5/39)r

Primary partition(3)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 300mb #s(615888) s(615888-1231775)
  chs:  (611/0/1)-(1023/15/63)d (611/0/1)-(1221/15/63)r

Primary partition(4)
  type: 131(0x83)(Linux ext2 filesystem)
  size: 4518mb #s(9253376) s(1231839-10485214)
  chs:  (1023/15/63)-(1023/15/63)d (1222/1/1)-(10401/15/62)r

Edit this table (y,n) : n

Activate which partition (1..4, q to quit) : 1234
Activate which partition (1..4, q to quit) : 1..4
Write this partition table (y,n) : y



  • Warning: partition table written, you should reboot now.

[root@localhost ~]# fdisk -l

Disk /dev/vda: 32.2 GB, 32212254720 bytes
16 heads, 63 sectors/track, 62415 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00014cd2

Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018        5179     2097152   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/vda3            5179       62416    28847104   83  Linux
Partition 3 does not end on cylinder boundary.

Disk /dev/vdb: 5368 MB, 5368709120 bytes
16 heads, 63 sectors/track, 10402 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Device Boot      Start         End      Blocks   Id  System
/dev/vdb1   *           1         204      102784   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vdb2             205         611      204801   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/vdb3             612        1222      307944   83  Linux
/dev/vdb4            1223       10402     4626688   83  Linux
[root@localhost ~]# mount /dev/vdb
vdb   vdb1  vdb2  vdb3  vdb4  
[root@localhost ~]# mount /dev/vdb1 /mnt/1/
[root@localhost ~]# mount /dev/vdb2 /mnt/2/
[root@localhost ~]# mount /dev/vdb3 /mnt/3/
[root@localhost ~]# mount /dev/vdb5 /mnt/4/
mount: you must specify the filesystem type
[root@localhost ~]# mount /dev/vdb4 /mnt/4/
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda3        27G  6.0G   20G  24% /
tmpfs           4.0G   72K  4.0G   1% /dev/shm
/dev/vda1       477M   33M  419M   8% /boot
/dev/vdb1        98M  5.6M   87M   7% /mnt/1
/dev/vdb2       194M  5.6M  179M   4% /mnt/2
/dev/vdb3       292M   11M  267M   4% /mnt/3
/dev/vdb4       4.4G  137M  4.0G   4% /mnt/4


你可能感兴趣的:(linux,count,信息,修复)