[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH]: Save boot record before writing to the dest_drive

From: kashyap garimella
Subject: [PATCH]: Save boot record before writing to the dest_drive
Date: Sat, 12 Sep 2009 19:35:45 +0530


I have added the following new features:

1) when grub-setup runs, it automatically stores the areas of (mbr + embed) region, which are overwritten, into the file (in the following specified format) in root directory.

2) grub-setup can restore the stored mbr in the following format back to destination drive:

1st 8 bytes - for embed_region.start [ this is of type grub_uint64_t - 8bytes for sure]
next 8 bytes for the core_size, which is of size_t format. I put 8 bytes for this because if we want to restore the backup file
from i386, it will not cause a problem.

next core_size bytes for core.img

next one byte contains 0xff - used as a signature bit, seperating the embed and mbr regions
next GRUB_DISK_SECTOR_SIZE bytes for mbr

Typical operations:
1) grub-setup --help:
Usage: grub-setup [OPTION]... DEVICE

Set up images to boot from DEVICE.
DEVICE must be a GRUB device (e.g. ``(hd0,1)'').

  -b, --boot-image=FILE   use FILE as the boot image [default=boot.img]
  -c, --core-image=FILE   use FILE as the core image [default=core.img]
  -Z, --backup-file=FILE  use FILE as the backup/restore file [default=bootsector.bak]
  -d, --directory=DIR     use GRUB files in the directory DIR [default=/boot/grub]
  -m, --device-map=FILE   use FILE as the device map [default=/boot/grub/]
  -r, --root-device=DEV   use DEV as the root device [default=guessed]
  -f, --force             install even if problems are detected
  -h, --help              display this message and exit
  -z, --restore           restore the boot sectors
  -V, --version           print version information and exit
  -v, --verbose           print verbose messages

Therefore when we execute grub-setup -d <dir> /dev/sda (optionally -Z backup-file name), it will create a file called bootsector.bak in <dir> and write to it.
RESTORATION: (grub-setup --restore ) V ( grub-setup -z ) V (grub-setup -z -Z backup_file) .... [ according to the modified help ]

A warning:
util/i386/pc/grub-setup.c:93: warning: ‘backup_img’ may be used uninitialized in this function
When I remove the line (496 in the patched one):   free(backup_img);
the warning goes off.
I could not understand how to resolve it. I need some help

Patch obtained by
svn di util/i386/pc/grub-setup.c
applyihng patch:
patch util/i386/pc/grub-setup.c patch_save_mbr

I tried my best to follow the coding standards and the style. I am very enthusiastic in developing grub. Please suggest better format for storing the boot sectors.
I hope I am not introducing more bugs.

Thank you,
Kashyap Garimella Jagannadh (irc: garimella )
Undergraduate student,
Indian Instition of Technology (IIT), Madras.

Attachment: patch_save_mbr
Description: Binary data

reply via email to

[Prev in Thread] Current Thread [Next in Thread]