xfs

How to change block size on XFS


Situation: Server uses XFS filesystem, block size 4kB. There are a lot of small files.

Result: Some directories take 2+GB space, but actual file size is less then 200MB.

Solution: Change XFS block size to least possible, 512B. I am aware it means more overhead and some performance loss, I haven't been able to find out how much.

Question: How to do it?

I am aware XFS uses xfsdump to backup data. So lets presume /dev/sda2 is actual XFS filesystem I want to change and /mnt/export is where I want to dump it using xfsdump. Manual says that dumped blocksize has to be same as restored blocksize and -b parameter "Specifies the blocksize, in bytes, to be used for the dump." . I am bit worried because manual also says "The default block size is 1Mb"

Is this then correct way to dump my complete filesystem (in this case, /dev/sda2 is mounted to /home)?

xfsdump -b 512 -f /mnt/export /home

If the above command is correct, what I need to do to correctly get my files back, only with 512B blocksize? My guess is reformat /dev/sda2 to 512B blocksize using

mkfs.xfs /dev/sda2 -b 512

and then use

xfsrestore -f /mnt/export /home

but I am not sure how and there isn't a good way to test and see if I am right.


Solution

  • So I did more research and came up with this:

    xfsdump -f /mnt/export_file /home
    umount /home
    mkfs.xfs -b size=1024 /dev/sda2 -f
    #Minimum block size for CRC enabled filesystems is 1024 bytes.
    mount /home
    xfsrestore -f /mnt/export_file /home
    

    As you can see, I was unable to change blocksize to 512B, because of minimum requirement for CRC enabled filesystems, but otherwise, complete success. I didn't concider I have to unmount the filesystem first. You won't be able to do that if you are logging in as someone who has homedir in /home, so log in as root.