From patchwork Sat Mar 23 10:56:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 7669 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4V1x3R4Lgsz3wtq for ; Sat, 23 Mar 2024 10:57:07 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4V1x3F5CMwzFMS; Sat, 23 Mar 2024 10:56:57 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4V1x3B6593z32w4; Sat, 23 Mar 2024 10:56:54 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) client-signature ECDSA (secp384r1)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4V1x320kdXz32vH for ; Sat, 23 Mar 2024 10:56:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4V1x3110tFzT1; Sat, 23 Mar 2024 10:56:45 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1711191405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jR6eOiJkv/Uncwr2Tljo2rq4PwdZQHf/FPVmGcGnTcI=; b=Ecnyyv/ACd+kkMb/etXqSYuSwSMxwlxuf0I8JSFjL68QvEhMy8YFKBcqm0CpLGIrkeeqWo 0KMwd2CXm3INVZDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1711191405; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jR6eOiJkv/Uncwr2Tljo2rq4PwdZQHf/FPVmGcGnTcI=; b=hgkAEi8nBdYPay/Zo9+orpSU/7Faaw42Tjit6vGhOvH3IB+NMc2xQAuJMZLcqUuxztdbGY d8GGXxkKj6l3Pd2PXy0ugazuehABDeNLqhShS2YkqMWQ/vB6nQd0gC8zbPqrvtelhGgWHl MXSxa3d79tqsP/qFZBTBU1KLGXn/0+o7F0GzMEE0iyJ73FnpZ4s0tlqi25EXuvKyHqQxBZ /5Msnf1iQrYolf+MFVqc5eUAMJ3XPPMBf0Ym9SYvZRXOfxPVqxrmKcSHrPzoq2xNJ6vhp9 Tb0Chmjn8VDg139DtNmcqj2COB0ZvRUJwjkvqzO9qiolcG1/GRStKQSxJl+8EQ== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCHv2 12/12] installer: Add code to correctly write the fstab when installing on BTRFS Date: Sat, 23 Mar 2024 11:56:29 +0100 Message-Id: <20240323105629.371511-12-stefan.schantl@ipfire.org> In-Reply-To: <20240323105629.371511-1-stefan.schantl@ipfire.org> References: <20240323105629.371511-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Message-ID-Hash: 5KQNDMFSQZXZR4HUBSTR33B5D35RFDTJ X-Message-ID-Hash: 5KQNDMFSQZXZR4HUBSTR33B5D35RFDTJ X-MailFrom: stefan.schantl@ipfire.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: IPFire development talk Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Signed-off-by: Stefan Schantl --- src/installer/hw.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/installer/hw.c b/src/installer/hw.c index 3b26920d1..77789e35e 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -1319,11 +1319,13 @@ static char* hw_get_uuid(const char* dev) { #define FSTAB_FMT "UUID=%s %-8s %-4s %-10s %d %d\n" int hw_write_fstab(struct hw_destination* dest) { + const struct btrfs_subvolumes* subvolume = NULL; FILE* f = fopen(DESTINATION_MOUNT_PATH "/etc/fstab", "w"); if (!f) return -1; char* uuid = NULL; + char mount_options[STRING_SIZE]; // boot if (*dest->part_boot) { @@ -1359,7 +1361,22 @@ int hw_write_fstab(struct hw_destination* dest) { // root uuid = hw_get_uuid(dest->part_root); if (uuid) { - fprintf(f, FSTAB_FMT, uuid, "/", "auto", "defaults", 1, 1); + if(dest->filesystem == HW_FS_BTRFS) { + // Loop through the list of subvolumes + for (subvolume = btrfs_subvolumes; subvolume->name; subvolume++) { + // Abort if the mount options could not be assigned + int r = snprintf(mount_options, sizeof(mount_options), "defaults,%s,subvol=%s", BTRFS_MOUNT_OPTIONS, subvolume->name); + if (r < 0) { + return r; + } + + // Write the entry to the file + fprintf(f, FSTAB_FMT, uuid, subvolume->mount_path, "btrfs", mount_options, 1, 1); + } + } else { + fprintf(f, FSTAB_FMT, uuid, "/", "auto", "defaults", 1, 1); + } + free(uuid); }