BootLoader & Grub详解
来源:互联网 发布:图片展示类cms系统 编辑:程序博客网 时间:2024/05/22 17:31
We'll see how to boot operating systems in a few minutes. First, here are a few useful tricks to help you learn to use GRUB interactively if your computer's BIOS supports that. This is how to use GRUB to take a look around inside a computer.
Tab completion is a very useful feature of GRUB. In the example shown below I want to use Tab completion to find out what hard disks and partitions ane in my computer,
grub> root (hd_There are some numbers that are supposed to follow '(hd' that we may not already know, so after we type: 'root (hd' we press our 'Tab' key. We use 'Tab' completion to allow GRUB to suggest some possibilities.
grub> root (hd
Possible disks are: hd0 hd1Okay, I know my Linux partition in in my first hard disk, so I typed '0,' (zero, comma) in after '(hd' and pressed 'Tab again for a list of partitions,
grub> root (hd0,
Possible partitions are:
Partition num: 0, Filesystem type is fat, partition type 0xc
Partition num: 1, Filesystem type is ext2fs, partition type 0x83
Partition num: 3, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type unknown, partition type 0x82These are a list of partitions in my computer. I want to choose one with a Linux kernel in it that I will be booting. It will likely be one of the partitions with the ext2fs file system, from here I can make a good guess.
Find Hard Disks
Here's another way to get GRUB to list all hard disks and partitions and give information on what filesystems are in a computer,
grub> geometry (hd_'Tab completion' is a very handy feature in GRUB's Command Line Interface. Make sure you use it as much as you can! In this example, I have typed the command 'geometry', and the first part only of a GRUB designation for a hard disk, without the number that normally belongs at the end of it, and press my tab key.
grub> geometry (hd
Possible disks are: hd0 hd1After pressing my 'Tab' key with the disk designation half typed, I get a list of all the hard disks currently in use by the machine.
Find Partitions
Now I want to find out what partitions are in the first hard disk,
grub> geometry (hd0)I completed the rest of the command and then pressed 'Enter' to see what partitions GRUB can detect on the first hard disk.
grub> geometry (hd0)
drive 0x80: C/H/S = 1023/255/63, The number of sectors = 156301488, LBA
Partition num: 0, Filesystem type is fat, partition type 0x1b
Partition num: 1, Filesystem type is ext2fs, partition type 0x83
Partition num: 3, Filesystem type unknown, partition type 0x7
Partition num: 4, Filesystem type unknown, partition type 0x82
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
Partition num: 6, Filesystem type is ext2fs, partition type 0x83
Partition num: 7, Filesystem type is ext2fs, partition type 0x83Okay, those are my partitions on the first hard disk, now I want to find out what partitions are on the second hard disk.
grub> geometry (hd1)
drive 0x81: C/H/S = 1023/255/63, The number of sectors = 58605120, LBA
Partition num: 2, Filesystem type is fat, partition type 0xb
Partition num: 3, Filesystem type is ext2fs, partition type 0x83
Now I know what partitions are in second hard disk.
I use these commands often to determine one hard disk from another before installing GRUB to a hard disk's MBR, to make sure I install the right GRUB to the right MBR.
Find out which partitions contain a Linux kernel
To find more information we can use the 'find' command, for example:
grub> find /vmlinuz
The feedback from the above command should give you one or more answers like:
grub> find /vmlinuz
(hd0,1)
(hd0,5)
(hd0,6)or something similar. These answers are all partitions that contain a Linux kernel.
Well, really, to be accurate, they are partitions which contain a symlink to a Linux kernel.
These partitions could be /boot partitions if an installation has separate /boot and / (root) partitions.
Find out which partition is your '/' or 'root' partition
grub> find /sbin/init
The results from the above command might appear as shown below,
grub> find /sbin/init
(hd0,1)
(hd0,5)
(hd0,6)
(hd0,7)
There are ways to have GRUB find out even more interesting information for us if it might help. We can open plain text files in any of those partitions we may be interested in with the 'cat' command. For a few examples,
grub> cat (hd0,7)/boot/grub/menu.lstThe installation's menu.lst file is certain to contain information useful to know for booting the machine's operating systems.
and,
grub> cat (hd0,7)/etc/fstabThe /etc/fstab file usually contains good information that might be useful to know for booting purposes
and also:
grub> cat (hd0,7)/boot/grub/device.map
The device.map file might occasionally be interesting to be able to see.
By the time you have tried out some of those extra commands you will be getting the idea that you can find out almost anything about any computer with GRUB's CLI.
That's probably all the information we need for getting GRUB to boot any Linux system.What You Absolutely Need to Know
Now let's take a look at an example. Imagine a system in which /dev/hda1 is mounted as /boot, and /dev/hda9 is mounted as / (你的根目录). Within /boot the kernel filename is vmlinuz-i686-up-4GB. Now let's answer the four questions:
(Remember, /dev/hda1 is mounted directly to /boot, so it contains the kernel directly)grub> root (hd0,0)
grub> kernel /vmlinuz-i686-up-4GB root=/dev/hda9
grub> boot
Be careful of these duelling root keywords. The standalone one is the root as seen from grub, and contains the kernel. The argument to the kernel statement is the root as seen from the fully booted system, and contains /sbin/init.
Be careful also of where you use grub partition notation and where you use Linux partition notation. You use grub partition notation ((hd0,0)) everywhere except the root=argument to the kernel statement. In the root= argument you use the Linux partition notation. Note that in Linux notation, the drive starts with a for the first IDE port master, then b for the first IDE port slave, then c for the second IDE port master, and d for the second IDE port slave, on and on throughout your IDE ports. In Linux notation, the partition number within the drive starts with 1.
In grub partition notation, the first accessible hard drive is (hd0), the next accessible hard drive (even if it's on the 3rd, 4th or higher IDE port) is (hd1), and so forth. In grub partition notation, the partition number is zero based. Thus:
/dev/hda1 is the same partition as (hd0,0)
Occasionally you'll need to specify an initrd, although this is rare. If so, after the kernel statement and of course before the boot statement, insert the following:initrd /initrd-i686-up-4GB.img
I have seen cases in which a kernel would kernel panic without an initrd statement, and would boot with it. The interesting thing is, once I got it booting, I could remove the initrd statement, rerun grub's setup, and it would now boot without the initrdstatement. If you get kernel panics and it isn't obvious why, don't hesitate to insert an initrd statement.
Another documented way to boot from grub is to put the grub-root in the kernel statement itself instead of as a separate entity:grub> kernel (hd0,0)/vmlinuz-i686-up-4GB root=/dev/hda9
grub> boot
- BootLoader & Grub详解
- BootLoader & Grub详解
- 金汤系列:bootloader之GRUB配置攻详解
- grub属于bootloader
- Grub for dos bootloader 分析
- Edit Ubuntu 16.04 bootloader GRUB
- bootloader详解
- Bootloader详解
- Bootloader详解
- bootloader详解
- GRUB详解
- grub详解
- GRUB详解
- GRUB详解
- grub详解
- Grub详解
- bootloader详解----bootloader的基本概念
- X86的bootloader(一):选择GRUB
- 初次来,算是个报告吧。
- Ubuntu下sudo命令的用法
- 一周小记
- Ogre 如何渲染简单的几何物体
- c语言就这样把我难到了,帮看看。谢谢
- BootLoader & Grub详解
- 三角函数取值范围
- Ogre中设置渲染性能参数
- WPF
- Java语法总结 - 内部类
- 位图排序
- 怎么访问局域网里面的计算机
- ubuntu10.10 搭建LAMP
- java Applet