Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"I have not the slightest confidence in 'spiritual manifestations.'" -- Robert G. Ingersoll


computers / comp.os.linux.misc / Re: Resize a BTRFS image file and underlying partition

SubjectAuthor
* Resize a BTRFS image file and underlying partitionSugarBug
+- Re: Resize a BTRFS image file and underlying partitionAndreas Kempe
`- Re: Resize a BTRFS image file and underlying partitionRich

1
Resize a BTRFS image file and underlying partition

<20231229170943.7aa9b81a@dev>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14195&group=comp.os.linux.misc#14195

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!.POSTED!not-for-mail
From: 3883@sugar.bug (SugarBug)
Newsgroups: comp.os.linux.misc
Subject: Resize a BTRFS image file and underlying partition
Date: Fri, 29 Dec 2023 17:13:44 -0600
Organization: sybershock.com Baggy Jeans Mafia
Message-ID: <20231229170943.7aa9b81a@dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: i2pn2.org;
logging-data="1597681"; mail-complaints-to="usenet@i2pn2.org";
posting-account="yZybWhCr+jI4C3MuGpPde+DhCwsjQrVZrsCOigcx7fM";
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: SugarBug - Fri, 29 Dec 2023 23:13 UTC

I am trying to riddle out how to resize a BTRFS partition _and_ the
underlying image file.

I created a image file:

$ truncate -s4G btrfs.img

I mounted and formatted the image as BTRFS volume:

$ ld=$(losetup --show --find btrfs.img); echo "$ld"

$ mkfs -t btrfs "$ld"

$ mkdir /mnt/btrfs_img

$ mount "$ld" /mnt/btrfs_img

I can resize the partition inside the image.

$ btrfs filesystem resize 2G /mnt/btrfs_img
$ btrfs filesystem resize 3G /mnt/btrfs_img

How do I resize the partition and the image file (btrfs.img)? I know I
can hack it with 'truncate' on the image file to shrink it but that does
not allow to grow the image file or grow the partition while
necessarily increasing the image file size. If I want to shrink the
partition to 2G, or grow it to 6G, how do I get the image file to
accurately shrink and grow with the partition?

--
3883@sugar.bug | sybershock.com | sci.crypt

Re: Resize a BTRFS image file and underlying partition

<umnrrb$18cj$1@nyheter.lysator.liu.se>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14196&group=comp.os.linux.misc#14196

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nyheter.lysator.liu.se!.POSTED!not-for-mail
From: kempe@lysator.liu.se (Andreas Kempe)
Newsgroups: comp.os.linux.misc
Subject: Re: Resize a BTRFS image file and underlying partition
Date: Sat, 30 Dec 2023 01:30:19 -0000 (UTC)
Organization: Lysator ACS
Message-ID: <umnrrb$18cj$1@nyheter.lysator.liu.se>
References: <20231229170943.7aa9b81a@dev>
Injection-Date: Sat, 30 Dec 2023 01:30:19 -0000 (UTC)
Injection-Info: nyheter.lysator.liu.se; posting-account="kempe";
logging-data="41363"; mail-complaints-to="newsmaster@lysator.liu.se"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Andreas Kempe - Sat, 30 Dec 2023 01:30 UTC

Den 2023-12-29 skrev SugarBug <3883@sugar.bug>:
> I am trying to riddle out how to resize a BTRFS partition _and_ the
> underlying image file.
>
> I created a image file:
>
> $ truncate -s4G btrfs.img
>
> I mounted and formatted the image as BTRFS volume:
>
> $ ld=$(losetup --show --find btrfs.img); echo "$ld"
>
> $ mkfs -t btrfs "$ld"
>
> $ mkdir /mnt/btrfs_img
>
> $ mount "$ld" /mnt/btrfs_img
>
> I can resize the partition inside the image.
>
> $ btrfs filesystem resize 2G /mnt/btrfs_img
> $ btrfs filesystem resize 3G /mnt/btrfs_img
>
> How do I resize the partition and the image file (btrfs.img)? I know I
> can hack it with 'truncate' on the image file to shrink it but that does
> not allow to grow the image file or grow the partition while
> necessarily increasing the image file size. If I want to shrink the
> partition to 2G, or grow it to 6G, how do I get the image file to
> accurately shrink and grow with the partition?
>

You say that truncate won't allow you to grow the image, but I don't
understand why you think that is the case. truncate can both shrink
and extend a file.

Since you have created the BTRFS filesystem directly on the image
without any partition table, if your commands are to be believed,
changing the size should be as simple as doing

truncate -s 6G btrfs.img
ld=$(losetup --show --find btrfs.img); echo "$ld"
mount "$ld" /mnt/btrfs_img
btrfs filesystem resize max /mnt/btrfs_img

NOTE: Backup your image before doing this if you have data you care
about!

The loopback device reports the size of the underlying image to the
file system and it should be able to expand to the max size available.
I've done the same with BTRFS on LUKS devices on images without any
issues.

Re: Resize a BTRFS image file and underlying partition

<umob0s$16gr4$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/computers/article-flat.php?id=14198&group=comp.os.linux.misc#14198

  copy link   Newsgroups: comp.os.linux.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: rich@example.invalid (Rich)
Newsgroups: comp.os.linux.misc
Subject: Re: Resize a BTRFS image file and underlying partition
Date: Sat, 30 Dec 2023 05:49:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <umob0s$16gr4$2@dont-email.me>
References: <20231229170943.7aa9b81a@dev>
Injection-Date: Sat, 30 Dec 2023 05:49:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb4466b9a5eee03458acbf33d0558aaa";
logging-data="1262436"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FiuhNUo/HVImnGyoz9qul"
User-Agent: tin/2.6.1-20211226 ("Convalmore") (Linux/5.15.139 (x86_64))
Cancel-Lock: sha1:PhWJuej9Pwuxo3B0azenvgJYzPw=
 by: Rich - Sat, 30 Dec 2023 05:49 UTC

SugarBug <3883@sugar.bug> wrote:
> How do I resize the partition and the image file (btrfs.img)? I know I
> can hack it with 'truncate' on the image file to shrink it but that does
> not allow to grow the image file or grow the partition while
> necessarily increasing the image file size. If I want to shrink the
> partition to 2G, or grow it to 6G, how do I get the image file to
> accurately shrink and grow with the partition?

Shrinking/growing the image file is fully separate and independent from
telling btrfs to shrink/grow the filesystem that is stored inside the
image file.

According to the truncate man page, truncate will both shrink and grow
files:

Shrink or *extend* the size of each FILE to the specified size

So, if you want to "grow" things, the first step is to make the image
file larger (because the space within the file has to exist first in
order for btrfs to grow the filesystem).

So you'd "truncate" it to the new larger size you want (it is
recommended that you do this only when it is not mounted and not
attached to a loop back device).

Then you would tell btrfs to grow the partition inside the image file.

To shrink things, first you want to tell btrfs to shrink the filesystem
that is inside the image file (presumably this will also cause it to
move any data that is currently stored beyond the new smaller size to
be within the new smaller size -- but double check this, I swore off
btrfs years ago due to its unreliability and have not touched it
since).

Then, once btrfs has been told a new, smaller size, and has "compacted
things" (hopefully it "compacts") then you unmount, remove from the
loop back device, and finally truncate the file to a smaller size
(note, don't truncate smaller than the size you told btrfs to shrink
into, otherwise you may lose data).

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor