Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting between 512 and 4096 byte sectors? [question] [solved] #36

Open
gardar opened this issue Apr 14, 2021 · 2 comments
Open

Converting between 512 and 4096 byte sectors? [question] [solved] #36

gardar opened this issue Apr 14, 2021 · 2 comments
Assignees
Labels

Comments

@gardar
Copy link

gardar commented Apr 14, 2021

Could this tool be used to convert a filesystem from 512 byte sectors to 4k?

For example:
If one replaces or adds a 4K formatted disk to lvm or md raid it will transform the lvm volume/md raid to a 4K devices which some filesystems (xfs at least) struggle with.
XFS for example will give the error xfs device supports 4096 byte sectors (not 512) and refuse to mount again until you remove the 4K device (which tranforms the device back to a 512 byte one).

@cosmos72
Copy link
Owner

cosmos72 commented Apr 15, 2021

Yes, you can use fstransform to create a new filesystem with different options and move the content of existing filesystem into it, in place.

For example, if a certain filesystem type (say, xfs) supports both 512B blocks and 4kB blocks,
and you have an existing xfs filesystem (for example inside device /dev/sda1) that uses 512B blocks, you can use

umount /dev/sda1
fstransform --opts-mkfs='-b size=4096' /dev/sda1 xfs

to convert it to 4kB blocks, while keeping the filesystem type to xfs.

I did a test with a loop filesystem:

$ ls -l img
-rw-r--r-- 1 root root 1073741824 Apr 15 17:17 img

$ file img
img: SGI XFS filesystem data (blksz 1024, inosz 512, v2 dirs)

$ losetup /dev/loop0 img

$ fstransform --opts-mkfs='-b size=4096' /dev/loop0 xfs
[ lots of output ... ]
17:19:56 fsck: /usr/sbin/fsck.xfs: XFS file system.
17:19:56 fstransform: completed successfully. device '/dev/loop0' now contains 'xfs' file-system

$ xfs_repair /dev/loop0 # because fsck.xfs does nothing...
[ lots of output ... ]
Phase 7 - verify and correct link counts...
done

$ file img
img: SGI XFS filesystem data (blksz 4096, inosz 512, v2 dirs)

As usual, remember that I do not take any responsibility if fstransform damages your filesystem.
Read: you'd better have a backup!

P.S. the operations described above create a new filesystem, and move the existing content into it.
They know nothing about RAID, LVM etc. and in particular they know nothing about xfs support for disks with 4kB sectors.
They just create a filesystem with a blocksize = 4kB, which is hopefully compatible with disks having 4kB sectors.

@gardar
Copy link
Author

gardar commented Apr 16, 2021

That's fantastic!
It's a big issue when replacing disks in a raid/lvm and the new disks you get are 4K, every single post I've seen about that issue has the only resolution to get a new replacement disk or format the array/volume, which is a tough solution in many cases.

This issue can be closed, but it's good that this solution is documented somewhere. Perhaps it would be good to add this to the readme so others that are seeking a solution can stumble across this.

@cosmos72 cosmos72 self-assigned this Apr 16, 2021
@cosmos72 cosmos72 changed the title Converting between 512 and 4096 byte sectors? Converting between 512 and 4096 byte sectors? [question] [solved] Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants