Received: from list by lists.gnu.org with archive (Exim 4.71) id 1bYuaq-0001Ot-4U for mharc-grub-devel@gnu.org; Sun, 14 Aug 2016 08:32:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYuam-0001M5-QV for grub-devel@gnu.org; Sun, 14 Aug 2016 08:32:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bYuai-0002Ub-He for grub-devel@gnu.org; Sun, 14 Aug 2016 08:32:39 -0400 Received: from mail-bl2nam02on0104.outbound.protection.outlook.com ([104.47.38.104]:64032 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bYuai-0002UV-7O for grub-devel@gnu.org; Sun, 14 Aug 2016 08:32:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sooners.onmicrosoft.com; s=selector1-ou-edu; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SwmbOeJBUFEYC5B0iG+uTDoP8n9vZQ/RG8PQU5B8ycA=; b=KuqYHXIEL5h12y5m1HVpDSNG2BY8IudrO3Jx9nNLKGKzHj8hnzEr12n4JDsFItDvg/rSIhgrqwAi+XGHKLNW9K9ZLiW/rfANgOJpx3nec5oeKIByG+7iq87foriXwuKmBBSdGxK5SlUiD20zND0z6LQHfBX/k3GIjDP1G5R32Ic= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=skenton@ou.edu; Received: from [192.168.1.18] (68.97.3.132) by MWHPR03MB2702.namprd03.prod.outlook.com (10.168.207.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.549.15; Sun, 14 Aug 2016 12:32:33 +0000 Subject: Re: Grub module to return partuuid of a device such as (hd0, gpt1) at boot time To: Andrei Borzenkov , The development of GNU GRUB References: <57AF593D.4090608@gmail.com> <2dcb99b3-2755-66f3-9140-962454d33bb7@ou.edu> From: Steve Kenton Message-ID: <8a631144-4854-98ff-8536-b73fdf3482db@ou.edu> Date: Sun, 14 Aug 2016 12:32:28 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: quoted-printable X-Originating-IP: [68.97.3.132] X-ClientProxiedBy: CO2PR04CA045.namprd04.prod.outlook.com (10.141.240.173) To MWHPR03MB2702.namprd03.prod.outlook.com (10.168.207.136) X-MS-Office365-Filtering-Correlation-Id: e7cd68e7-473e-45ca-0bc2-08d3c43f110c X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 2:jMxUq3y6Dx1RBP13tWZuy5vgBgmTg3YS/mCFk2ImpI9kOMpMyeYvRirf73JFsEbYNrzlSCZVsACQOr2hAJQZZpGf3g4CsoMEb11CpTJdVxVmIrk6/FtBFxXFfyddlChRxMs4atAeHTfWPl0YULfXhglobGW1JGkjDRKIfHyOeBnvUY9RGM6ySOhLlZ5kOZqP; 3:y3wC8exZSzoDTeMOg47IsAGbtWjyPubLpiOj178YnoTFzefA8Td3buSh5H8amwy3t8Joz5i7Y3ykfelGtO5g6DxijU5ebiZt0ralNHc48U8Xw56KPczHLr8MaQ9nBC4j; 25:klTjSnwJ5SBNO4B+cIgAKfx2mS121E5zqZi8GO950pUvQoaKnKrHiLUNoIF++AcoPuqaBY8rgGN598lsgjE3fqFkDS489kkf7Zt/u5cEApwPIkV8hvGapY9mnCcodZLkOWn2Nk3+0BfaPmqo8W9ecGMxHSeYaZAhWmXrMIgM3yquVyb5N8NVa/6h2IPsmEEqXIy8kkg9JkuAjEDBHTb3rEcupK6K63HDBYdnEWXlDKERP1etrjG2GZjf4RnNny7DbahpcmQBcOKaX0fGdBgq77PrlMXnpCCGMDeZrXOxH6AReaooLv6Y6vp6GZmt+eo5Sm6sRx+yhDefo3enJhJ02zKAbPR+l21o/8E6AduIpJoP8e3Vz5vLplXzVScQuJVldpX26Pm0bioNWs0bcJnOMzoOZZy8MKzcKpakIhZeYN4= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:MWHPR03MB2702; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 31:rxbszsualvbqiAFFEJSAA+CEC14INrwe0KpqngqxYoKKURzKuXnqxcGXhMWEP/yGtZFWQm4akRXushTV1LlQXXiguVIV1k5hm3lOJk/1lvOMbtbxJXugw4G/j7w1DYja8UIWeExgo0Sb3hbHyKWGV68EpzArKmdh8x7vOQdkJOUsxuKmazAY4F9J95btnCwHuxjaNFqQbwrgkzMLAdQMx2FfMNimXlKNfvKlKSGh6Fw=; 20:/hkDCoBvcVJMNzI+i5fgIEmzWvy4Pnx8OG3IPJI+FtFBY3Mqgv8vI7YNCebKD6qOL6eKcMyhxpZuOnZCo/U0VbBr2pLh9cmNBve44Y0gevG4/+jEBGU+ctclKiQuXsYlMsuyD90NmCzsktUG17dcImIUgcMmw2022oHkXN5tXsbVdQOSLIbYZ2u7GRLEBK0evfLMq/h2CIF75dXr43BBTO/JIRPofgJpd9mjUfOuDNfeKve61w1Lz6USoNmfm3/5u04GcMTB+96idHAYl4TdsFm9jvLZVmMJOnrVutDTva8YfjesI/V7/nvfHxnmAuCj5Drrc62HwyJltoSN0MNHrYHIxQHF2RitdrofqobYXK6kZDVrtr7AYkj1kR2Q2VMIZQm7Q/ZRPiGn4bBGJ2a5MEpJ1muybVgN4yWdAK7w2YtDg2IR40XF5QBSPv18XWb4Kqn+Yb7wtvTc5kv8Yp2GfqsnDNeKE7KJaO4/gElzzJjjzttyKmYjBapKUq2IZ0M1 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046); SRVR:MWHPR03MB2702; BCL:0; PCL:0; RULEID:; SRVR:MWHPR03MB2702; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2702; 4:JqGxozYDjHmY5lU5/T+lOX9mXP8WFXWUD+4ueQJR2dfE5w/QqmLIOApZmBdueCKomyxngfYKtspZJ5DGGhD6ti5GlYLEkksJmKhKAVC9PhnuJAQH7PkA5lzAcBwWRnfIa1mDZiqvb3l41A/58GkG/q7UrFL1kIPk3XLSdPhUye5oZIQQDFURtY5P7ZUyJlEz9He75cWkdWqEsIXrTttg3HNX7G4TTLIQOZtAuCQ0LkO8z/i28RMj9h4IMwWvUlFfdqLWYK6AK8/diDAzHfp38Q0StGbHH480yFqNLUfEKcR9+sKohVsBAdiNIpdfSoO27WFugkhtpaIMkmmu6H2qku/6RM0/CgjBuFKfh+Aeru8jvNsXDEvAPRtH6FTmjoR4g4chDbqfIkuUlPAfymLFgw== X-Forefront-PRVS: 00342DD5BC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(6049001)(7916002)(199003)(377454003)(189002)(24454002)(8676002)(86362001)(31686004)(575784001)(81156014)(345774005)(189998001)(101416001)(42186005)(83506001)(75432002)(54356999)(76176999)(31696002)(19580395003)(81166006)(36756003)(105586002)(23676002)(50466002)(90282001)(97736004)(5001770100001)(4001350100001)(50986999)(33646002)(2906002)(117156001)(7736002)(68736007)(107886002)(2950100001)(3846002)(77096005)(6116002)(64126003)(586003)(88552002)(2870700001)(47776003)(93886004)(7846002)(305945005)(106356001)(92566002)(65956001)(65806001)(66066001)(89122001)(65826006)(21314002); DIR:OUT; SFP:1102; SCL:1; SRVR:MWHPR03MB2702; H:[192.168.1.18]; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: ou.edu does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2702; 23:v6//IZlbIXvrW12uIHh7Z8G069IY5llfTvENxildN?=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ZQ9bhMwAJyPwmGeyGYAtsfiF8r0W3WqnrqiGbPjhwLYfxMUloXvHEBHieTsA==; 24:X1PWTLAWKs7r2oHxM1SxtE69JM8JUKbwFD4wvQvU6j0jxSANms5IZf/RIUneMASkdxRnCaPWiqbYQnM1ota8QvsPPT7ASjxheNJ9r32lRjY=; 7:Oa0S8s7rVoE8FsqrIAbKvW003LfS3v7jZgphMkt+P45PJrvuFwR/6j0zxIRXBiBr8+nMJWle2s+lfHtenYVJ86gtGQej7irGHdwtI8lhqY+7yYErObamDdQf1DnG/2tkKKbcs845y5z+IBF8r5sjTfkqKufIwFBiFt6wlr4813axOmanuiZzfRrt6n8OgdP6+M2TyABHMaxmM6mlsqMOQ79FEIl8vMXHdFq4XO0qCZOMfE8Z2hGekt+w5BXJGa4l SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: ou.edu X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Aug 2016 12:32:33.3594 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2702 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.104 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, 14 Aug 2016 12:32:42 -0000 Thank you for the pointers and encouragement. I knew there had to be a=20 better way and I will do as you suggest using probe etc with current=20 source. I was just experimenting with the source that was already=20 available with my current Buildroot setup as a proof of concept. Steve Kenton On 08/14/2016 07:13 AM, Andrei Borzenkov wrote: > 13.08.2016 23:25, Steve Kenton =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >> My thought is to add a new command "partuuid" which takes a > We have "probe" command and if implemented it should be integrated there. > >> drive&partition string and sets an environment variable to the partition >> uuid (grub "partuuid" by default). Since grub always calls the load >> drive "hd0" > That's wrong in general. > >> this can then be passed directly to the kernel as a command >> line for the rootfs in many cases. Or search could be used to find the >> drive and partuuid could be used to make it palatable to the kernel. For >> example: >> >> menuentry "Buildroot" { >> set root=3D(hd0,gpt1) >> partuuid $root partuuid >> linux /boot/bzImage root=3DPARTUUID=3D$partuuid rootfstype=3Dext4 >> console=3Dtty1 quiet splash=3Dsilent >> } >> >> Below is my first pass at a solution. It's really pseudo code since I >> have not even tried to compile it yet. I was just getting familiar with >> the grub environment since I've never tinkered with it before. Lot's of >> cut and paste but I think it's pretty close. >> >> Steve Kenton >> >> >> /* >> GUIDs are usually stored as 128-bit BE values, and are commonly >> displayed as 32 hexadecimal digits >> most commonly written in text as a sequence of hexadecimal digits >> separated into five groups, such as: >> >> 3F2504E0-4F89-41D3-9A0C-0305E82C3301 >> > Usually GUIDs are displayed in lower case > >> This text notation contains the following fields, separated by hyphens: >> Hex digits Description >> 8 Data1 >> 4 Data2 >> 4 Data3 >> 4 Initial two bytes from Data4 >> 12 Remaining six bytes from Data4 >> >> For the first three fields, the most significant digit is on the left. >> The last two fields are treated as eight separate bytes, each having >> their most significant digit on the left, and they follow each other >> from left to right. Note that the digit order of the fourth field may be >> unexpected, since it is treated differently from the other fields in the >> structure. This is sometimes known as "registry format". > Not sure what it has to do with registry. For GPT GUID are pretty well > defined by UEFI spec which in turn is based on RFC 4122. > >> */ >> >> int main(int argc, char **argv) // example usage: partuuid "hd0,gpt1" >> partuuid >> { >> >> char *name, *partnum, *var; >> int number; // the partition # of interest > Please avoid C++ comments. > >> grub_disk_t disk; >> grub_err_t err; >> >> auto int NESTED_FUNC_ATTR find_partuuid(grub_disk_t disk, const >> grub_partition_t p); >> int NESTED_FUNC_ATTR find_partuuid(grub_disk_t disk, const >> grub_partition_t p) > We got rid of nested functions years ago. > >> { >> struct grub_gpt_partentry entry; >> int ret =3D true; // keep looking >> >> if (grub_disk_read(disk, p->offset, p->index, sizeof(entry), >> &entry)) >> ret =3D false; // EOF >> else if (p->number =3D=3D number) // number and var are in scop= e >> from the outer function >> { >> char partuuid[37]; // 32 hex digits, 4 dashes and a NUL >> >> partuuid =3D grub_xasprintf >> ("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X", // need to double > grub internal implementation does not include upper case version. > >> check caps and endian-ness issues >> grub_be_to_cpu32 (*(grub_uint32_t *) &entry.guid[0]), >> grub_be_to_cpu16 (*(grub_uint16_t *) &entry.guid[4]), >> grub_be_to_cpu16 (*(grub_uint16_t *) &entry.guid[6]), >> entry.guid[7], entry.guid[8], // endian-ness does not matte= r >> for single bytes >> entry.guid[9], entry.guid[10], entry.guid[10], >> entry.guid[10], entry.guid[10], entry.guid[10], entry.guid[10]); >> err =3D grub_set_env(var, partuuid); // need to error check >> ret =3D false; // found it, all done >> } >> >> return ret; >> } >> >> // Split disk and partition from the name string and get environmen= t >> variable name - need to error check >> name =3D argv[1]; >> partnum =3D grub_strchr(name, ',') + 1; >> var =3D argv[2]; // should default to "partuuid" if not supplied >> while (*partnum && grub_isalpha(*partnum)) >> partnum++; > You can simply read partition info directly from disk, no need to > iterate at all. grub_disk_open returns all needed information about > partition location. > >> number =3D grub_strtoul(partnum, (char **) &partnum, 0) - 1; // nee= d >> to look at this function >> if (disk =3D grub_disk_open(name)) // ignores partition if present = in > You should return error if open fails, not silently ignore it. Not to > mention, that it won't even compile because of warning that is treated > as error. > >> name string, NULL on failure >> err =3D grub_gpt_partition_map_iterate(disk, find_partuuid); >> > Linux supports synthetic "GUID" on MSDOS labels too. This should support > it as well (even though I am not sure how useful they are). > >> return 0; >> } >> >> >> On 08/13/2016 06:40 PM, Andrei Borzenkov wrote: >>> 13.08.2016 20:30, adrian15 =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >>>> What's your use case? >>>> >>> Well, this has been requested before and this is supported by Linux >>> kernel. So as long as this does not increase core modules size (i.e. is >>> done outside of partition probing core) I think it will be OK. >>> >>>> adrian15 >>>> >>>> El 12/08/16 a las 16:11, Steve Kenton escribi=C3=B3: >>>>> As far as I can tell there is no search module that can be used to ge= t >>>>> the partuuid at boot time given a grub root device such as >>>>> (hd0,gtp1). I >>>>> think is would be a useful addition since the resulting partuuid coul= d >>>>> be passed directly to the kernel as root=3DPARTUUID=3Dxxx and it does= not >>>>> seem like it should be hard to do. Am I missing something obvious? An= d, >>>>> before I jump end the deep end of the pool and try to write it, is >>>>> anyone else working on something similar? >>>>> >>> There was recent patch series that adds support for user-space >>> grub-probe. Would be good if implementation can be shared. I do not wan= t >>> to add any special code to handle partitions UUID to core as this is >>> very special case of really one partition type only, used infrequently >>> and can be entirely handled by usual device iteration. >>> >>>>> Not subscribed, please cc me on reply. >>>>> >>> Not sure why, but whatever reply I chose Thunderbird and Gmail only >>> reply to list. >>>