From nobody Sat Nov 19 13:48:44 2022 X-Original-To: freebsd-arm@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NDw3f4Y7sz4hqqT for ; Sat, 19 Nov 2022 13:48:46 +0000 (UTC) (envelope-from mike@karels.net) Received: from mail.karels.net (mail.karels.net [216.160.39.52]) by mx1.freebsd.org (Postfix) with ESMTP id 4NDw3f0qjHz3QFb for ; Sat, 19 Nov 2022 13:48:46 +0000 (UTC) (envelope-from mike@karels.net) Authentication-Results: mx1.freebsd.org; none Received: from mail.karels.net (localhost [127.0.0.1]) by mail.karels.net (8.16.1/8.16.1) with ESMTP id 2AJDmiuS062793; Sat, 19 Nov 2022 07:48:45 -0600 (CST) (envelope-from mike@karels.net) Received: from [10.0.2.130] ([10.0.1.1]) by mail.karels.net with ESMTPSA id HamEL7zeeGNH9QAA4+wvSQ (envelope-from ); Sat, 19 Nov 2022 07:48:44 -0600 From: Mike Karels To: John-Mark Gurney Cc: freebsd-arm@freebsd.org Subject: Re: adding swap when expanding root filesystem Date: Sat, 19 Nov 2022 07:48:44 -0600 X-Mailer: MailMate (1.14r5921) Message-ID: 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> List-Id: Porting FreeBSD to ARM processors List-Archive: https://lists.freebsd.org/archives/freebsd-arm List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-arm@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 4NDw3f0qjHz3QFb X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:209, ipnet:216.160.36.0/22, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N 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."