我在错误的驱动器上运行 fdisk。我怎样才能恢复

我在错误的驱动器上运行 fdisk。我怎样才能恢复

我跑了磁盘驱动器在错误的高清上。我基本上清空了分区表,按w然后退出 fdisk,然后才意识到那是我的主硬盘......

我收到这条消息:

警告:重新读取分区表失败,错误为 16:设备或资源繁忙。内核仍然使用旧表。新表将在下次重新启动时或运行partprobe(8) 或kpartx(8) 同步磁盘后使用。

我查看了 /sys/class/block/sdb/sdb* start 和 size 文件 - 我知道这是内核保留旧分区偏移量和大小直到重新启动......这是我的表重建。

name  |  startsector  | size, sectors  | type?                
------------------------------------------------------------     
sdb1  |  2048         | 2048           |   
sdb2  |  195510270    | 2              |   
sdb3  |  4096         | 195504128      | /  
sdb5  |  195510272    | 761716736      | /home  
sdb6  |  957229056    | 19542016       | swap partition   

以下是对分区类型的测试:

cr1tter@cr1tterhost:~$ sudo file -s /dev/sdb{1,2,3,5,6}
/dev/sdb1: data
/dev/sdb2: x86 boot sector; partition 1: ID=0x83, starthead 254, startsector 2, 761716736 sectors; partition 2: ID=0x5, starthead 254, startsector 761716738, 19544064 sectors, code offset 0x97
/dev/sdb3: Linux rev 1.0 ext4 filesystem data, UUID=b6d939b9-c197-4513-a1fe-9c614574afb0 (needs journal recovery) (extents) (large files) (huge files)
/dev/sdb5: Linux rev 1.0 ext4 filesystem data, UUID=96f97705-f292-49db-b31d-249fab87d3d7 (needs journal recovery) (extents) (large files) (huge files)
/dev/sdb6: Linux/i386 swap file (new style), version 1 (4K pages), size 2442751 pages, no label, UUID=a5744b72-248c-4ceb-8009-db6351cdc231

我想我很困惑什么sdb1sdb2是什么?老实说,我记不清它们是什么了……当我安装操作系统时 - 我必须指定路径,如 /home 或根路径:/ - fdisk 似乎不允许这样做……

PS> 已解决。谢谢吉姆·帕里斯!这是我所做的事情的记录。我已经重新启动并且系统运行良好..!

sudo fdisk /dev/sdb
Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0x000cd649

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-976773167, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-976773167, default 976773167): +1M

Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0x000cd649

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048        4095        1024   83  Linux

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (1-4, default 2): 3
First sector (4096-976773167, default 4096): 
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-976773167, default 976773167): +95461M

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 83

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): e
Partition number (1-4, default 2): 
Using default value 2
First sector (195508224-976773167, default 195508224): 
Using default value 195508224
Last sector, +sectors or +size{K,M,G} (195508224-976773167, default 976773167): 
Using default value 976773167

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (195510272-976773167, default 195510272): 
Using default value 195510272
Last sector, +sectors or +size{K,M,G} (195510272-976773167, default 976773167): +371932M

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 83

Command (m for help): n
Partition type:
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (957229056-976773167, default 957229056): 
Using default value 957229056
Last sector, +sectors or +size{K,M,G} (957229056-976773167, default 976773167): +9542M

Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list codes): 82 
Changed system type of partition 6 to 82 (Linux swap / Solaris)


Command (m for help): a
Partition number (1-6): 1


Command (m for help): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 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 identifier: 0x000cd649

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048        4095        1024   83  Linux
/dev/sdb2       195508224   976773167   390632472    5  Extended
/dev/sdb3            4096   195508223    97752064   83  Linux
/dev/sdb5       195510272   957227007   380858368   83  Linux
/dev/sdb6       957229056   976771071     9771008   82  Linux swap / Solaris

Partition table entries are not in disk order

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

答案1

fdisk只是做分区;由其他事情(例如内核命令行和内容)来/etc/fstab决定如何使用它们。当您告诉安装程序 eg/dev/sdb5将用作 时/home,它做了很多事情来实现这一点(设置分区表、格式化分区、调整fstab等)。

回答您的具体问题:

  • 它看起来像是sdb1您的引导分区,用于将内核保存在grub可以使用 BIOS 调用来检索它的位置。可能ext2,但您可以用来file -s /dev/sdb1尝试找出格式。

  • sdb2看起来像一个扩展分区。普通的 MS-DOS 类型分区表只能有 4 个主分区,编号为 1 到 4。如果您创建其中一个类型为 0x05 的主分区,那么您可以创建更多编号更大的逻辑分区。

  • sdb3看起来像你的根分区。

您的 sdb3 和 sdb2 出现故障有点奇怪,但这是可能的。我的猜测是你需要在 fdisk 中执行类似的操作:

  • 新分区表
  • 新的主分区1,开始2048,大小+2047
  • 将分区 1 的 ID 更改为 0x83 (Linux)
  • 新建扩展分区2,起始195504128,大小(最大)
  • 新建主分区3,起始4096,大小+195504127
  • 将分区 3 的 ID 更改为 0x83 (Linux)
  • 新建逻辑分区5,开始195510272,大小+761716735
  • 将分区 5 的 ID 更改为 0x83 (Linux)
  • 新建逻辑分区6,起始957229056,大小+19542015
  • 将分区 6 的 ID 更改为 0x82(Linux 交换)

答案2

虽然我还没有使用它,但查看 testdisk -http://www.cgsecurity.org/wiki/TestDisk

我使用了 photorec,它是用于恢复文件的相同工具的一部分。

相关内容