• Save
Installing grub on virtual hard disk images
Upcoming SlideShare
Loading in...5
×
 

Installing grub on virtual hard disk images

on

  • 9,829 views

This presentation demonstrates the process to create a new Qemu usable virtual disk capable of self boot using the popular Grub boot loader. Grub in turn can boot other kernels placed on the disk file ...

This presentation demonstrates the process to create a new Qemu usable virtual disk capable of self boot using the popular Grub boot loader. Grub in turn can boot other kernels placed on the disk file system. The steps are applicable only for a GNU/Linux System. All tools used are readily available on all popular linux distros in use.

Statistics

Views

Total Views
9,829
Views on SlideShare
9,829
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Installing grub on virtual hard disk images Installing grub on virtual hard disk images Presentation Transcript

    • Installing grub on virtual hard disks
      Sukhvinder Singh
      http://www.linkedin.com/in/s0001
      sukh.chauhan@gmail.com
      30 Aug 2010
    • Steps
      This presentation demonstrates the process to create a new Qemu usable virtual disk capable of self boot using the popular Grub boot loader. Grub in turn can boot other kernels placed on the disk file system. The steps are applicable only for a GNU/Linux System. All tools used are readily available on all popular linuxdistros in use. To demonstrate we’ll take ubuntu-desktop as the reference test platform.
    • Create a disk image
      Create a disk image. You may create a file named disk.img, containing 40320 blocks ( a block has a standard size of 512 bytes). This results in a disk image of size 20643840 bytes ( = 21 MB). The size used is only for demonstration purposes. You may use a different size based on your requirement.
      40320 blocks
      x
      512 bytes/block
      =
      20643840 bytes
      (21 MB)
      $ dd if=/dev/zero of=disk.img count=40320
      40320+0 records in
      40320+0 records out
      20643840 bytes (21 MB) copied, 0.175132 s, 118 MB/s
    • Create a partition on the disk image
      Expert command (m for help): m
      Command action
      b move beginning of data in a partition
      c change number of cylinders (=40)
      d print the raw data in the partition table
      e list extended partitions
      f fix partition order
      g create an IRIX (SGI) partition table
      h change number of heads (=16)
      i change the disk identifier
      m print this menu
      p print the partition table
      q quit without saving changes
      r return to main menu
      s change number of sectors/track (=63)
      v verify the partition table
      w write table to disk and exit
      Use fdisk to create a partition on the disk image.
      Set CHS (Cylinder-Head-Sectors) geometry of the disk
      Create a primary partition
      Set the OS identifier for the partition to 83 (Linux)
      Calculate CHS:
      The number of sectors in a cylinder is fixed to 63 ( a popular constant ), S = 63
      Taking heads to an arbitrary value of 16, H=16 (another popular constant)
      C * H * S = Number of blocks = 40320
      C * 16 * 63 = 40320
      C = 40 ; H = 16 ; S = 63
    • Setup the loopback device
      Using fdisk, find the starting sector of the recently created partition. The start field shows the starting sector of the partition.
      There are about 32256 bytes before the first partition begins.
      $ fdisk -u -l disk.img
      Device Boot Start End Blocks Id System
      disk.img1 63 40319 20128+ 83 Linux
      • Set up the loop device to point to the start sector (i.e. 32256 bytes )
      $ losetup -o 32256 /dev/loop0 disk.img
    • Create a file system
      Format the disk and create an ext2 filesystem on the image
      $ mkfs.ext2 /dev/loop0
      Mount the image
      Mount the disk image to a directory on the local filesystem
      $ mount /dev/loop0 /mnt
      Detach the loopback device
      $ losetup –d /dev/loop0
    • Install Grub
      $ mkdir -p /mnt/boot/grub $ cp /boot/grub/stage1 /boot/grub/stage2 /mnt/boot/grub/ $ vi /mnt/boot/grub/grub.conf title=MyKernel root (hd0,0) kernel /mykernel
      $ mkdir -p /mnt/boot/grub $ cp /boot/grub/stage1 /boot/grub/stage2 /mnt/boot/grub/ $ vi /mnt/boot/grub/grub.conf title=MyKernel root (hd0,0) kernel /mykernel
      $ mkdir -p /mnt/boot/grub $ cp /boot/grub/stage1 /boot/grub/stage2 /mnt/boot/grub/
      Copy Grub files (stage1 and stage2) from your existing distro (in our case, ubuntu system) to the image file.
      $ mkdir -p /mnt/boot/grub
      $ cp /usr/lib/grub/i386-pc/stage1 /usr/lib/grub/i386-pc/stage2 /mnt/boot/grub/
      • Unmount the disk image
      $ umount /mnt
    • Setup Grub device-map
      $ grub --device-map=/dev/null
      device (hd0) disk.img
      geometry (hd0) 40 16 63
      root (hd0,0)
      setup (hd0)
      quit
    • Boot using Qemu
      The following command will bring up the Qemu window and boot from the new disk.img.
      $ qemu –hda disk.img –m 128
      The grub boot code on the disk.img boots to stage2 and brings up a grub command prompt.
      grub >
      If you have placed a multiboot specification compliant kernel (for ex. linux kernel 2.6.* ) on the disk.img filesystem under /boot directory, the following command will bring up the kernel.
      grub> kernel /boot/kernel.bin
      grub> boot
    • For more information, contact:Sukhvinder Singhhttp://www.linkedin.com/in/s0001sukh.chauhan@gmail.com