LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   xfs - Can't have a partition outside the disk (https://www.linuxquestions.org/questions/linux-hardware-18/xfs-cant-have-a-partition-outside-the-disk-4175702802/)

virilo 10-29-2021 02:14 PM

xfs - Can't have a partition outside the disk
 
My hard drive crashed and a restoration company was able to copy everything to another new drive.

I think they used dd or similar.

It had two xfs partitions. But, now I can only mount the first one.

If I try to view the partitions with gparted it says:

Quote:

Can't have a partition outside the disk
It seems that the new disk was a little smaller than the original (different models):

Quote:

fdisk -l -u=sectors

Disk /dev/sdd: 9,1 TiB, 10000797794304 bytes, 19532808192 sectors
Disk model: Elements 25A3
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

Device Start End Sectors Size Type
/dev/sdd1 2048 9766436863 9766434816 4,6T Linux filesystem
/dev/sdd2 9766436864 19532871679 9766434816 4,6T Linux filesystem
But the numbers doesn't match!:

Quote:

19532808192-9766434816-9766434816-2048 = -63488
How can I update the partition table and xfs file system to fit the current hard drive?

shruggy 10-29-2021 02:43 PM

There are several possibilities.

You can attempt automatic repair with TestDisk.

Or do it manually with fdisk.

Other options include GParted and Boot-Repair.

jefro 10-29-2021 02:56 PM

There is also a partition repair that hasn't been updated in a long time but may still work.
Ranish.

I'd make a dd copy of the drive before I started any repair.

rknichols 10-29-2021 06:29 PM

Quote:

Originally Posted by virilo (Post 6296853)
Code:

fdisk -l -u=sectors

Disk /dev/sdd: 9,1 TiB, 10000797794304 bytes, 19532808192 sectors
Disk model: Elements 25A3
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

Device Start End Sectors Size Type
/dev/sdd1 2048 9766436863 9766434816 4,6T Linux filesystem
/dev/sdd2 9766436864 19532871679 9766434816 4,6T Linux filesystem


Simpler arithmetic, same result: (19532871679+1) - 19532808192 = 63488

It's fairly straightforward to make an empty file of size 63488*512 and use dmsetup to create a virtual drive appending that file to the end of /dev/sdd2. That virtual drive could then be checked, mounted, and even shrunk to fit in the available space on the physical disk. The problem here with that is that xfs probably won't let you mount the drive without first running xfsrepair, that repair operation has the potential to cause unrecoverable data loss, and an xfs filesystem cannot be shrunk in place.

Should you want to try it anyway:
Code:

truncate --size=$((63488*512)) /var/tmp/padfile
losetup -vf /var/tmp/padfile
echo -e "0 9766434816 /dev/sdd2 0 \n 9766434816 63488 /dev/loop0 0" | dmsetup create padded

If the device returned by losetup is other than "/dev/loop0", use that instead in the echo command. You can now use "/dev/mapper/padded" as the device name in mount, xfsrepair, etc. commands.

To unwind:
Code:

dmsetup remove padded
losetup -d /dev/loop0
rm /var/tmp/padfile

But, you really shouldn't be attempting that repair on your only copy of the data. If you're going to need a new drive with sufficient capacity to hold that data, you might as well just get a drive at least as large as the original and just "dd" this slightly-too-small drive to it. Way simpler, a lot safer.


All times are GMT -5. The time now is 12:26 AM.