From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1eiQGm-0007i8-4x for mharc-grub-devel@gnu.org; Sun, 04 Feb 2018 14:48:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiQGj-0007g6-Ir for grub-devel@gnu.org; Sun, 04 Feb 2018 14:48:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eiQGi-0001BJ-K2 for grub-devel@gnu.org; Sun, 04 Feb 2018 14:48:05 -0500 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]:37598) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eiQGi-0001AN-Do for grub-devel@gnu.org; Sun, 04 Feb 2018 14:48:04 -0500 Received: by mail-pl0-x242.google.com with SMTP id ay8so10337558plb.4 for ; Sun, 04 Feb 2018 11:48:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+riFQ3MFgj1RBV+IVJdvXawvasNNCopIeGTDovP/iCc=; b=GjUVURsy424LkZKDGZSTarUgk80FTA5nyPnPZnnFijGxDTB+l82FMyKRtmtwSUai2d veCIjuncSJwaBMegz85kimJJLIkmKUc0NzERr6PMe+BU1c7I3AThHbVfKTcwbrDr8rHa YVO0A8FJyQwAl2SXh200sOnk0TvQFUCkiX7q07rzA5b1bzaZjRQJ2859mEjdqJtETu55 z9P2PcDyka2+ch2LxjVT64J9NsiVzjGU5Y2l+ltz5FOqqRfSBCtnFI4xc19bLej5xaja HyGxp7hU4iA3CflV8a9mRoUs8xxWRf2k3YKTuUQo5yL5y7AD6UlYLERi5Mn5gNYyy7D3 43Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+riFQ3MFgj1RBV+IVJdvXawvasNNCopIeGTDovP/iCc=; b=j+WoCnp34ZD8dfjHTt+YRGChY2ILZL7+kDDZY7FgA9bUe/7gecm1tn6w4nr43ig5wC GAvwMfBW/XCVEfcBcq7BMght0LlsmfL3gS0QPhRRrAvcgB75bm3ENUnIR/Q0P1FWbg0w 50IRr2H2Tgh2MKE7zTJbP3VYXVRoEvxC5CfXDo6PaC+oAIOPjKBRSITIPKD62V97xexs iPwJDBG/EFThORcVibHq2CLXuKdaWGS4I/G8iJ2FLgYpJJPhFSWzpkCzYPEZz9GTQoFO VGwFqsjZt+fw33I/2IRtVUWXENP635BSZzIpqE+pwLedUEi7RIEOSIAcSpujYSiR9+7y IRyA== X-Gm-Message-State: AKwxytfV6DztcfhPzVA4iIyVblqwD63juWYvqLTUZupKP4JVOakzvce8 IXULgm+mqgJ/aZvjH0YQkqdA1g== X-Google-Smtp-Source: AH8x227CtOzyesraPpa7pYxzuXB9t3ippVeo/m8eN/rjD/psp6tx+xk7qhX2YxwztyRAogrqvDcu1w== X-Received: by 2002:a17:902:33c1:: with SMTP id b59-v6mr32998400plc.111.1517773682925; Sun, 04 Feb 2018 11:48:02 -0800 (PST) Received: from localhost.localdomain ([2601:602:9c01:e86a:2ec2:3a19:cd81:76ab]) by smtp.googlemail.com with ESMTPSA id v20sm13565736pfe.176.2018.02.04.11.48.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2018 11:48:01 -0800 (PST) From: Nicholas Vinson To: grub-devel@gnu.org Subject: [GRUB PARTUUID PATCH V5 2/3] Add PARTUUID detection support to grub-probe Date: Sun, 4 Feb 2018 11:47:36 -0800 Message-Id: <20180204194737.22662-3-nvinson234@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180204194737.22662-1-nvinson234@gmail.com> References: <20180204194737.22662-1-nvinson234@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::242 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Feb 2018 19:48:06 -0000 Add PARTUUID detection support grub-probe for MBR and GPT partition schemes. The Linux kernel supports mounting the root filesystem by Linux device name or by the Partition [GU]UID. GRUB's mkconfig, however, currently only supports specifing the rootfs in the kernel command-line by Linux device name unless an initramfs is also present. When an initramfs is present GRUB's mkconfig will set the kernel's root parameter value to either the Linux device name or to the filesystem [GU]UID. Therefore, the only way to protect a Linux system from failing to boot when its Linux storage device names change is to either manually edit grub.cfg or /etc/default/grub and append root=PARTUUID=xxx to the command-line or create an initramfs that understands how to mount devices by filesystem [G]UID and let grub-mkconfig pass the filesystem [GU]UID to the initramfs. The goal of this patch set is to enable root=PARTUUID=xxx support in grub-mkconfig, so that users don't have to manually edit /etc/default/grub or grub.cfg, or create an initramfs for the sole purpose of having a robust bootloader configuration for Linux. --- util/grub-probe.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/util/grub-probe.c b/util/grub-probe.c index 21cb80fbe..3656e32e8 100644 --- a/util/grub-probe.c +++ b/util/grub-probe.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ enum { PRINT_DRIVE, PRINT_DEVICE, PRINT_PARTMAP, + PRINT_PARTUUID, PRINT_ABSTRACTION, PRINT_CRYPTODISK_UUID, PRINT_HINT_STR, @@ -85,6 +87,7 @@ static const char *targets[] = [PRINT_DRIVE] = "drive", [PRINT_DEVICE] = "device", [PRINT_PARTMAP] = "partmap", + [PRINT_PARTUUID] = "partuuid", [PRINT_ABSTRACTION] = "abstraction", [PRINT_CRYPTODISK_UUID] = "cryptodisk_uuid", [PRINT_HINT_STR] = "hints_string", @@ -181,6 +184,48 @@ probe_partmap (grub_disk_t disk, char delim) } } +static void +probe_partuuid (grub_disk_t disk, char delim) +{ + /* + * Nested partitions not supported for now. + * Non-nested partitions must have disk->partition->parent == NULL + */ + if (disk->partition && disk->partition->parent == NULL) + { + if (strcmp(disk->partition->partmap->name, "msdos") == 0) + { + /* + * The partition GUID for MSDOS is the partition number (starting + * with 1) prepended with the NT disk signature. + */ + grub_uint32_t nt_disk_sig; + grub_partition_t p = disk->partition; + disk->partition = p->parent; + + if (grub_disk_read (disk, 0, GRUB_BOOT_MACHINE_WINDOWS_NT_MAGIC, + sizeof(nt_disk_sig), &nt_disk_sig) == 0) + { + grub_printf ("%08x-%02x", + grub_le_to_cpu32(nt_disk_sig), 1 + p->number); + } + disk->partition = p; + } + else if (strcmp(disk->partition->partmap->name, "gpt") == 0) + { + grub_partition_t p = disk->partition; + struct grub_gpt_partentry gptdata; + + disk->partition = p->parent; + + if (grub_disk_read (disk, p->offset, p->index, + sizeof(gptdata), &gptdata) == 0) + print_gpt_guid(gptdata.guid); + disk->partition = p; + } + } +} + static void probe_cryptodisk_uuid (grub_disk_t disk, char delim) { @@ -635,6 +680,12 @@ probe (const char *path, char **device_names, char delim) /* Check if dev->disk itself is contained in a partmap. */ probe_partmap (dev->disk, delim); + else if (print == PRINT_PARTUUID) + { + probe_partuuid (dev->disk, delim); + putchar (delim); + } + else if (print == PRINT_MSDOS_PARTTYPE) { if (dev->disk->partition -- 2.15.1