操作系统: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/
我将引用擦拭和撤消从那里开始,我想知道它是否正常,我可以在我的服务器上安全地执行它,我还没有重新启动服务器,从那时起,我试图从中找出解决方法地狱拼写错误:
擦拭部分
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)) partprobe /dev/sda
可能的替代解决方案
刚才,我testdisk
在该SSD驱动器上运行了,它发现了很多分区,但只有这两个与原始分区匹配:
TestDisk 7.1, Data Recovery Utility, July 2019
Christophe GRENIER <[email protected]>
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(将分区结构写入磁盘)吗?如果没有,为什么不呢?
答案1
你很幸运,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...
。
同样,您确实需要注意在正确的偏移量中输入正确的值!
进一步自动化可能不会太糟糕,但是考虑到所涉及的风险,我不太愿意在没有进行大量测试的情况下公开发布这样的脚本。
如果可以的话,在乱搞之前先复制一份磁盘内容。
答案2
在我的问题中,标题为撤销wipefs
,我选择使用 重新创建分区testdisk
,您最好避免它,因为它花费了可测量的时间(不仅仅是点击Write),在我这样做之前,我必须仔细检查两个分区 -testdisk
让我阅读他们的结构,我继续阅读了一些目录 - 看起来还不错。
我没有想到的是底层文件系统,因为它当然现在没有启动。
我从实时 Linux Mint 上拍了一张 GParted 的照片:
我将重复一遍命令的完整输出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
为了撤消已删除的内容,我做了:
首先,我的 Ext4 分区:
echo -en '\x53\xef' | dd of=/dev/sda2 bs=1 conv=notrunc seek=$((0x00000438))
partprobe /dev/sda2
现在,可以安装并可以读取所有文件。
二、我的EFI分区:
echo -en '\x46\x41\x54\x33\x32\x20\x20\x20' | dd of=/dev/sda1 bs=1 conv=notrunc seek=$((0x00000052))
echo -en '\xeb' | dd of=/dev/sda1 bs=1 conv=notrunc seek=$((0x00000000))
echo -en '\x55\xaa' | dd of=/dev/sda1 bs=1 conv=notrunc seek=$((0x000001fe))
partprobe /dev/sda1
我重新启动,并通过 SSH 连接到我的服务器,现在没有任何问题了。