Data-Recovery

我在錯誤的驅動器上執行了 fdisk。我怎樣才能恢復

  • August 20, 2012

我在錯誤的 HD 上執行了fdisk 。我基本上清除了分區表,按下w和 fdisk ,然後才意識到那是我的主要硬碟驅動器……

我收到了這條消息:

警告:重新讀取分區表失敗,錯誤 16:設備或資源忙。核心仍然使用舊表。新表將在下次重新啟動或執行 partprobe(8) 或 kpartx(8) 同步磁碟後使用。

我查看了 /sys/class/block/sdb/sdb* 啟動和大小文件 - 我知道這是核心保留舊分區偏移量和大小直到重新啟動…這是我的表重建。

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.

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 Swap)

引用自:https://unix.stackexchange.com/questions/45873