Difference between revisions of "GRUB Legacy (简体中文)"

From ArchWiki
Jump to: navigation, search
(Use new related template.)
Line 15: Line 15:
 
[[uk:GRUB]]
 
[[uk:GRUB]]
 
{{Translateme (简体中文)}}
 
{{Translateme (简体中文)}}
{{Article summary start|摘要}}
+
{{Related articles start (简体中文)}}
{{Article summary text|涵盖Archlinux缺省的启动加载器大部分方面, GRand Unified Bootloader (GRUB).}}
+
{{Related|Arch Boot Process}}
{{Article summary heading|概览}}
+
{{Related|Boot Loaders}}
{{Article summary text|{{Boot process overview (简体中文)}}}}
+
{{Related|Boot Debugging}}
{{Article summary heading|相关文章}}
+
{{Related|grub-gfx}}
{{Article summary wiki|Boot Debugging}}
+
{{Related|Kernel parameters}}
{{Article summary wiki|grub-gfx}}
+
{{Related articles end}}
{{Article summary end}}
+
  
 
'''[https://www.gnu.org/software/grub/grub-legacy.en.html GNU GRUB (Legacy)]''' 是一个来自 GNU 项目的启动引导程序。
 
'''[https://www.gnu.org/software/grub/grub-legacy.en.html GNU GRUB (Legacy)]''' 是一个来自 GNU 项目的启动引导程序。

Revision as of 12:23, 25 November 2013

Tango-preferences-desktop-locale.png本页面需要更新翻译,内容可能已经与英文脱节。要贡献翻译,请访问简体中文翻译组Tango-preferences-desktop-locale.png

附注: please use the first argument of the template to provide more detailed indications.

GNU GRUB (Legacy) 是一个来自 GNU 项目的启动引导程序。

GNU GRUB的前身为Grand Unified Bootloader,由 Erich Stefan Boleyn 设计和实现。

简单的说,启动引导程序是计算机启动时运行的第一个程序。它可用于选择操作系统分区上的不同内核,也可用于向这些内核传递启动参数。然后内核初始化操作系统的其余部分。

注意: Arch Linux 已经用 GRUB2 替代了 GRUB Legacy。参见这里的通知。建议用户使用 GRUB2Syslinux
注意: grub 包不支持 GPT 磁盘、BTRFS 文件系统和 UEFI 固件。

安装Grub包

Archlinux 是默认安装grub的。如果你在安装系统的时候没有安装,可以安装官方源grub 包。

另外,GRUB 必须安装到一个磁盘或分区的启动扇区中来作为启动加载器工作。这在 #Bootloader installation 部分有详细介绍。

升级到 GRUB(2)

是否必须升级

不是必须的。老 GRUB 不会从系统删除,工作照旧。

然而,和其它不被支持的软件包一样,后续的 bug 将无人修复。所以建议所有的用户抽时间升级到 GRUB 2.x, 或其它支持的 Boot Loader

如何升级

升级 GRUB Legacy 到 GRUB(2) 的步骤和从已有系统安装 GRUB(2) 基本一样。详细信息位于这里.

配置

配置文件位于 /boot/grub/menu.lst。按照你的要求编辑这个文件。

  • timeout # -- 默认操作系统被自动加载前的等待时间(单位是秒)。
  • default # -- 超时时默认的启动项。

一个范例配置文件(/boot 位于独立分区中):

/boot/grub/menu.lst
# Config file for GRUB - The GNU GRand Unified Bootloader
# /boot/grub/menu.lst

# DEVICE NAME CONVERSIONS
#
#  Linux           GRUB
# -------------------------
#  /dev/fd0        (fd0)
#  /dev/sda        (hd0)
#  /dev/sdb2       (hd1,1)
#  /dev/sda3       (hd0,2)
#

#  FRAMEBUFFER RESOLUTION SETTINGS
#     +-------------------------------------------------+
#          | 640x480    800x600    1024x768   1280x1024
#      ----+--------------------------------------------
#      256 | 0x301=769  0x303=771  0x305=773   0x307=775
#      32K | 0x310=784  0x313=787  0x316=790   0x319=793
#      64K | 0x311=785  0x314=788  0x317=791   0x31A=794
#      16M | 0x312=786  0x315=789  0x318=792   0x31B=795
#     +-------------------------------------------------+
#  for more details and different resolutions see
#  https://wiki.archlinux.org/index.php/GRUB#Framebuffer_Resolution

# general configuration:
timeout   5
default   0
color light-blue/black light-cyan/blue

# boot sections follow
# each is implicitly numbered from 0 in the order of appearance below
#
# TIP: If you want a 1024x768 framebuffer, add "vga=773" to your kernel line.
#
#-*

# (0) Arch Linux
title  Arch Linux
root   (hd0,0)
kernel /vmlinuz-linux root=/dev/sda3 ro
initrd /initramfs-linux.img

# (1) Windows
#title Windows
#rootnoverify (hd0,0)
#makeactive
#chainloader +1

寻找 GRUB 根分区

GRUB 必须被告知它的文件位于文件系统的位置。因为可能有多个系统存在 (也就是在多启动环境中)。 GRUB 文件总是位于/boot,它有可能在一个独立的分区中。

注意: GRUB 定义的存储设备的方式与传统的内核命名方式不同。
  • 硬盘定义为 (hdX);这也可以用来指定任何 USB 存储设备。
  • 设备和分区的编号从0开始。例如,BIOS 识别出的第一个硬盘被定为 (hd0)。第二个设备被叫做 (hd1)。这也应用到分区。因此第一个硬盘上的第二个分区叫做 (hd0,1).

如果你不知道 /boot 的位置,使用 GRUB shell find 命令来定位 GRUB 文件。作为 root 进入 GRUB shell:

# grub

下面的例子适用于没有独立 /boot 分区的系统。/boot 只是 / 下的一个目录:

grub> find /boot/grub/stage1

下面的例子适用于有独立的 /boot 分区的系统:

grub> find /grub/stage1

GRUB 会找到这个文件,然后输出 stage1 文件的位置。例如:

grub> find /grub/stage1
 (hd0,0)

这个返回值需要输入到配置文件的 root 行。输入 quit 退出这个 shell。

双启动到Windows

把段内容加入到你的/boot/grub/menu.lst末尾。它假设你的Windows启动分区是位于[s/h]da2。

/boot/grub/menu.lst
 # (2) Windows
 title Windows
 rootnoverify (hd0,0)
 makeactive
 chainloader +1
注意: 如果你尝试双启动到 Windows 7,你需要注释掉 makeactive 行。
注意: Windows 2000 和之后的版本不需要在第一个分区就可以启动(与通常认为的不同)。如果 Windows 分区改变了 (也就是说,如果你在 Windows 分区的前面添加了一个分区),你需要编辑 Windows 的 boot.ini 文件来反映改变。(参见本文获取更多细节。)

如果 Windows 位于另一块硬盘,需要使用 map 命令。这会欺骗你的 Windows 安装程序,让它以为自己在主硬盘上。假设你的 Windows 分区是在第二块硬盘上的第一个分区:

/boot/grub/menu.lst
 title Windows
 map (hd0) (hd1)
 map (hd1) (hd0)
 rootnoverify (hd1,0)
 makeactive
 chainloader +1
注意: 如果你尝试双启动到 Windows 7,你需要注释掉 makeactive 行。

双启动到GNU/Linux

和Arch linux的加载方式一样。例如:

/boot/grub/menu.lst
 title Other Linux
 root (hd0,2)
 kernel /path/to/kernel root=/dev/sda3 ro
 initrd /path/to/initrd
注意: 也许需要额外的选项,同时一个初始化内存盘需要使用。检查一下另一个发行版的 /boot/grub/menu.lst 来得到启动选项,或者参考 #chainloader 和 configfile (推荐)。

chainloaderconfigfile

  • 为了方便系统维护,应该使用 chainloaderconfigfile 命令启动提供了”自动化“引导的其他linux操作系统(例如: Debian, Ubuntu, openSUSE),这样就允许每个发行版自行维护需要的 menu.lst 启动选项。
  • chainloader命令能装载其他的启动引导器(而不是内核镜像); 当其他的启动引导器安装在一个分区的启动扇区(例如:GRUB)时就有用了. 这样就可以实现安装一个“主”GRUB在MBR和一些分散的GRUB在每个分区的引导记录区.
  • {ic|configfile}}命令能指导GRUB装载确切的配置文件. 这样就可以引导其他的操作系统的menu.lst而不需要在引导的操作系统上安装GRUB. 这种方法有一个警告就是其他操作系统的menu.lst可能和安装的GRUB版本不兼容; 许多版本的操作系统非常依赖于GRUB的版本.

