Filesystems

撤消 wipefs –all –force /dev/sda?/dev/sda

  • April 11, 2021

作業系統:Debian Bullseye uname -a,:

Linux backup-server 5.10.0-5-amd64 #1 SMP Debian 5.10.24-1 (2021-03-19) x86_64 GNU/Linux

我正在尋找一種**撤消此wipefs**命令的方法:

wipefs --all --force /dev/sda? /dev/sda

而以前的結構是:

fdisk -l /dev/sda

Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: CT240BX200SSD1  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 8D5A08BF-0976-4CDB-AEA2-8A0EAD44575E

Device       Start       End   Sectors   Size Type
/dev/sda1     2048   1050623   1048576   512M EFI System
/dev/sda2  1050624 468860927 467810304 223.1G Linux filesystem

以及該wipefs命令的輸出(仍在我的終端上):

/dev/sda1: 8 bytes were erased at offset 0x00000052 (vfat): 46 41 54 33 32 20 20 20
/dev/sda1: 1 byte was erased at offset 0x00000000 (vfat): eb
/dev/sda1: 2 bytes were erased at offset 0x000001fe (vfat): 55 aa
/dev/sda2: 2 bytes were erased at offset 0x00000438 (ext4): 53 ef
/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0x37e4895e00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa

我可能在https://sysbits.org/上找到了一篇文章,即: https ://sysbits.org/undoing-wipefs/

我將從那裡引用擦除撤消部分,我想知道它是否正確並且我可以在我尚未重新啟動的伺服器上安全地執行它,並且從那時起試圖從這個地獄中找出解決方法一個錯字:

  1. 擦拭部分
wipefs -a /dev/sda

/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0x3b9e655e00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
  1. 撤消部分
echo -en '\x45\x46\x49\x20\x50\x41\x52\x54' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x00000200))
echo -en '\x45\x46\x49\x20\x50\x41\x52\x54' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x3b9e655e00))
echo -en '\x55\xaa' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x000001fe))

partprobe /dev/sda

可能的替代解決方案

剛才我testdisk在那個SSD盤上執行,發現很多分區,但只有這兩個與原來的匹配:

TestDisk 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <grenier@cgsecurity.org>
https://www.cgsecurity.org

Disk /dev/sda - 240 GB / 223 GiB - CHS 29185 255 63

    Partition                  Start        End    Size in sectors

1 P EFI System                  2048    1050623    1048576 [EFI System Partition] [NO NAME]
2 P Linux filesys. data      1050624  468860927  467810304

我可以/我應該點擊Write(將分區結構寫入磁碟)嗎?如果不是,為什麼不呢?

你很幸運,wipefs實際上列印出了它擦拭的部分。

這些,

wipefs -a /dev/sda
/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0x3b9e655e00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa

echo -en '\x45\x46\x49\x20\x50\x41\x52\x54' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x00000200))
echo -en '\x45\x46\x49\x20\x50\x41\x52\x54' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x3b9e655e00))
echo -en '\x55\xaa' | dd of=/dev/sda bs=1 conv=notrunc seek=$((0x000001fe))

總的來說,對我來說看起來很明智。

**但請注意,那裡的偏移量與您的情況不同!**您需要使用從wipefs.

根據偏移值(0x3b9e655e00 對 0x37e4895e00),它們的磁碟比您的磁碟稍大(~256 GB 對~240 GB)。使用它們的值意味著磁碟末尾的備份 GPT 將被損壞。這並不重要,因為只要第一個副本完好無損,任何分區工具都應該能夠重寫它。

但是,如果反過來,並且您使用的錯誤偏移量恰好在您的磁碟大小範圍內,您最終會覆蓋驅動器的某個隨機部分。不好。

此外,文件系統的幻數當然需要放在正確的位置。


我用 VFAT 圖像測試了擦除和撤消它,並在仔細閱讀您的版本之前將其從頭頂上寫下來:

printf "$(printf '\\x%s' 46 41 54 31 36 20 20 20)" |
 dd bs=1 conv=notrunc seek=$(printf "%d" 0x00000036) of=test.vfat

那是針對單個wipefs輸出線的(對其他人重複):

test.vfat: 8 bytes were erased at offset 0x00000036 (vfat): 46 41 54 31 36 20 20 20

開頭的嵌套 printf 允許從 複製粘貼輸出wipefs,而無需手動更改46 41 54 31...\x46\x41\x54\x31....

同樣,您確實需要注意在正確的偏移量中輸入正確的值!

進一步自動化可能不會太糟糕,但是涉及風險,我不太熱衷於在沒有經過大量測試的情況下公開發布這樣的腳本。

如果可以的話,在弄亂它之前複製磁碟內容。

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