exactly shrinking btrfs on a device?
Hey.
Assuming one has a btrfs (e.g. even on multiple devices)... one can shrink the total fs via:
btrfs filesystem resize
(or even it's usage on a specific device via
btrfs filesystem resize devid:… )
If that btrfs on some given device was placed within some other container (e.g. a partition, LUKS, LVM, etc.) one likely wants to next shrink that outer container.
How does one do that? I mean, how do I find out the exact last by that btrfs uses on a particular device?
Is it what btrfs inspect-internal dump-super /dev/<particular device> gives me as:
dev_item.total_bytes ...
?
Is that always a multiple of 512?
And I'd assume that's the length, so the address of the last used byte would be dev_item.total_bytes - 1 ?
Respectively if I have that fs in a partition like:
Number Start (sector) End (sector) Size Code Name 2 2097152 976773119 464.8 GiB 8300 Linux filesystem
That would mean, the last used / end sector is :
2097152 + ceil(dev_item.total_bytes/512) - 1
Does that sound right?
Cheers,
Chris.
Quoted 6 lines · On Sat, 06 Apr 2024 00:22:52 +0200 Christoph Anton Mitterer…
If that btrfs on some given device was placed within some other container (e.g. a partition, LUKS, LVM, etc.) one likely wants to next shrink that outer container.
How does one do that? I mean, how do I find out the exact last by that btrfs uses on a particular device?
I do it like this:
Shrink it with a large headroom left to spare, e.g. by 50-100 GB more than necessary (or say by 10%, if it is small). Then shrink the outer container. Then grow the FS using the "max" keyword, to occupy the entire new size of the container.
Signature · 2 lines
With respect, Roman
Quoted 7 lines · Roman Mamedov
Shrink it with a large headroom left to spare, e.g. by 50-100 GB more than
necessary (or say by 10%, if it is small). Then shrink the outer container.
Then grow the FS using the "max" keyword, to occupy the entire new size of the
container.
Yeah... sure that works... but it's not so suited if one wants to set some exact size.
Quoted 9 lines · Christoph Anton Mitterer
Quoted 7 lines · Roman Mamedov
Shrink it with a large headroom left to spare, e.g. by 50-100 GB more than
necessary (or say by 10%, if it is small). Then shrink the outer container.
Then grow the FS using the "max" keyword, to occupy the entire new size of the
container.
Quoted 4 lines
Yeah... sure that works... but it's not so suited if one wants to set some exact size.
Why not? You set the container to the exact size and let btrfs grow up to it. Or may be you need to clarify your question.
Quoted 3 lines · Andrei Borzenkov
Why not? You set the container to the exact size and let btrfs grow up
to it. Or may be you need to clarify your question.
Well... maybe, I guess, I just wanna know where it exactly ends. ^^
Cheers,
Chris
Quoted 6 lines · On Sun, 07 Apr 2024 04:52:06 +0200 Christoph Anton Mitterer…
Quoted 3 lines · Andrei Borzenkov
Why not? You set the container to the exact size and let btrfs grow up
to it. Or may be you need to clarify your question.Well... maybe, I guess, I just wanna know where it exactly ends. ^^
Try "btrfs fi show /mnt/point/ --raw". It will show the device size in bytes, as used by Btrfs.
...
devid 1 size 503251058688 used 400023945216 path /dev/sda3
...
# blockdev --getsize64 /dev/sda3 503251060736
This seems to be the number you're looking for.
In my case we can see that since the total device size is not a multiple of 4096, Btrfs has left 2048 bytes unused at the end.
Signature · 2 lines
With respect, Roman
Quoted 5 lines · Roman Mamedov
Try "btrfs fi show
/mnt/point/--raw". It will show the device size in
bytes, as used by Btrfs....
Quoted 8 lines
devid 1 size 503251058688 used 400023945216 path
/dev/sda3
...# blockdev --getsize64 /dev/sda3 503251060736This seems to be the number you're looking for.
Thanks for the hint. I think it's the same as what I already had seen from dump-super.
I've submitted https://github.com/kdave/btrfs-progs/pull/775 cause I think that should go into the documentation.
Thanks,
Chris.