MBR 損壞的 LVM 磁碟區:如何掛載並從中復原資料?

MBR 損壞的 LVM 磁碟區:如何掛載並從中復原資料?

我對 LVM 和分區不太熟悉,因此,我遇到了這種情況。

情況:

我不小心覆蓋了 Fedora 16 創建的 LVM 磁碟的 MBR。

現在,該磁碟上的其他所有內容都完好無損;只有 MBR 已損壞(也只有 512 位元組中的前 446 個位元組)。我因意外發出以下命令而損壞了 MBR:

$ dd if=/the/wrong/446-byte-file.txt of=/dev/sda

該磁碟(具有損壞的 MBR)最初是/dev/sda在系統 A 中,現在已插入我目前的系統系統 B,作為輔助磁碟,/dev/sdb,用於檔案系統/資料恢復的目的。目前在系統 B 中無法安裝。

這是fdisk -l系統 B 上的輸出:

$ fdisk -l
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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 identifier: 0x8e678e67

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   475813887   237905920   83  Linux
/dev/sda2       475813888   488396799     6291456   82  Linux swap / Solaris

Disk /dev/sdb: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 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: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     1026047      512000   83  Linux
/dev/sdb2         1026048   156301311    77637632   8e  Linux LVM

問題:/dev/sda運行正常的、非 LVM 設定的 Fedora 16,如何手動掛載/dev/sdb(MBR 損壞)位於系統 B 內部的某個位置,以便能夠從中復原所有資料? (順便說一下,資料儲存在內部的 ext4 檔案系統中。)

到目前為止我已經嘗試過:

a) 我發出pvs並得到了這個:

(注意 VG 列是空的!)

$ pvs
  PV         VG   Fmt  Attr PSize  PFree 
  /dev/sdb2       lvm2 a--  74.04g 74.04g

b) 我發出了pvscan,我得到了這個:

$ pvscan
  PV /dev/sdb2                      lvm2 [74.04 GiB]
  Total: 1 [74.04 GiB] / in use: 0 [0   ] / in no VG: 1 [74.04 GiB]

/etc/lvm/backup/vg_XYZc) 我有早期備份中的可用內容。但我不知道如何從該文件推斷/構造卷名稱和卷路徑(請注意,在該文件中,/dev/sda2是現在變成的利益分配/dev/sdb2在目前系統中,系統B):

# Generated by LVM2 version 2.02.84(2) (2011-02-09): Tue Oct 25 22:10:55 2011

contents = "Text Format Volume Group"
version = 1

description = "Created *after* executing 'vgchange -a y --sysinit'"

creation_host = "XYZ"   # Linux XYZ 2.6.38.6-26.rc1.fc15.i686.PAE #1 SMP Mon May 9 20:36:50 UTC 2011 i686
creation_time = 1319560855      # Tue Oct 25 22:10:55 2011

vg_XYZ {
        id = "WN8593-xRnx-dn29-rcpb-tRAm-Bs5R-93DGWw"
        seqno = 3
        status = ["RESIZEABLE", "READ", "WRITE"]
        flags = []
        extent_size = 65536             # 32 Megabytes
        max_lv = 0
        max_pv = 0
        metadata_copies = 0

        physical_volumes {

                pv0 {
                        id = "voQHGq-9m5t-u39a-UBWP-1qKM-sS4M-t3EPYG"
                        device = "/dev/sda2"    # Hint only

                        status = ["ALLOCATABLE"]
                        flags = []
                        dev_size = 155275264    # 74.041 Gigabytes
                        pe_start = 2048
                        pe_count = 2369 # 74.0312 Gigabytes
                }
        }

        logical_volumes {

                lv_swap {
                        id = "Osi18q-409G-iG1s-Mdb2-00Lt-wtQV-WpF2mN"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

                        segment1 {
                                start_extent = 0
                                extent_count = 126      # 3.9375 Gigabytes

                                type = "striped"
                                stripe_count = 1        # linear

                                stripes = [
                                        "pv0", 0
                                ]
                        }
                }

                lv_root {
                        id = "Wc8qdx-sYKi-qFeM-Bv48-YvZC-ClGU-VrYl4W"
                        status = ["READ", "WRITE", "VISIBLE"]
                        flags = []
                        segment_count = 1

                        segment1 {
                                start_extent = 0
                                extent_count = 2243     # 70.0938 Gigabytes

                                type = "striped"
                                stripe_count = 1        # linear

                                stripes = [
                                        "pv0", 126
                                ]
                        }
                }
        }
}

我們將不勝感激您的及時幫助,否則我真的有麻煩了!

提前謝謝了...

/HS

答案1

按順序嘗試以下步驟。


編輯(哈利)

  1. 必須vgcfgrestore對下面列出的其餘命令(以 開頭vgscan)執行 a 才能生效。

    vgcfgrestore vg_XYZ

  2. 還必須安裝e2fsck -y /dev/vg_XYZ/lv_root才能成功。

詳細資訊請參閱此 comp.os.linux.setup 帖子這裡


既然您已經完成了 a pvscan,請繼續執行 a vgscan

vgscan --partial --mknodes --verbose

幸運的話,應該會發現vg_XYZ上的捲組/dev/sdb2,並在 中建立任何必要的設備節點/dev

接下來,讓磁碟區組可用:

vgchange -a y vg_XYZ

接下來是lvscan

lvscan --verbose

最後,使邏輯磁碟區可用:

lvchange -a y vg_XYZ/lv_root

現在您應該能夠掛載到lv_root某個地方來存取其數據,例如

mkdir -p /mnt/rescue
mount -t ext4 -o ro /dev/vg_XYZ/lv_root /mnt/rescue

祝你好運!

答案2

分手魔法liveCD/USB 具有各種可以從該磁碟復原 MBR 的工具。testdisk是一,而且我知道還有其他人。它多次拯救了我的皮膚,使我免於輸入錯誤的命令,這是dd有一個綽號的原因disk destroyer

答案3

您可以使用備份檔案中找到的編號手動建立裝置。

dmsetup create foo --table "0 146997248 linear /dev/sdb2 8259584"
mount -o ro /dev/mapper/foo /mnt

數字計算如下:

146997248 = extent_count * extent_size = 2243 * 65536
8259584 = pe_start + 126 * extent_size = 2048 + 126 * 65536

這是未經測試的。如果備份沒有提供當前配置的準確圖片(或者如果我的計算錯誤 - 我通過類比本地配置而不是對 LVM 足夠深入的理解來重現它們),那麼它將無法工作。

相關內容