[dm-crypt] Filesystem unreadabe after resizing LUKS

Matthias Schniedermeyer ms at citd.de
Thu Jan 30 17:22:20 CET 2014


On 30.01.2014 16:24, Pawel Chojnacki wrote:
> Hello,
> 
> Two days ago I tried to shrink my LUKS-encrypted /dev/sdb5 partition from
> 119 to 110 GB according to
> http://ubuntuforums.org/showthread.php?t=726724. Each step worked
> properly, but in the end I'm not able to mount the
> partition. I wanted to ask if you have any idea what may have caused that
> and how to fix it:

The actual commands you executed would be useful.

> As far as I understand, the physical volume is 110 GB large, and filesystem
> is 117.9 GB (why?). When trying to read from superblocks:

A filesystem has the information stored about it's size stored inside 
itself, it doesn't needs (or uses) the information about the outer 
container-size for that.

You have a problem when the outer size doesn't correspond with the 
stored filesystem size. Altough actually problematic is only the 
"filesystem is bigger" case, the other case is (potentially) just wasted 
space.

As for shrinking, this is an operation that is NOT guruanteed to be 
successful. There maybe files in the space you want to shrink away and 
AFAIK there aren't any (OSS) tools that relocate files (except the 
XFS-specific xfs_fsr, but more about XFS in the next paragraph). The 
resize2fs-manpage isn't really informative. You would have to check the 
file-layouts of EVERY file. "filefrag" can tell you where the physical 
blocks of a file are located, you would need to calcutate the offset 
that will ouside the shrinked filesystem and move any file that is 
beyond the offset (Just copying such a file away and back MIGHT be 
enough, but that depends a little on luck)
After that you would need to hope that there aren't any "other" things 
in "to be removed" space. Like for e.g. directory-data

For e.g. i can definitly say that you can't shrink an XFS, because there 
simply isn't any tool that can do that. It's technically possible to do 
that, but nobodoy bothered to create the necessary tool which would 
check & relocate files/directores... and then fix up the metadata of the 
filesystem. There are people that ask the question from time to time. 
But "Backup & Restore" is still the only "officially supported" way to 
shrink a XFS filesystem.

The only Linux filesystem (i know) that will definitly be able to 
"shrink" is BTRFS (Keyword: rebalancing), altough i'm unsure if it can 
do that today or at some point in the future.





-- 

Matthias


More information about the dm-crypt mailing list