From patchwork Sat Mar 23 10:56:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 7667 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 4V1x3Q3rNWz3wtq for ; Sat, 23 Mar 2024 10:57:06 +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 4V1x3F1CnfzFMF; 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 4V1x3B1zv3z32vr; 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 4V1x302d2Gz32vH for ; Sat, 23 Mar 2024 10:56:44 +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 4V1x300L5Vz4Rt; Sat, 23 Mar 2024 10:56:43 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1711191404; 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=Ir0APRKSp65ziwxEt1nN4BMrv+OX3uWfPgCnlVXX0kc=; b=vYYZ/a28KL7GVD+AdeRPW6upY2iGDTysCoBocAOn8VINUfJ2PxFuxcOpPCQyltkba3L9HL 38Lw2cI0bbXfxAAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1711191404; 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=Ir0APRKSp65ziwxEt1nN4BMrv+OX3uWfPgCnlVXX0kc=; b=DuSFq67jp851zFjs9KVD7X8qURqaFdGo2AtYRRFYhsi72AZujgKSD/HqG1IfCGst4GPTta wpmugbArxR8KjzHaz293osCQRQtAxUbR2fL9zA9xBqD9aIBCCibRG+6QThd+Zu4MreafGD 7ABZAuOeuUkUhtGf5oXFxAhrSxAXTqXXb84XU0CVey7WB3jjS8G16MTIf3Z3zMSxKSQJEj VSfYZc6V5d0+G/PuBJp1SiBTe4HEyFFTdMxLQhB0Uq8seB6I4r7ZG9F3mod7PoxFB3dGK5 2J/vjJviGvRvRptbrYI8p6eMt39viV2qvpbiYxSXaheHBg0sW1bTgCbXx4BXOw== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCHv2 09/12] installer: Mount BTRFS layout before installing the system Date: Sat, 23 Mar 2024 11:56:26 +0100 Message-Id: <20240323105629.371511-9-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: GYKIGUOTCZR2RNYQKKM55EKSL4WSHX7E X-Message-ID-Hash: GYKIGUOTCZR2RNYQKKM55EKSL4WSHX7E 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 | 57 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/src/installer/hw.c b/src/installer/hw.c index ba6064cf5..8ee6c5726 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -935,6 +935,7 @@ int hw_create_btrfs_layout(const char* path, const char* output) { int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) { char target[STRING_SIZE]; + int r; assert(*prefix == '/'); @@ -962,9 +963,17 @@ int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) { } // root - int r = hw_mount(dest->part_root, prefix, filesystem, 0); - if (r) - return r; + if (dest->filesystem == HW_FS_BTRFS) { + r = hw_mount_btrfs_subvolumes(dest->part_root); + + if (r) + return r; + } else { + r = hw_mount(dest->part_root, prefix, filesystem, 0); + + if (r) + return r; + } // boot snprintf(target, sizeof(target), "%s%s", prefix, HW_PATH_BOOT); @@ -1028,6 +1037,48 @@ int hw_mount_filesystems(struct hw_destination* dest, const char* prefix) { return 0; } +int hw_mount_btrfs_subvolumes(const char* source) { + const struct btrfs_subvolumes* subvolume = NULL; + char path[STRING_SIZE]; + char options[STRING_SIZE]; + int r; + + // Loop through the list of known subvolumes. + for ( subvolume = btrfs_subvolumes; subvolume->name; subvolume++ ) { + // Assign subvolume path. + r = snprintf(path, sizeof(path), "%s%s", DESTINATION_MOUNT_PATH, subvolume->mount_path); + + if (r < 0) { + return r; + } + + // Assign subvolume name. + r = snprintf(options, sizeof(options), "subvol=%s,", subvolume->name); + if (r < 0) { + return r; + } + + // Create the directory. + r = hw_mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO); + + // Abort if the directory could not be created. + if(r != 0 && errno != EEXIST) + return r; + + // Print log message + fprintf(flog, "Mounting subvolume %s to %s\n", subvolume->name, subvolume->mount_path); + + // Try to mount the subvolume. + r = mount(source, path, "btrfs", NULL, options); + + if (r) { + return r; + } + } + + return 0; +} + int hw_umount_filesystems(struct hw_destination* dest, const char* prefix) { int r; char target[STRING_SIZE];