例如, GRUB即将安装在MBR(主引导记录区)上,但是其他的启动引导器(可能是GRUB或者LILO)已经安装到了(hd0,2)启动扇区.

---------------------------------------------
|   |           |           |   %           |
| M |           |           | B %           |
| B |  (hd0,0)  |  (hd0,1)  | L %  (hd0,2)  |
| R |           |           |   %           |
|   |           |           |   %           |
---------------------------------------------
  |                           ^
  |       chainloading        |
  -----------------------------

你可以简单的在 menu.lst下添加:

title Other Linux
root (hd0,2)
chainloader +1

或者,当(hd0,2)上的启动引导器是GRUB时:

title Other Linux
root (hd0,2)
configfile /boot/grub/menu.lst

chainloader 命令也可以用来装载MBR的第二个驱动引导器:

title Other drive
rootnoverify (hd1)
chainloader +1

GNU/Linux的双启动 (GRUB2)

如果其他linux发行版本用GRUB2(如:ubuntu9.10或者更高版本),而且你在它的/分区安装了启动装载程序, 你可以添加如下条目到你的/boot/grub/menu.lst:

/boot/grub/menu.lst
 # other Linux using GRUB2
 title Ubuntu
 root (hd0,2)
 kernel /boot/grub/core.img

在启动时选择个标题就可以引导在/dev/sda3上的其他操作系统发行版本的GRUB2菜单.

启动加载器安装

手动恢复 GRUB 库

*stage*文件在/boot/grub目录下, 但是在如下情况下没有:启动装载程序在系统安装时没有安装或者/分区的文件系统损坏,意外删除等情况.

使用如下的命令手动复制GRUB的库文件:

# cp -a /usr/lib/grub/i386-pc/* /boot/grub
注意: 不要忘记挂载系统的boot分区如果用其他的操作系统做上面的操作!上面的boot分区既可以挂载在根分区也可以挂载在根分区的/boot目录下!

关于安装GRUB的常识(General notes about bootloader installation )

GRUB有可能从一个单独的介质安装(例如:一张LiveCD),或者直接从运行着的Arch中安装,GRUB启动引导器“很少”需要重新安装,当遇到如下情况时“不”需要安装:

  • 配置文件被更新了。
  • grub软件包被更新了。

遇到如下请况时“需要”安装:

  • 启动引导器还没有安装。
  • 其他的操作系统对linux的启动引导器重写了。
  • 启动引导器因为一些未知的原因未能成功引导系统

在重装或安装之前,请注意以下几点:

  • 在进行操作之前确保你的GRUB配置文件是正确的(/boot/grub/menu.lst)。请参考#Finding GRUB's root以确认你的设备被正确的定义。
  • GRUB必须安装在MBR(整个硬盘的第一扇区),或者在能被大多数BIOSes识别的第一个存储设备的第一个分区,为了满足个人的多系统引导需求,GRUB的多重设置就起作用了,请参考#chainloader and configfile
  • 在安装GRUB启动引导器时你需要在chrooted(即更改root目录)的环境下(例如:通过安装光盘chroot安装的系统),比如你编辑RAID的配置文件或者你忘记安装或者破坏了你的GRUB安装,你都需要通过一张LiveCD或者其他的linux操作系统Change Root(即更改root目录).

首先,在grub命令模式下键入:

使用root命令找到/boot下的文件(see #Finding GRUB's root),以便找到那个分区下包含引导的文件(配置好之后,使用/boot),即可引导启动:

grub> root (hd1,0)

建议:在GRUB命令行模式下支持命令补全,如果你建入'root (hd'然后连续敲击Tab两次你就可以看见可利用的存储分区设备,在分区下也适用,命令补全在GRUUB引导菜单上也适用,如果你为了自己编辑时产生错误,用Tab建找到设备和分区,请参考#Edit GRUB entries in the boot menu

安装到主引导记录区(Master Boot Record)

下面的例子安装GRUB到主引导记录区的第一阶段(计算机开机访问硬盘的首个扇区):

grub> setup (hd0)

安装到分区

下面的例子安装GRUB到整个硬盘的第一个分区:

grub> setup (hd0,0)

在运行setup完成之后, 键入 quit 退出命令行. 如果你更改了root目录, exit your chroot and unmount partitions. 现在重启测试一下.

其他替代方法 (grub-install)

注意: 这个操作不怎么可靠,推荐使用GRUB命令模式.

使用grub-install命令跟随你安装启动装载程序的分区. 例如将grub安装到第一块硬盘的MBR:

# grub-install /dev/sda

GRUB会显示它是否安装成功. 如果没有安装成功,你得用GRUB的命令模式.

技巧和窍门

附加的配置笔记.

图形化启动

对于那些渴望看见图形界面的人, 参阅grub-gfx. GRUB2 也提供增强的图形化功能,例如背景图片和点阵字体.

Framebuffer resolution

One can use the resolution given in the menu.lst, but you might want to use your LCD wide-screen at its full native resolution. Here is what you can do to achieve this:

On Wikipedia, there is a list of extended framebuffer resolutions (i.e. beyond the ones in the VBE standard). But, for example, the one I want to use for 1440x900 (vga=867) does not work. This is because the graphic card manufacturers are free to choose any number they wish, as this is not part of the VBE 3 standard. This is why these codes change from one card to the other (possibly even for the same manufacturer).

So instead of using that table, you can use one of the tools mentioned below to get the correct code:

GRUB recognized value

This is an easy way to find the resolution code using only GRUB itself.

On the kernel line, specify that the kernel should ask you which mode to use.

kernel /vmlinuz-linux root=/dev/sda1 ro vga=ask

Now reboot. GRUB will now present a list of suitable codes to use and the option to scan for even more.

You can pick the code you would like to use (do not forget it, it is needed for the next step) and boot using it.

Now replace ask in the kernel line with the correct one you have picked.

e.g. the kernel line for [369] 1680x1050x32 would be:

kernel /vmlinuz-linux root=/dev/sda1 ro vga=0x369

hwinfo

  1. Install hwinfo from [community].
  2. Run hwinfo --framebuffer as root.
  3. Pick up the code corresponding to the desired resolution.
  4. Use the 6 digit code with 0x prefix in vga= kernel option in menu.lst. Or convert it to decimal to avoid the use of 0x prefix.

Example output of hwinfo:

Mode 0x0364: 1440x900 (+1440), 8 bits
Mode 0x0365: 1440x900 (+5760), 24 bits

And the kernel line:

kernel /vmlinuz-linux root=/dev/sda1 ro vga=0x0365
注意: vbetest gives you VESA mode to which we need to add 512 to get the correct value to use in kernel option line. While hwinfo gives you directly the correct value needed by the kernel.

vbetest

  1. Install the lrmiAUR package from the AUR that contains the vbetest tool (x86_64 users will need to use #hwinfo above).
  2. Run vbetest as root
  3. Then note the number in [ ] corresponding to your desired resolution.
  4. Press 'q' to quit vbetest interactive prompt.
    1. As an option, in a console as root, you can test the mode you just picked up by running vbetest -m <yourcode> and see a pattern like this one
  5. Add 512 to the discovered value picked up above and use the total value to define the vga= parameter in the kernel options of menu.lst.
  6. Reboot to enjoy the result

For example vbetest on one computer:

[356] 1440x900 (256 color palette)
[357] 1440x900 (8:8:8)

So here the number you want is 357. Then, 357 + 512 = 869, so you will use vga=869. Add your value to the end of the kernel line in menu.lst as shown below:

kernel /vmlinuz-linux root=/dev/sda1 ro vga=869
Note:
  • (8:8:8) is for 24-bit color (24bit is 32bit)
  • (5:6:5) is for 16-bit color
  • (5:5:5) is for 15-bit color

Naming by label

If you alter (or plan to alter) partition sizes from time to time, you might want to consider defining your drive/partitions by a label. You can label ext2, ext3, ext4 partitions by:

e2label </dev/drive|partition> label

The label name can be up to 16 characters long but cannot have spaces for GRUB to understand it. Then define it in your menu.lst:

kernel /boot/vmlinuz-linux root=/dev/disk/by-label/Arch_Linux ro

Password protection

You can enable password protection in the GRUB configuration file for operating systems you wish to have protected. Bootloader password protection may be desired if your BIOS lacks such functionality and you need the extra security.

First, choose a password you can remember and then encrypt it:

# grub-md5-crypt
Password:
Retype password:
$1$ZOGor$GABXUQ/hnzns/d5JYqqjw

Then add your password to the beginning of the GRUB configuration file (the password must be at the beginning of the configuration file for GRUB to be able to recognize it):

# general configuration
timeout   5
default   0
color light-blue/black light-cyan/blue

password --md5 $1$ZOGor$GABXUQ/hnzns/d5JYqqjw

Then for each operating system you wish to protect, add the lock command:

# (0) Arch Linux
title  Arch Linux
lock
root   (hd0,1)
kernel /boot/vmlinuz-linux root=/dev/disk/by-label/Arch_Linux ro
initrd /boot/initramfs-linux.img
Warning: If you disable booting from other boot devices (like a CD drive) in the BIOS's settings and then password protect all your operating system entries, it could be difficult to re-enable booting back into the operating systems if the password is forgotten.

Restart with named boot choice

If you realize that you often need to switch to some other non-default OS (e.g. Windows) having to reboot and wait for the GRUB menu to appear is tedious. GRUB offers a way to record your OS choice when restarting instead of waiting for the menu, by designating a temporary new default which will be reset as soon as it has been used.

Supposing a simple menu.lst setup like this:

/boot/grub/menu.lst
# general configuration:
timeout 10
default 0
color light-blue/black light-cyan/blue

# (0) Arch
title  Arch Linux
root (hd0,1)
kernel /boot/vmlinuz-linux root=/dev/disk/by-label/ARCH ro
initrd /boot/initramfs-linux.img

# (1) Windows
title Windows XP
rootnoverify (hd0,0)
makeactive
chainloader +1

Arch is the default (0). We want to restart in to Windows. Change default 0 to default saved -- this will record the current default in a default file in the GRUB directory whenever the savedefault command is used. Now add the line savedefault 0 to the bottom of the Windows entry. Whenever Windows is booted, it will reset the default to Arch, thus making changing the default to Windows temporary.

Now all that is needed is a way to easily change the default manually. This can be accomplished using the command grub-set-default. So, to reboot into Windows, enter the following command:

$ sudo grub-set-default 1 && sudo shutdown -r now

For ease of use, you might to wish to implement the "Allow users to shutdown fix" (including /sbin/grub-set-default amongst the commands the user is allowed to issue without supplying a password).

LILO 和 GRUB 相互配合

如果LILO软件包已经安装在你的系统,删除它使用命令:

# pacman -R lilo

as some tasks (e.g. kernel compilation using make all) will make a LILO call, and LILO will then be installed over GRUB. LILO may have been included in your base system, depending on your installer media version and whether you selected/deselected it during the package selection stage.

Note: pacman -R lilo will not remove LILO from the MBR if it has been installed there; it will merely remove the lilo package. The LILO bootloader installed to the MBR will be overwritten when GRUB (or another bootloader) is installed over it.

GRUB 启动盘

首先,你需要格式化一张软盘:

 fdformat /dev/fd0
 mke2fs /dev/fd0

然后挂载软盘

 mount -t ext2 /dev/fd0 /mnt/fl

将grub安装到磁盘上:

 grub-install --root-directory=/mnt/fl '(fd0)'

复制你的 menu.lst 文件到磁盘上:

 cp /boot/grub/menu.lst /mnt/fl/boot/grub/menu.lst

现在卸载你的软盘:

 umount /mnt/fl

这样就完成了!现在你可以用这张磁盘重启你的计算机,它应该会用GRUB启动。当然还需先确认在你的BIOS里启动顺序中已经将软盘设为比硬盘更高优先级。

另见: Super GRUB Disk

隐藏GRUB菜单

hiddenmenu选项能默认隐藏菜单. 这样在启动时没有菜单显示但默认的选项会在启动延时后自动选择.你仍然可以按Esc让菜单显示出来. 要用这个选项, 只要在 /boot/grub/menu.lst文件中添加:

hiddenmenu

Advanced Debugging

Content moved to Boot_Debugging

Troubleshooting

GRUB Error 17

Note: the solution below works also for GRUB Error 15

The first check to do is to unplug any external drive. Seems obvious, but sometimes we get tired ;)

If your partition table gets messed up, an unpleasant "GRUB error 17" message might be the only thing that greets you on your next reboot. There are a number of reasons why the partition table could get messed up. Commonly, users who manipulate their partitions with GParted -- particularly logical drives -- can cause the order of the partitions to change. For example, you delete /dev/sda6 and resize /dev/sda7, then finally re-create what used to be /dev/sda6 only now it appears at the bottom of the list, /dev/sda9 for example. Although the physical order of the partitions/logical drives has not changed, the order in which they are recognized has changed.

Fixing the partition table is easy. Boot from your Arch CD/DVD/USB, login as root and fix the partition table:

# fdisk /dev/sda

Once in disk, enter e[x]tra/expert mode, [f]ix the partition order, then [w]rite the table and exit.

You can verify that the partition table was indeed fixed by issuing an fdisk -l. Now you just need to fix GRUB. See the #Bootloader installation section above.

Basically you need to tell GRUB the correct location of your /boot then re-write GRUB to the MBR on the disk.

For example:

# grub
grub> root (hd0,6)
grub> setup (hd0)
grub> quit

See [this page] for a more in-depth summary of this section.

/boot/grub/stage1 not read correctly

If you see this error message while trying to set up GRUB, and you are not using a fresh partition table, it is worth checking it.

# fdisk -l /dev/sda

This will show you the partition table for /dev/sda. So check here, whether the "Id" values of your partitions are correct. The "System" column will show you the description of the "Id" values.

If your boot partition is marked as being "HPFS/NTFS", for example, then you have to change it to "Linux". To do this, go to fdisk,

# fdisk /dev/sda

change a partition's system id with [t], select you partition number and type in the new system id (Linux = 83). You can also list all available system ids by typing "L" instead of a system id.

If you have changed a partitions system id, you should [v]erify your partition table and then [w]rite it.

Now try to set up GRUB again.

[Here] is the forum post reporting this problem.

Accidental install to a Windows partition

If you accidentally install GRUB to a Windows partition, GRUB will write some information to the boot sector of the partition, erasing the reference to the Windows bootloader. (This is true for NTLDR the bootloader for Windows XP and earlier, unsure about later versions).

To fix this you will need to use the Windows Recovery Console for your Windows release. Because many computer manufacturers do not include this with their product (many choose to use a recovery partition) Microsoft has made them available for download. If you use XP, look at this page to be able to turn the floppy disks to a Recovery CD. Boot the Recovery CD (or enable Windows Recovery mode) and run fixboot to repair the partition boot sector. After this, you will have to install GRUB again---this time, to the MBR, not to the Windows partition---to boot Linux.

See further discussion here.

Edit GRUB entries in the boot menu

Once you have selected and entry in the boot menu, you can edit it by pressing key e. Use tab-completion if you need to to discover devices then Esc to exit. Then you can try to boot by pressing b.

Note: These settings will not be saved.

device.map error

If an error is raised mentioning /boot/grub/device.map during installation or boot, run:

# grub-install --recheck /dev/sda

to force GRUB to recheck the device map, even if it already exists. This may be necessary after resizing partitions or adding/removing drives.

KDE reboot pull-down menu fails

If you have opened a sub-menu with the list of all operating systems configured in GRUB, selected one, and upon restart, you still booted your default OS, then you might want to check if you have the line:

default saved

in /boot/grub/menu.lst.

GRUB fails to find or install to any virtio /dev/vd* or other non-BIOS devices

I had trouble installing GRUB while installing Arch Linux in an virtual KVM machine using a virtio device for hard drive. To install GRUB, I figured out the following: Enter a virtual console by typing Ctrl+Alt+F2 or any other F-key for a free virtual console. This assumes that your root file system is mounted in the folder /mnt and the boot file system is either mounted or stored in the folder /mnt/boot.

1. Assure that all needed GRUB files is present in your boot directory (assuming it is mounted in /mnt/boot folder), by issuing the command:

# ls /mnt/boot/grub

2. If the /mnt/boot/grub folder already contains all the needed files, jump to step 3. Otherwise, do the following commands (replacing /mnt, your_kernel and your_initrd with the real paths and file names). You should also have the menu.lst file written to this folder:

# mkdir -p /mnt/boot/grub                # if the folder is not yet present
# cp -r /boot/grub/stage1 /boot/grub/stage2 /mnt/boot/grub
# cp -r your_kernel your_initrd /mnt/boot

3. Start the GRUB shell with the following command:

# grub --device-map=/dev/null

4. Enter the following commands. Replace /dev/vda, and (hd0,0) with the correct device and partition corresponding to your setup.

device (hd0) /dev/vda
root (hd0,0)
setup (hd0)
quit

5. If GRUB reports no error messages, then you probably are done. You also need to add appropriate modules to the ramdisk. For more information, please refer to the KVM guide on Preparing an (Arch) Linux guest

External resources