[12/17] installer: Add code to correctly write the fstab when installing on BTRFS

Message ID 20240315191442.3951-13-stefan.schantl@ipfire.org
State Superseded
Headers
Series BTRFS support on IPFire 2.x (experimental) |

Commit Message

Stefan Schantl March 15, 2024, 7:14 p.m. UTC
  Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 src/installer/hw.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
  

Patch

diff --git a/src/installer/hw.c b/src/installer/hw.c
index b5b853e92..26c473e9c 100644
--- a/src/installer/hw.c
+++ b/src/installer/hw.c
@@ -1260,6 +1260,7 @@  int hw_write_fstab(struct hw_destination* dest) {
 		return -1;
 
 	char* uuid = NULL;
+	char mount_options[STRING_SIZE];
 
 	// boot
 	if (*dest->part_boot) {
@@ -1295,7 +1296,16 @@  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 array of known BTRFS subvolumes
+			for ( int i = 0; i < LEN(btrfs_subvolumes); i++ ) {
+				snprintf(mount_options, sizeof(mount_options), "defaults,%s,subvol=%s", BTRFS_MOUNT_OPTIONS, btrfs_subvolumes[i][0]);
+				fprintf(f, FSTAB_FMT, uuid, btrfs_subvolumes[i][1], "btrfs", mount_options, 1, 1);
+			}
+		} else {
+			fprintf(f, FSTAB_FMT, uuid, "/", "auto", "defaults", 1, 1);
+		}
+
 		free(uuid);
 	}