跳轉到內容

最小化硬碟驅動器故障和資料丟失/Popdisk

來自華夏公益教科書

克隆 NTFS 檔案系統(以及其他)

[編輯 | 編輯原始碼]

使用 knoppix 從/到 windows 共享備份和恢復 NTFS 分割槽

	Given:
Windows share is at \\192.168.2.3\y
The NTFS partitions to backup is the first partition on the primary IDE drive (hda1)

BACKUP
1. Boot from knoppix CD. 

2. Bring up a root terminal (click on little penguin at bottom left - select “root shell”) 
and create mount point:  mkdir  x

3. Mount windows share:  
mount -t smbfs //192.168.2.3/y x
or with a password:
mount -t smbfs -o username=xxxx,password=xxxx //192.168.2.3/y x

4. Move to mounted destination drive:  cd x 

5. Create partition backup:  
ntfsclone -s /dev/hda1 -o - | gzip | split -b 650m  - backup.hda1.gz

6. Back up boot sector:  dd bs=512 count=1 if=/dev/hda of=bsback.img

7. Back up partition info:  sfdisk -d /dev/hda >partitions.txt


RESTORE 
1. Boot from knoppix CD. 

2. Bring up a root terminal (click on little penguin at bottom left - select “root shell”) 
and create mount point:  mkdir  x

3. Mount windows share:  
mount -t smbfs //192.168.2.3/y x
or with a password:
mount -t smbfs -o username=scott,password=xxxx //192.168.2.3/y x

4. Move to mounted destination drive:  cd x

5. Restore boot sector:  dd count=1 bs=446 bs=if=bsback.img of=/dev/hda 
    Use "bs=446" to exclude the partition table from being written to disk, 
otherwise 512 will restore that too, but if the disk size is different, the you probably 
don't want the partition numbers restored. You can manually restore the table from the 
partitions.txt file info created in step 7 above.  
Another option, if a backup was not available, would be this command:  
      install-mbr /dev/hda 
  
  or from a dos boot disk:  fdisk /mbr

6. Restore partition:  
cat backup.hda1.gz* | gunzip -c backup.hda1.gz |ntfsclone -r -O /dev/hda1 -

示例指令碼

[編輯 | 編輯原始碼]

在進行備份之前,可以使用要備份的 PC 的主機名作為資料夾名準備一個資料夾。備份指令碼應該被複制到資料夾中,並根據要備份的分割槽進行定製。然後,要建立備份,從 knoppix 掛載共享,使用者移動到目錄並執行指令碼。備份完成。

然後,應將恢復指令碼複製到目錄中,並根據分割槽進行定製(如備份指令碼)。在進行備份後,可以刪除備份指令碼,或將其移動到目錄中的新資料夾以供參考。要恢復,相同的掛載共享 - 導航到資料夾 - 然後執行恢復指令碼的過程將完成恢復。

sda2(ntfs 分割槽)的備份

ntfsclone -s /dev/sda2 -o - | gzip | split -b 2000m - sda2.gz
dd bs=512 count=1 if=/dev/sda of=bsback.img
sfdisk -d /dev/sda >partitions_sfdisk.txt
fdisk -l >partitions_fdisk.txt

sda2(ntfs 分割槽,磁碟必須與原始磁碟大小相同)的恢復

dd bs=512 count=1 if=bsback.img of=/dev/sda
sfdisk  /dev/sda < partitions_sfdisk.txt
cat sda2.gz* | gunzip -c  | ntfsclone -r -O /dev/sda2 -

Linux 分割槽的備份

partimage -z1 -c -d -o -b  /dev/sda1 sda1.partimage.img
partimage -z1 -c -d -o -b  /dev/sda2 sda2.partimage.img
partimage -z1 -c -d -o -b  /dev/sda4 sda4.partimage.img
dd bs=512 count=1 if=/dev/sda of=bsback.img
sfdisk -d /dev/sda >partitions_sfdisk.txt
fdisk -l >partitions_fdisk.txt

Linux 分割槽的恢復(還重新建立交換分割槽 sda3)

dd bs=512 count=1 if=bsback.img of=/dev/sda
sfdisk  /dev/sda < partitions_sfdisk.txt
partimage -b restore  /dev/sda1 sda1.partimg.img.000
partimage -b restore  /dev/sda2 sda2.partimg.img.000  
mkswap /dev/sda3
partimage -b restore  /dev/sda4 sda4.partimg.img.000

注意:FAT32 和其他分割槽型別也可以使用 partimage 非常高效地備份。NTFS 是 partimage 還沒有很好地支援的一種分割槽型別(AFAIK),因此上面使用 ntfsclone。

  • 只能恢復到相同大小的磁碟,因為使用 dd 和 sfdisk 方法恢復主引導記錄和分割槽。有一些方法可以克服此限制,但我還沒有測試和微調它們。
  • 恢復完整的 Linux 系統時,可能需要調整 grub 配置,以便按數字而不是按名稱指向分割槽,而現在許多較新的 Linux 發行版往往這樣做。

其他想法 - 願望清單

[編輯 | 編輯原始碼]
  • 這些指令碼可以在除 Windows 共享之外的其他目標型別上執行。這就是使用 knoppix 型別引導磁碟的優點。這裡可能有一些關於掛載檔案系統的說明。即時 Linux CD 至少可以掛載以下檔案系統... 以便將備份傳送到
    • 本地分割槽(NTFS、FAT32、EXT2、EXT3 是主要的)
    • USB 驅動器
    • NFS 共享
  • 希望建立一個指令碼生成器,它檢查本地磁碟並互動式地建立一個備份和恢復指令碼以匹配。這將很有趣,而且可能非常有用 :)
  • 建立一些指令碼以備份到本地 CD/DVD 驅動器,並使它們可啟動。
  • 建立一個簡化的、快速啟動的即時 Linux CD,它只包含磁碟映像工具


其他提示

[編輯 | 編輯原始碼]

克隆後重置壞扇區列表

當您將分割槽從帶有壞扇區的磁碟克隆到新磁碟時,Windows 仍然在新磁碟上報告壞扇區。這是因為,根據設計,ntfsclone 複製所有內容,包括壞扇區列表。

雖然這與 ntfsclone 嚴格來說沒有關係,但有些人可能會使用以下過程在克隆後重置壞扇區列表

  1. 備份分割槽中的重要資料,以防萬一
  2. 使用 ntfsinfo 使用 ntfsinfo -i 8 <分割槽> 找出 $Badclus 中 '$Bad' 屬性的大小。它將是“Dumping attribute $DATA (0×80)”中的“Allocated size”值(將有兩個 0×80 屬性。只有一個具有“Allocated size”行)。
  3. 使用 ntfstruncate <分割槽> 8 0x80 '$Bad' 0 將 $Bad 的屬性長度設定為零。
  4. 使用 ntfstruncate <分割槽> 8 0x80 '$Bad' <ntfs_size> 將 $Bad 的屬性長度重新設定為步驟 2 中記錄的正確值。
  5. 啟動進入 Windows 並執行 chkdsk。它將找到錯誤並應予以修復。

除非您確定壞扇區只是錯誤,否則建議在執行此操作後使用硬碟製造商的工具或 chkdsk /r 執行完整的面掃描。本段文字從http://www.linux-ntfs.org/doku.php?id=ntfsclone複製

進一步閱讀

[編輯 | 編輯原始碼]
華夏公益教科書