xen bootloader

XendBootLoader.py:

  1. 判读bootloader是否存在
    •    Linux:/usr/bin/pygrub
    •    Windows: /usr/lib/xen/boot/hvmloade
  2. 判断 启动设备是否存在,不存在返回:Disk isn't accessible
  3. 打开一个管道,用于两个pty进程间通信:/var/run/xend/boot/xenbl.%s 
  4. 构造命令并在pty子进程中执行:
    • /usr/bin/pygrub [ --kernel=%s --ramdisk=%s --args=%s  --output=%s -q ] path-to-disk
  5. 如果子进程(执行bootloader)执行失败,或没有任何输出,则raise VmError, msg,否则返回sxp格式的结果。
   
源码中的注释:
    # We need to present the bootloader's tty as a pty slave that xenconsole
    # can access.  Since the bootloader itself needs a pty slave,
    # we end up with a connection like this:
    #
    # xenconsole -- (slave pty1 master) <-通过管道复制数据-> (master pty2 slave) -- bootloader
    #
    # where we copy characters between the two master fds, as well as
    # listening on the bootloader's fifo for the results.
    # filedescriptors:
    #   r - input from the bootloader (bootstring output)
    #   m1 - input/output from/to xenconsole
    #   m2 - input/output from/to pty that controls the bootloader
 
 
/usr/bin/pygrub

pygrub解析传入的分区的结构,如果是一个disk,那么就从disk找到active的分区,如果是分区,那就直接解析分区,然后引导启动。
Usage: /usr/bin/pygrub [-q|--quiet] [-i|--interactive] [--output=] [--kernel=] [--ramdisk=] [--args=] [--entry=] <image>
  1.  grub文件路径为:/boot/grub/menu.lst", "/boot/grub/grub.conf" 或 "/grub/menu.lst", "/grub/grub.conf"
  2. 使用pygrub,启动分区要放在第一个位置。
 
手动执行的结果是:
linux (kernel /var/run/xend/boot/boot_kernel.L_jphs)(ramdisk /var/run/xend/boot/boot_ramdisk.9Ed02z)(args "ro root=/dev/sda2 ")
 
PV-GRUB被认为是pygrub的取代:
 

PV-GRUB replaces PyGrub to boot domU images safely: it runs the regular grub inside the created domain itself and uses regular domU facilities to read the disk / fetch files from network etc.; it eventually loads the PV kernel and chain-boots it.

kernel = "/usr/lib/xen/boot/pv-grub-x86_32.gz"
extra = "(hd0,0)/grub/menu.lst"
 
/usr/lib/xen/boot/hvmloader

源码在hvmloader.c中,有待继续研究。
原文地址:https://www.cnblogs.com/feisky/p/2325022.html