Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ci93s-0005tJ-3a for mharc-grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48487) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ci93p-0005rc-E3 for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ci93o-0007s3-2P for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:05 -0500 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]:36784) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ci93n-0007rj-Op for grub-devel@gnu.org; Sun, 26 Feb 2017 19:21:03 -0500 Received: by mail-pg0-x244.google.com with SMTP id 25so2118953pgy.3 for ; Sun, 26 Feb 2017 16:21:03 -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=AKtBOXxQMbdZb4d50fAP7Tz33ZYRW0aLmeNwpBPkR54=; b=l/EiIoicn8TBtNxoSzAUkjyR8qbUhi2AH+CEtA+2q0SCoW84uO16z0CY2X+my27Vir RSkUBG7Os4Ye8GoQS0jQH/BD37Sf+jpGhIIv0TUHbojnJEMKaEi7dYUsJRWjeMrmg/EQ vVMOU32m9DR+JWOILh03bMrQevEwapwV3Ajk4qsp29SlWaJqMesuQihzYrVW06B1Gp/x zCdijrPFX+dHuVjtCJSQcCKn5+37Ou1TaYOoK2Nnt9GZ/Xge/IhJkdLwBp4fYUKZ48jb RTJ/xNAIqEZiwc/BKBvMTNjg7aCJwyzEPSE84czjf7DmZzMEI+Ek9tDi0D8BDz+/LqFg Q29Q== 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=AKtBOXxQMbdZb4d50fAP7Tz33ZYRW0aLmeNwpBPkR54=; b=F8mX5IzBcG4rTr9tp4TgktwW4zOXtt5nEwaN4zl3jJkkMEswu9XHKXtrbFCKRn+S5H p/gDOF0kdr4hkUW8MWOelTXzr3zOM8Zz7r6Gq4UuNVxsdrnG8WNjIl/SBFEFDY3U0dJi e1ZrlNl7NeQq1xvU5roM49WJPS6JkopzOzI6DayHBVKDk7f5m+awO5+3xW7jhuR13Bca 0G5OE2ImWW768OmoT85dgUNQ2z1FVh0y02aosSzSVau9wFl07jDT+rL+2Il8cahB1Fgo xeZWoV1bDdlHwHrc/d53JhUbgzd5k6u6fie2SBjxo0cLGIM8KUdNJrgwHsugP3PqgomM Q5Cw== X-Gm-Message-State: AMke39kq3M+zv3QpmlcgqK/FgUnS7uYZCeOFemmcmD3BEreA0nHtjkiM9v+00rCobekb2Q== X-Received: by 10.84.232.1 with SMTP id h1mr20145491plk.95.1488154862859; Sun, 26 Feb 2017 16:21:02 -0800 (PST) Received: from localhost.localdomain ([2601:602:9c01:e86a:1fb0:47b:8245:c067]) by smtp.googlemail.com with ESMTPSA id u82sm26523453pfd.7.2017.02.26.16.21.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Feb 2017 16:21:01 -0800 (PST) From: Nicholas Vinson To: skenton@ou.edu, grub-devel@gnu.org Subject: [GRUB PARTUUID PATCH V3 2/5] Add PARTUUID detection support to grub-probe Date: Sun, 26 Feb 2017 16:20:52 -0800 Message-Id: <20170227002055.5829-3-nvinson234@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170227002055.5829-1-nvinson234@gmail.com> References: <20170227002055.5829-1-nvinson234@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::244 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: Mon, 27 Feb 2017 00:21: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 | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/util/grub-probe.c b/util/grub-probe.c index 8ac527d2f..81f550e0d 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", @@ -168,6 +171,57 @@ 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) + { + grub_printf ("%02x%02x%02x%02x-%02x%02x-%02x%02x" + "-%02x%02x-%02x%02x%02x%02x%02x%02x", + gptdata.guid[3], gptdata.guid[2], gptdata.guid[1], + gptdata.guid[0], gptdata.guid[5], gptdata.guid[4], + gptdata.guid[7], gptdata.guid[6], gptdata.guid[8], + gptdata.guid[9], gptdata.guid[10], gptdata.guid[11], + gptdata.guid[12], gptdata.guid[13], gptdata.guid[14], + gptdata.guid[15]); + } + disk->partition = p; + } + } +} + +static void probe_cryptodisk_uuid (grub_disk_t disk, char delim) { grub_disk_memberlist_t list = NULL, tmp; @@ -621,6 +675,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.12.0