* exactly shrinking btrfs on a device?
@ 2024-04-05 22:22 Christoph Anton Mitterer
2024-04-05 22:37 ` Roman Mamedov
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Anton Mitterer @ 2024-04-05 22:22 UTC (permalink / raw
To: linux-btrfs@vger.kernel.org
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-05 22:22 exactly shrinking btrfs on a device? Christoph Anton Mitterer
@ 2024-04-05 22:37 ` Roman Mamedov
2024-04-05 22:41 ` Christoph Anton Mitterer
0 siblings, 1 reply; 7+ messages in thread
From: Roman Mamedov @ 2024-04-05 22:37 UTC (permalink / raw
To: Christoph Anton Mitterer; +Cc: linux-btrfs@vger.kernel.org
On Sat, 06 Apr 2024 00:22:52 +0200
Christoph Anton Mitterer <calestyo@scientia.org> wrote:
> 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.
--
With respect,
Roman
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-05 22:37 ` Roman Mamedov
@ 2024-04-05 22:41 ` Christoph Anton Mitterer
2024-04-06 5:03 ` Andrei Borzenkov
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Anton Mitterer @ 2024-04-05 22:41 UTC (permalink / raw
To: Roman Mamedov; +Cc: linux-btrfs@vger.kernel.org
On Sat, 2024-04-06 at 03:37 +0500, Roman Mamedov wrote:
> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-05 22:41 ` Christoph Anton Mitterer
@ 2024-04-06 5:03 ` Andrei Borzenkov
2024-04-07 2:52 ` Christoph Anton Mitterer
0 siblings, 1 reply; 7+ messages in thread
From: Andrei Borzenkov @ 2024-04-06 5:03 UTC (permalink / raw
To: Christoph Anton Mitterer, Roman Mamedov; +Cc: linux-btrfs@vger.kernel.org
On 06.04.2024 01:41, Christoph Anton Mitterer wrote:
> On Sat, 2024-04-06 at 03:37 +0500, Roman Mamedov wrote:
>> 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.
>
>
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-06 5:03 ` Andrei Borzenkov
@ 2024-04-07 2:52 ` Christoph Anton Mitterer
2024-04-07 14:29 ` Roman Mamedov
0 siblings, 1 reply; 7+ messages in thread
From: Christoph Anton Mitterer @ 2024-04-07 2:52 UTC (permalink / raw
To: Andrei Borzenkov; +Cc: linux-btrfs@vger.kernel.org
On Sat, 2024-04-06 at 08:03 +0300, Andrei Borzenkov wrote:
> 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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-07 2:52 ` Christoph Anton Mitterer
@ 2024-04-07 14:29 ` Roman Mamedov
2024-04-08 2:00 ` Christoph Anton Mitterer
0 siblings, 1 reply; 7+ messages in thread
From: Roman Mamedov @ 2024-04-07 14:29 UTC (permalink / raw
To: Christoph Anton Mitterer; +Cc: Andrei Borzenkov, linux-btrfs@vger.kernel.org
On Sun, 07 Apr 2024 04:52:06 +0200
Christoph Anton Mitterer <calestyo@scientia.org> wrote:
> On Sat, 2024-04-06 at 08:03 +0300, Andrei Borzenkov wrote:
> > 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.
--
With respect,
Roman
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: exactly shrinking btrfs on a device?
2024-04-07 14:29 ` Roman Mamedov
@ 2024-04-08 2:00 ` Christoph Anton Mitterer
0 siblings, 0 replies; 7+ messages in thread
From: Christoph Anton Mitterer @ 2024-04-08 2:00 UTC (permalink / raw
To: Roman Mamedov; +Cc: linux-btrfs@vger.kernel.org
On Sun, 2024-04-07 at 19:29 +0500, Roman Mamedov wrote:
> 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.
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-04-08 2:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-05 22:22 exactly shrinking btrfs on a device? Christoph Anton Mitterer
2024-04-05 22:37 ` Roman Mamedov
2024-04-05 22:41 ` Christoph Anton Mitterer
2024-04-06 5:03 ` Andrei Borzenkov
2024-04-07 2:52 ` Christoph Anton Mitterer
2024-04-07 14:29 ` Roman Mamedov
2024-04-08 2:00 ` Christoph Anton Mitterer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.