[Discuss] Recovering a corrupted usb hard drive with XFS
Dale R. Worley
worley at alum.mit.edu
Wed May 15 11:50:43 EDT 2024
> From: John Abreau <abreauj at gmail.com>
> I have an 18TB external hard drive that recently suffered a loss. When I
> first set it up, I formatted it as a single partition with an xfs
> filesystem.
>From the messages, I tend to agree with Gregory Galperin that you
accidentally formatted sdx rather than sdx1, and then repeated using sdx
rather than sdx1 when you mounted it. In particular, you saw this
peculiar situation before *before* running xfs_repair:
> /dev/sdf exists, but /dev/sdf1 does not.
That indicates that at that point, the kernel couldn't see a partition
table. And then fdisk reports that the disk starts with an XFS
signature:
> When I ran fdisk to examine the drive, it gave the following error:
>
> Welcome to fdisk (util-linux 2.39.4).
>> Changes will remain in memory only, until you decide to write them.
>> Be careful before using the write command.
>
>> The device contains 'xfs' signature and it will be removed by a write
>> command. See fdisk(8) man page and --wipe option for more details.
Though that doesn't solve the problem. It seems like you need to verify
the size of the filesystem, shrink it if necessary, then shift it later
on the disk, then insert a GPT before the filesystem. In a perfect
world, GParted could do this but I don't know if it can. I managed to
find these with the query "use gparted to add a partition table to a
disk that doesn't have one site:superuser.com":
https://superuser.com/questions/1633123/how-to-partition-a-drive-that-has-no-partition-table-without-formatting
https://superuser.com/questions/1200128/how-to-create-a-partition-table-on-a-drive-with-a-file-system-occupying-the-whol
https://superuser.com/questions/1650509/add-gpt-to-disk-that-has-bare-ext4-file-system-without-data-loss
In principal, it can be done by: (1) using the right utility to shrink
the filesystem enough to leave space for the GPT, (2) copying the
filesystem "further" into the disk by that amount (which mostly has to
be done *in reverse* to not lose data, so it can't be done directly by
dd), (3) creating the GPT, (4) inserting a partition entry that
describes the existing filesystem.
If you can back up the disk to somewhere, wiping the disk and rebuilding
it is going to be easier and safer.
Dale
More information about the Discuss
mailing list