From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 11B1590523; Mon, 10 Oct 2022 23:32:54 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id 60AFC90232; Mon, 10 Oct 2022 23:32:31 +0000 (UTC) Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by atuin.qyliss.net (Postfix) with ESMTPS id 82B7590077 for ; Mon, 10 Oct 2022 23:32:13 +0000 (UTC) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 6865E5C01AF for ; Mon, 10 Oct 2022 19:32:09 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 10 Oct 2022 19:32:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alyssa.is; h=cc :content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1665444729; x=1665531129; bh=DR prbDrK6+DUbovtZxtyJxjTJoVY+mulNABHaXghULE=; b=q45AfNCnkiLIsWmeDm 7epLK1lQLZ5vpnJLqFWaUo2o++ovUHHFh2Y7JreTsYXAelDmX/LkC4bKXBwWimOf WIjCPlPBN9HYy2YgzH1ED5CTqMlwiywKf0VuwWDorYLHSrp8ZnyG6VF/gZSVaoRr 9PLI6sUUwnoN/vJDCzpnhs4/37yLzfL8DNEgwHIGbACdMbuWuKPX4nuTT604GeLL hmLRPJ1s9gO5KKl20zsbBSHY8bjXdLhF5KQQgEd7nq35D1pBuM8bP6SH4AnUvG98 5pxgk++54t64urRuL7J6XUzxH5wZoTTB5qKtnEvdKYEvBcBA+BJTeLP6tJCVuB/g uwsg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1665444729; x=1665531129; bh=DRprbDrK6+DUb ovtZxtyJxjTJoVY+mulNABHaXghULE=; b=UDkHsAUck99u8TJ3Ywzb5YBpmaOHA z3ovhRoukVoRpEXVynqVa1yWMWWtr05NbAFRQIwOHFtFphO9nUidj1urJ092i1Yv G15ifBFvj6wtLTn3JHipaX3nMfFxcbdo7xELAwRR8loTp+zQRWc4G9kcX2v4ItPn P4hKti+y4eLTAcvB08OifCXziaCSMaiyhTdDMT9MP1J3Xp0DlccEgMsOnoCFaObY A1xN2P1UIQ5+/ulaWZdV7XAbOtAvudc+eajZHYWr8ZEsoRUjEfCqMRroWCZ2+jbL ZK9GnU7AD3C2aqmqQMLVskV9wrSZFhryX465N1P4amtFCwzbcc42RoJ+A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeejhedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgjfhgggfestdekre dtredttdenucfhrhhomheptehlhihsshgrucftohhsshcuoehhihesrghlhihsshgrrdhi sheqnecuggftrfgrthhtvghrnhepgfefudekvdelieelledufeevheeglefggedvudejvd dtffeuueevffehleejkedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomhepqhihlhhishhsseigvddvtddrqhihlhhishhsrdhnvght X-ME-Proxy: Feedback-ID: i12284293:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 10 Oct 2022 19:32:09 -0400 (EDT) Received: by x220.qyliss.net (Postfix, from userid 1000) id A61B1B6F; Mon, 10 Oct 2022 23:32:06 +0000 (UTC) From: Alyssa Ross To: devel@spectrum-os.org Subject: [PATCH 14/22] host/initramfs/extfs.nix: tar2ext4 -> mkfs.ext4 -d Date: Mon, 10 Oct 2022 23:28:54 +0000 Message-Id: <20221010232909.1953738-15-hi@alyssa.is> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20221010232909.1953738-1-hi@alyssa.is> References: <20221010232909.1953738-1-hi@alyssa.is> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: CSHNA6FSQDMX7A3BPR6APRHB3LOAHZWX X-Message-ID-Hash: CSHNA6FSQDMX7A3BPR6APRHB3LOAHZWX X-MailFrom: qyliss@x220.qyliss.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.5 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: tar2ext4 is designed for making read-only, minimally-sized ext4 images. That's great for the Spectrum host system's root filesystem, but it doesn't make sense for the user data partition, because even if we mark it read/write after running tar2ext4, there will be very few inodes available, so it won't be very useful for storing data. To fix this, we use the normal tools for creating an ext4 filesystem. We create a sparse image of an extremely large size to ensure there's enough space available for metadata and things for the partition to grow to fit any disk a user might want to to use Spectrum on, then shrink the image down to its minimum size. Doing it this way assumes that the build environment will always support sparse files. If this turns out not to be the case, we can use mkfs.ext4's -E resize= option to set the maximum expected disk size, and use a smaller size for the initial image size. I haven't done that here to avoid having to pick that smaller number. Now that the filesystem is no longer marked as read-only, we need to fsck it before every mount, or it won't mount any more after the first time. Signed-off-by: Alyssa Ross --- host/initramfs/extfs.nix | 16 +++++++++++----- host/rootfs/etc/s6-rc/ext/up | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/host/initramfs/extfs.nix b/host/initramfs/extfs.nix index 0ee337b..a510c02 100644 --- a/host/initramfs/extfs.nix +++ b/host/initramfs/extfs.nix @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross # SPDX-License-Identifier: MIT -{ config, runCommand, tar2ext4 }: +{ config, runCommand, e2fsprogs, tar2ext4 }: let netvm = import ../../vm/sys/net { @@ -15,9 +15,10 @@ let in runCommand "ext.ext4" { - nativeBuildInputs = [ tar2ext4 ]; + nativeBuildInputs = [ e2fsprogs ]; } '' - mkdir -p svc/data/appvm-{catgirl,lynx,mg} + mkdir -p root/svc/data/appvm-{catgirl,lynx,mg,nix} + cd root tar -C ${netvm} -c data | tar -C svc -x chmod +w svc/data @@ -26,6 +27,11 @@ runCommand "ext.ext4" { tar -C ${appvm-lynx} -c . | tar -C svc/data/appvm-lynx -x tar -C ${appvm-mg} -c . | tar -C svc/data/appvm-mg -x - tar -cf ext.tar svc - tar2ext4 -i ext.tar -o $out + mkfs.ext4 -d . $out 16T + resize2fs -M $out + + # The generated image will have all files owned by the uid and gid + # mkfs.ext4 was run as, so we need to normalize ownership to root. + find -exec echo $'set_inode_field {} uid 0\nset_inode_field {} gid 0' ';' | + debugfs -wf - $out '' diff --git a/host/rootfs/etc/s6-rc/ext/up b/host/rootfs/etc/s6-rc/ext/up index c189471..78b2637 100644 --- a/host/rootfs/etc/s6-rc/ext/up +++ b/host/rootfs/etc/s6-rc/ext/up @@ -2,5 +2,6 @@ # SPDX-FileCopyrightText: 2021-2022 Alyssa Ross if { /etc/mdev/wait ext } +foreground { fsck.ext4 -fp /dev/ext } if { resize2fs /dev/ext } mount /dev/ext /ext -- 2.37.1