Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 19 Nov 2022 07:48:44 -0600
From:      Mike Karels <mike@karels.net>
To:        John-Mark Gurney <jmg@funkthat.com>
Cc:        freebsd-arm@freebsd.org
Subject:   Re: adding swap when expanding root filesystem
Message-ID:  <BCF0D91E-29EF-4FEA-BB6D-835F759BC686@karels.net>
In-Reply-To: <20221118224510.GI3414@funkthat.com>
References:  <202211071610.2A7GAcHl090048@mail.karels.net> <20221118010348.GG3414@funkthat.com> <21BE16D1-0E58-4771-B6DD-7B2EAC6665C5@karels.net> <20221118224510.GI3414@funkthat.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On 18 Nov 2022, at 16:45, John-Mark Gurney wrote:

> Mike Karels wrote this message on Fri, Nov 18, 2022 at 09:45 -0600:
>> On 17 Nov 2022, at 19:03, John-Mark Gurney wrote:
>>
>>> Mike Karels wrote this message on Mon, Nov 07, 2022 at 10:10 -0600:
>>>> This question is not really arm-specific, but I couldn't think of a =
better
>>>> mailing list for it.
>>>>
>>>> There are peridic issues reported on small systems like Raspberry Pi=

>>>> where people are running buildworld or poudriere and running out of
>>>> memory.  As the user gets no control over the disk layout when insta=
lling,
>>>> there is no option to add swap space on the install image.  I have a=
dded
>>>> swap space on a USB disk, but this is often not an option.  It occur=
red
>>>> to me that it might be reasonable to add swap space before expanding=

>>>> the root filesystem if there is sufficient space.  I have a prototyp=
e,
>>>
>>> So, if you boot to single user mode, before growfs runs on first boot=
,
>>> you can manually add a swap partition at the end of the disk.
>>>
>>> You'll need to gpart recover the disk first, so that the gpt (iirc)
>>> covers the remaining disk, and then add a swap partition at the end.
>>> This'll take a bit of math, but isn't too hard.
>>
>> Right, that???s what my prototype does (as part of the growfs script).=

>>
>>>> and wondered if this is a good thing to do.  Granted, this will ofte=
n
>>>> create swap on microSD, which is not optimal, but probably better th=
an
>>>> nothing.
>>>
>>> The other option is to use a swap file as outlined in the handbook:
>>> https://docs.freebsd.org/en/books/handbook/config/#create-swapfile
>>>
>>>> The current prototype creates a swap partition which is 1/10 of the =
disk
>>>> if the disk is at least 15 GB and the initial root partition is no m=
ore
>>>> than 1/3 of the disk, but only up to 1.5x of physical memory.  I wou=
ld
>>>> probably enable this by default, but provide a way to disable it via=
 a
>>>> kenv variable and/or a variable in /etc/rc.conf.
>>>
>>> I would like to see the ability to drop a file on the FAT file system=

>>> so that the system can be configured at first boot w/o requiring some=
one
>>> to either boot to single user mode, or have a FreeBSD system.  This i=
sn't
>>> too hard, as I have a review already open for it:
>>> https://reviews.freebsd.org/D26713
>>>
>>> It makes use of cpercival's cloud init, but slightly modified so it l=
ooks
>>> on the fat file system that most arm images have.
>>>
>>> with this, it wouldn't be too hard to gin up some commands to automat=
ically
>>> add the swap partition on first boot, but until something like this i=
s
>>> done, it has to be done manually.
>>
>> I like the config script idea, but it runs after the root file system =
is
>> mounted read/write, and growfs runs before that.  Meanwhile, I have ad=
ded
>> the ability to suppress swap space, or set its size, via either /etc/r=
c.conf
>> or kernel environment.  I will probably have something ready for revie=
w soon.
>> Meanwhile, if anyone wants to test (especially on GPT), let me know.
>
> It looks like growfs can run on read-write UFS filesystems, or at least=
 that's
> what the man page implies:
>
> CAVEATS
>      When expanding a file system mounted read-write, any writes to tha=
t file
>      system will be temporarily	suspended until	the expansion is finish=
ed.
>
> I haven't tried it though.
>
> https://www.freebsd.org/cgi/man.cgi?query=3Dgrowfs&apropos=3D0&sektion=3D=
0&manpath=3DFreeBSD+13.1-RELEASE+and+Ports&arch=3Ddefault&format=3Dhtml

Although that is true, and I have used it, it seems better to do the grow=
fs
step before root is read/write.  As the comment added to the growfs scrip=
t
says, =E2=80=9CWe need to run early, because there might be not enough fr=
ee space
on rootfs for the boot to succeed=E2=80=9D.  (Comment added when =E2=80=9C=
BEFORE: root=E2=80=9D was
added.)  I don=E2=80=99t see any significant advantage in using the confi=
g script
that would outweigh this, although the fstab entry could be added at the
same time.

I have run into a small snag with adding a dump device.  We don=E2=80=99t=
 currently
have =E2=80=98dumpdev=3D=E2=80=9CAUTO=E2=80=9D=E2=80=99 in rc.conf for th=
e arm images.  We could add it when
building, or I could add it when modifying the fstab (in that case, only
when adding a swap partition).  Also, this step runs well after the dumpo=
n
script.  I suppose I can just do =E2=80=9Cdumpon -a=E2=80=9D again if add=
ing to fstab.

		Mike

> -- =

>   John-Mark Gurney				Voice: +1 415 225 5579
>
>      "All that I will do, has been done, All that I have, has not."



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BCF0D91E-29EF-4FEA-BB6D-835F759BC686>