* [gentoo-user] [cookbook] grub2 for idiots like me
@ 2011-01-23 22:28 walt
2011-01-24 17:00 ` [gentoo-user] Re: [cookbook] grub2 for idiots like me PART 2 walt
0 siblings, 1 reply; 3+ messages in thread
From: walt @ 2011-01-23 22:28 UTC (permalink / raw
To: gentoo-user
Okay, I genuinely have grub2 installed and doing exactly what it's
supposed to do: boot your machine using only partition LABELS, not
device names/numbers.
Below are a series of steps that *any* gentoo fan should recognize and
be comfortable with.
If you are not familiar with any of these steps, you really *should*
become familiar with them.
If you don't *want* to become familiar with them, have you tried ubuntu?
First, skip grub-1.98 and go for grub-1.99-rc1 because it's much better.
Yes, you could unmask sys-boot/grub-9999, but that's way more trouble
than it's worth. Learn to do it the way it's meant to be done and you
will be pleased with your new skills :)
You need to get the source tarball first. Many different ways to do
that, but my brain-dead way is to use firefox and enter this URL:
ftp://alpha.gnu.org/gnu/grub/
Click on the file grub-1.99~rc1.tar.gz to start downloading it. If you
don't know where firefox is saving the file, shame on you.
You should become familiar with building software in your own home
directory. At work or school you may not have root privileges, so
be brave now and learn how easy it is:
$ cd
$ mkdir src
$ cd src
$ tar -xvzf <wherever>/grub-1.99~rc1.tar.gz <lots of screen output>
$ cd grub-1.99~rc1
Many projects will include the 'configure' file as part of the tarball,
but grub2 does not. Lots of files like configure.ac, config.in, etc,
but you won't find 'configure' this time.
So, you need to create a brand new 'configure' by running the autogen.sh
script that the grub2 devs include for that purpose. (You may need to
emerge sys-devel/autogen if you don't already have it.)
$ ./autogen.sh (tons of screen output>
$ mkdir build
$ cd build
$ ../configure --prefix=$HOME <the default is /usr/local, but you are
not root, so you can't install anything
in /usr/local>
$ make all install <compile and install grub2 in your home dir>
This step, if it works, will install grub stuff in ~/sbin ~/bin ~/etc
~/share and ~/lib/grub. The directories should be created if they
don't already exist, I think.
Up to now your system files have not been touched because you are not
root and therefore you are not able to break your system.
I'm taking a break now to answer any questions about problems you may
encounter, and because I've had enough beer for today already.
All of this should be old material for gentooers. If it's new to you,
then please try the steps above just to learn the basics of building
(any) linux software. Even if you fail you will learn in the process.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gentoo-user] Re: [cookbook] grub2 for idiots like me PART 2
2011-01-23 22:28 [gentoo-user] [cookbook] grub2 for idiots like me walt
@ 2011-01-24 17:00 ` walt
2011-01-25 23:41 ` [gentoo-user] [cookbook] Mounting root partition by UUID (no initrd needed) walt
0 siblings, 1 reply; 3+ messages in thread
From: walt @ 2011-01-24 17:00 UTC (permalink / raw
To: gentoo-user
On 01/23/2011 02:28 PM, walt wrote:
> Okay, I genuinely have grub2 installed and doing exactly what it's
> supposed to do: boot your machine using only partition LABELS, not
> device names/numbers...
If you got through part 1 you should have all the files you need to
install grub2 to your drive's boot block -- that's the part that is
potentially dangerous, so practice installing to a USB thumb drive
*before* you try it for real.
All of my USB thumb drives were formatted FAT16 at the factory, and
grub2 (being a bit of a pig) won't fit in a FAT16 partition table.
The answer is to reformat the drive to FAT32 or ext2, or you can use
a tool like gparted to shrink the FAT16 fs and create a new very tiny
partition for ext2. Even 3MB is big enough to hold grub -- the size
of the file system isn't important -- it's the partition table that's
too small in FAT16.
Assume you have the ext2 partition of the thumb drive mounted on
/mnt/floppy, for example, and the thumb drive is /dev/sdc.
For the actual install you need to be root because you will be
writing to the device as well as the ext2 fs on the device.
# mkdir -p /mnt/floppy/boot/grub
# /home/walt/sbin/grub-install --boot-directory=/mnt/floppy/boot/ /dev/sdc
That second step will write the actual grub2 boot block to the thumb
drive, as well as copying lots of grub modules to /mnt/floppy/boot/grub
from /home/walt/lib/grub/i386-c.
All of those grub 'modules' contain the actually code that does things
like print the boot menu on your screen and accept keystrokes from
your keyboard, search for partition LABELs, UUIDs, display boot splash
screens, play idiotic tunes, load custom fonts and fancy colors, and
tons of other stuff you won't ever want if you're still sane.
That should be enough to let you boot into the grub2 shell from your
thumb drive, assuming you set your BIOS to allow it.
Just like legacy grub, the grub2 command shell will always show you
what you can type next if you hit the tab key -- and there is quite
a long list.
The important commands to learn are 'ls', 'search', 'probe', 'help',
and 'linux'. That 'linux' command is what actually loads your kernel
from the /boot partition after you have located it with the search
and (possibly) the probe commands.
Use the help command and the tab key whenever you don't know what to
do next. You'll pick it up very quickly that way -- far faster than
trying to read any of the incomplete documentation.
One very clueful tool is the brand new utility 'grub-menulst2cfg' which
you should find in your ~/bin directory. Running that on your existing
/boot/grub/menu.lst will show you the equivalent commands for your new
/boot/grub/grub.cfg file. Very neat, and isn't included in the current
stable grub-1.98.
Once you play with the grub2 command shell you will easily see how to
use the same commands in grub.cfg because the syntax is the same.
Next time I'll explain how to use GPT (GUID Partition Table) to let
your kernel find and mount your root partition using its UUID without
an initrd. Very nifty!
^ permalink raw reply [flat|nested] 3+ messages in thread
* [gentoo-user] [cookbook] Mounting root partition by UUID (no initrd needed)
2011-01-24 17:00 ` [gentoo-user] Re: [cookbook] grub2 for idiots like me PART 2 walt
@ 2011-01-25 23:41 ` walt
0 siblings, 0 replies; 3+ messages in thread
From: walt @ 2011-01-25 23:41 UTC (permalink / raw
To: gentoo-user
(I'm separating this from the grub2 stuff because it works with any
bootloader that allows you pass a boot parameter to your kernel.)
This turned out to be easier than I thought -- but be aware that your
kernel must have "EFI GUID partition table support" compiled in before
you start anything else. (See the File Systems/Partition Types menu.)
BTW, you don't need to have a newer computer with EFI support. An old
BIOS machine uses a GPT just fine as long as your kernel knows about it.
The only other tool you need is sys-apps/gdisk, which will convert your
traditional DOS partition table to GPT -- and back again if you want.
I strongly suggest that you practice on a USB thumb drive before you
risk your real partition table!
There is one small complication with thumb drives that you won't run
into with real hard drives: gdisk may complain that the thumb drive's
partition table overlaps a partition.
If you don't want to delete your thumb drive's partition you can use
gparted (or parted) to shrink the drive's partition to leave 3 megabytes
or so at the end of the drive. Again, you won't need to worry about
this if/when you work on a real hard drive.
# gdisk /dev/sdd (assuming your USB stick is sdd and newer than FAT16)
After reading the horrifying warnings you can type ? to see a list of
gdisk commands. If you know fdisk, most of the commands will be old
friends by now.
You want "recovery and transformation options (experts only)". You'll
soon be an expert, so worry not.
Next: "load MBR and build fresh GPT from it". You can ignore the next
horrifying warning because gdisk will give you yet another last chance
to quit without saving your disgusting changes.
When you're finally ready: "write table to disk and exit". Done!
Now unplug/replug your thumb drive to force the kernel to re-read its
shiny new GPT partition table.
If you see errors, you probably forgot step number one: build and boot
a kernel with CONFIG_EFI_PARTITION=y. Otherwise you should be able to
use the thumb drive as you always do.
I suggest that you use gdisk to convert the thumb drive's GPT back to
the traditional DOS/MBR partition table, just so you know you can do it
if you really need to. And then convert it back again to GPT so you can
try the next part of our experiment.
Now, the point of this whole exercise (IIRC) is to allow your kernel to
mount your root partition without knowing its name (/dev/sdxx).
You can now try it without risking your hard drive, thanks to the new
GPT on your thumb drive. (This will work only for kernels >=2.6.37!!!)
The secret is to use your bootloader (e.g.grub) to pass a kernel boot
parameter like this: root=PARTUUID=<your partition UUID>.
Ah, but exactly what *is* your partition UUID? This is important!
The only way I've discovered to find the correct UUID (out of the many
possible choices) is to use gdisk, which created the UUID in the first
place.
Note: the UUID you need is *not* the one you see in /dev/disk/by-uuid.
This is indeed very stupid, and I'm hoping that someone will fix it.
# gdisk /dev/sdd (again assuming that your thumb drive is sdd)
Use the "i" command to display detailed info about the partition where
you plan to save a copy of your kernel. For example:
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Linux/Windows data)
Partition unique GUID: 6BAD4248-FC6D-4487-A255-A3B57504BE10
First sector: 16065 (at 7.8 MiB)
Last sector: 131106464 (at 62.5 GiB)
Partition size: 131090400 sectors (62.5 GiB)
Attribute flags: 0000000000000000
Partition name: Linux/Windows data
The one you need is the "unique GUID": 6BAD4248-FC6D-4487-A255-A3B57504BE10
(I wish I could tell you what the "GUID code" is for, but I have NFI.)
So, in this specific example, the kernel boot parameter I would use is:
root=PARTUUID=6BAD4248-FC6D-4487-A255-A3B57504BE10
Note that the "PARTUUID" keyword was introduced very recently in linux kernel
2.6.37, and it has nothing whatever to do with the "UUID" keyword used in the
many online tutorials on how to build an initrd!
The whole point of this exercise is to show you how to avoid the need for an
initrd in the first place.
I've run out of steam for today. Questions/corrections are welcome :)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-01-25 23:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-23 22:28 [gentoo-user] [cookbook] grub2 for idiots like me walt
2011-01-24 17:00 ` [gentoo-user] Re: [cookbook] grub2 for idiots like me PART 2 walt
2011-01-25 23:41 ` [gentoo-user] [cookbook] Mounting root partition by UUID (no initrd needed) walt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox