Gentoo Archives: gentoo-user

From: walt <w41ter@×××××.com>
To: gentoo-user@l.g.o
Subject: [gentoo-user] [cookbook] Mounting root partition by UUID (no initrd needed)
Date: Tue, 25 Jan 2011 23:44:09
Message-Id: ihnn3j$9p2$1@dough.gmane.org
In Reply to: [gentoo-user] Re: [cookbook] grub2 for idiots like me PART 2 by walt
1 (I'm separating this from the grub2 stuff because it works with any
2 bootloader that allows you pass a boot parameter to your kernel.)
3
4 This turned out to be easier than I thought -- but be aware that your
5 kernel must have "EFI GUID partition table support" compiled in before
6 you start anything else. (See the File Systems/Partition Types menu.)
7
8 BTW, you don't need to have a newer computer with EFI support. An old
9 BIOS machine uses a GPT just fine as long as your kernel knows about it.
10
11 The only other tool you need is sys-apps/gdisk, which will convert your
12 traditional DOS partition table to GPT -- and back again if you want.
13
14 I strongly suggest that you practice on a USB thumb drive before you
15 risk your real partition table!
16
17 There is one small complication with thumb drives that you won't run
18 into with real hard drives: gdisk may complain that the thumb drive's
19 partition table overlaps a partition.
20
21 If you don't want to delete your thumb drive's partition you can use
22 gparted (or parted) to shrink the drive's partition to leave 3 megabytes
23 or so at the end of the drive. Again, you won't need to worry about
24 this if/when you work on a real hard drive.
25
26 # gdisk /dev/sdd (assuming your USB stick is sdd and newer than FAT16)
27
28 After reading the horrifying warnings you can type ? to see a list of
29 gdisk commands. If you know fdisk, most of the commands will be old
30 friends by now.
31
32 You want "recovery and transformation options (experts only)". You'll
33 soon be an expert, so worry not.
34
35 Next: "load MBR and build fresh GPT from it". You can ignore the next
36 horrifying warning because gdisk will give you yet another last chance
37 to quit without saving your disgusting changes.
38
39 When you're finally ready: "write table to disk and exit". Done!
40
41 Now unplug/replug your thumb drive to force the kernel to re-read its
42 shiny new GPT partition table.
43
44 If you see errors, you probably forgot step number one: build and boot
45 a kernel with CONFIG_EFI_PARTITION=y. Otherwise you should be able to
46 use the thumb drive as you always do.
47
48 I suggest that you use gdisk to convert the thumb drive's GPT back to
49 the traditional DOS/MBR partition table, just so you know you can do it
50 if you really need to. And then convert it back again to GPT so you can
51 try the next part of our experiment.
52
53 Now, the point of this whole exercise (IIRC) is to allow your kernel to
54 mount your root partition without knowing its name (/dev/sdxx).
55
56 You can now try it without risking your hard drive, thanks to the new
57 GPT on your thumb drive. (This will work only for kernels >=2.6.37!!!)
58
59 The secret is to use your bootloader (e.g.grub) to pass a kernel boot
60 parameter like this: root=PARTUUID=<your partition UUID>.
61
62 Ah, but exactly what *is* your partition UUID? This is important!
63
64 The only way I've discovered to find the correct UUID (out of the many
65 possible choices) is to use gdisk, which created the UUID in the first
66 place.
67
68 Note: the UUID you need is *not* the one you see in /dev/disk/by-uuid.
69 This is indeed very stupid, and I'm hoping that someone will fix it.
70
71 # gdisk /dev/sdd (again assuming that your thumb drive is sdd)
72
73 Use the "i" command to display detailed info about the partition where
74 you plan to save a copy of your kernel. For example:
75
76 Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Linux/Windows data)
77 Partition unique GUID: 6BAD4248-FC6D-4487-A255-A3B57504BE10
78 First sector: 16065 (at 7.8 MiB)
79 Last sector: 131106464 (at 62.5 GiB)
80 Partition size: 131090400 sectors (62.5 GiB)
81 Attribute flags: 0000000000000000
82 Partition name: Linux/Windows data
83
84 The one you need is the "unique GUID": 6BAD4248-FC6D-4487-A255-A3B57504BE10
85
86 (I wish I could tell you what the "GUID code" is for, but I have NFI.)
87
88 So, in this specific example, the kernel boot parameter I would use is:
89
90 root=PARTUUID=6BAD4248-FC6D-4487-A255-A3B57504BE10
91
92 Note that the "PARTUUID" keyword was introduced very recently in linux kernel
93 2.6.37, and it has nothing whatever to do with the "UUID" keyword used in the
94 many online tutorials on how to build an initrd!
95
96 The whole point of this exercise is to show you how to avoid the need for an
97 initrd in the first place.
98
99 I've run out of steam for today. Questions/corrections are welcome :)