* [PATCH] Backup old boot sectors before installation
@ 2009-12-11 9:26 Zhu Yi
2009-12-11 9:39 ` Felix Zielcke
2009-12-24 21:21 ` Robert Millan
0 siblings, 2 replies; 19+ messages in thread
From: Zhu Yi @ 2009-12-11 9:26 UTC (permalink / raw)
To: grub-devel; +Cc: Zhu Yi
Add a feature to backup the old boot sectors before overwritting
them with grub2 boot and core images. Users can later recover the
previous boot sectors with grub-install --recover option.
P.S. I found this might be a useful feature after I overwrote my
second PGP encrypted hard disk (Windows XP installed) boot sectors
by grub2 by mistake.
Signed-off-by: Zhu Yi <yi.zhu@intel.com>
---
diff --git a/util/i386/pc/grub-install.in b/util/i386/pc/grub-install.in
index 8a06213..c33bd87 100644
--- a/util/i386/pc/grub-install.in
+++ b/util/i386/pc/grub-install.in
@@ -51,6 +51,7 @@ no_floppy=
force_lba=
recheck=no
debug=no
+recover=
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
disk_module=biosdisk
@@ -77,6 +78,7 @@ Install GRUB on your drive.
--no-floppy do not probe any floppy drive
--recheck probe a device map even if it already exists
--force install even if problems are detected
+ --recover restore the previous boot sectors
EOF
if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then
cat <<EOF
@@ -129,6 +131,10 @@ for option in "$@"; do
debug=yes ;;
-f | --force)
setup_force="--force" ;;
+ --recover)
+ recover="$grub_prefix/bootsectors.bak" ;;
+ --recover=*)
+ recover=`echo "$option" | sed 's/--recover=//'` ;;
-*)
echo "Unrecognized option \`$option'" 1>&2
usage
@@ -203,6 +209,37 @@ else
exit 1
fi
+if test -f "$recover"; then
+ if test `stat -c%s $recover` -eq 512; then
+ echo "The backup file $recover contains MBR only. Did you install"
+ echo "grub2 using UNRELIABLE blocklist with --force? If so, try to"
+ echo "recover with `dd if=$recover of=$1 bs=512 count=1`. But you"
+ echo "take your own risk!"
+ exit 1
+ fi
+ start=`od -j512 -N8 -An -td8 $recover`
+ start2=`od -j92 -N8 -An -td8 $grubdir/boot.img`
+
+ # Synaty check for the recovery file
+ if test $start -ne $start2; then
+ echo "Error: start position of $recover doesn't match with boot.img"
+ exit 1
+ fi
+ if test $((`stat -c%s $recover` - 520)) -ne \
+ `stat -c%s $grubdir/core.img`; then
+ echo "Error: $recover doesn't match current core.img"
+ exit 1
+ fi
+
+ # Recovery
+ dd if=$recover of=$install_device bs=512 count=1 > /dev/null 2>&1
+ dd if=$recover of=$install_device skip=520 seek=`expr $start \* 512` \
+ bs=1 > /dev/null 2>&1
+ rm -f $recover
+ echo "Recover boot sectors from $recover successfully"
+ exit 0
+fi
+
# Create the GRUB directory if it is not present.
test -d "$bootdir" || mkdir "$bootdir" || exit 1
test -d "$grubdir" || mkdir "$grubdir" || exit 1
diff --git a/util/i386/pc/grub-setup.c b/util/i386/pc/grub-setup.c
index c536be0..e862e9b 100644
--- a/util/i386/pc/grub-setup.c
+++ b/util/i386/pc/grub-setup.c
@@ -45,7 +45,9 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <dirent.h>
+#include <errno.h>
#include <grub/util/getroot.h>
#define _GNU_SOURCE 1
@@ -53,6 +55,7 @@ static const grub_gpt_part_type_t grub_gpt_partition_type_bios_boot = GRUB_GPT_P
#define DEFAULT_BOOT_FILE "boot.img"
#define DEFAULT_CORE_FILE "core.img"
+#define DEFAULT_BACKUP_FILE "bootsectors.bak"
/* This is the blocklist used in the diskboot image. */
struct boot_blocklist
@@ -85,7 +88,7 @@ grub_refresh (void)
static void
setup (const char *dir,
- const char *boot_file, const char *core_file,
+ const char *boot_file, const char *core_file, const char *backup_file,
const char *root, const char *dest, int must_embed, int force, int fs_probe)
{
char *boot_path, *core_path, *core_path_dev;
@@ -396,6 +399,63 @@ setup (const char *dir,
block->len = 0;
block->segment = 0;
+ int grub_disk_backup(grub_disk_t disk, grub_disk_addr_t sector,
+ grub_off_t offset, grub_size_t size, const char *path)
+ {
+ char *tmp_buf;
+ char mbr[GRUB_DISK_SECTOR_SIZE];
+ int fd;
+
+ grub_util_info ("opening the backup file `%s'", path);
+ fd = open (path, O_CREAT|O_EXCL|O_WRONLY);
+ if (fd < 0) {
+ if (errno == EEXIST)
+ return 0;
+ else {
+ fprintf (stderr, "couldn't open backup file `%s'", path);
+ return -1;
+ }
+ }
+
+ fp = fdopen (fd, "wb");
+ if (! fp) {
+ close (fd);
+ return -1;
+ }
+
+ /* Backup MBR */
+ if (grub_disk_read (disk, 0, 0, GRUB_DISK_SECTOR_SIZE, mbr) !=
+ GRUB_ERR_NONE) {
+ fclose (fp);
+ return -1;
+ }
+
+ grub_util_write_image (mbr, GRUB_DISK_SECTOR_SIZE, fp);
+
+ /* Record the start position of core image */
+ if (fwrite(§or, sizeof(sector), 1, fp) != 1) {
+ fclose (fp);
+ return -1;
+ }
+
+ /* Backup the sectors will be overwritten by core image */
+ tmp_buf = xmalloc (size);
+ if (grub_disk_read (disk, sector, offset, size, tmp_buf) != GRUB_ERR_NONE) {
+ fclose (fp);
+ return -1;
+ }
+
+ grub_util_write_image (tmp_buf, size, fp);
+
+ fclose (fp);
+ return 0;
+ }
+
+ /* Backup MBR and the sectors will be overwritten by core image */
+ if (grub_disk_backup (dest_dev->disk, embed_region.start, 0, core_size,
+ grub_util_get_path (dir, backup_file)))
+ grub_util_error ("failed to backup previous boot sectors");
+
/* Write the core image onto the disk. */
if (grub_disk_write (dest_dev->disk, embed_region.start, 0, core_size, core_img))
grub_util_error ("%s", grub_errmsg);
@@ -548,6 +608,11 @@ unable_to_embed:
grub_util_write_image (core_img, GRUB_DISK_SECTOR_SIZE * 2, fp);
fclose (fp);
+ /* Backup MBR */
+ if (grub_disk_backup (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE,
+ grub_util_get_path (dir, backup_file)))
+ grub_util_error ("failed to backup previous boot sectors");
+
/* Write the boot image onto the disk. */
if (grub_disk_write (dest_dev->disk, 0, 0, GRUB_DISK_SECTOR_SIZE, boot_img))
grub_util_error ("%s", grub_errmsg);
@@ -596,6 +661,7 @@ DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
-d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n\
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
-r, --root-device=DEV use DEV as the root device [default=guessed]\n\
+ -k, --backup-file=FILE use FILE as the backup file [default=%s]\n\
-f, --force install even if problems are detected\n\
-s, --skip-fs-probe do not probe for filesystems in DEVICE\n\
-h, --help display this message and exit\n\
@@ -605,7 +671,7 @@ DEVICE must be a GRUB device (e.g. ``(hd0,1)'').\n\
Report bugs to <%s>.\n\
",
DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY,
- DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
+ DEFAULT_DEVICE_MAP, DEFAULT_BACKUP_FILE, PACKAGE_BUGREPORT);
exit (status);
}
@@ -627,6 +693,7 @@ main (int argc, char *argv[])
{
char *boot_file = 0;
char *core_file = 0;
+ char *backup_file = 0;
char *dir = 0;
char *dev_map = 0;
char *root_dev = 0;
@@ -638,7 +705,7 @@ main (int argc, char *argv[])
/* Check for options. */
while (1)
{
- int c = getopt_long (argc, argv, "b:c:d:m:r:hVvf", options, 0);
+ int c = getopt_long (argc, argv, "b:c:d:m:r:k:hVvf", options, 0);
if (c == -1)
break;
@@ -680,6 +747,13 @@ main (int argc, char *argv[])
root_dev = xstrdup (optarg);
break;
+ case 'k':
+ if (backup_file)
+ free (backup_file);
+
+ backup_file = xstrdup (optarg);
+ break;
+
case 'f':
force = 1;
break;
@@ -789,6 +863,7 @@ main (int argc, char *argv[])
setup (dir ? : DEFAULT_DIRECTORY,
boot_file ? : DEFAULT_BOOT_FILE,
core_file ? : DEFAULT_CORE_FILE,
+ backup_file ? : DEFAULT_BACKUP_FILE,
root_dev, grub_util_get_grub_dev (devicelist[i]), 1, force, fs_probe);
}
}
@@ -798,6 +873,7 @@ main (int argc, char *argv[])
setup (dir ? : DEFAULT_DIRECTORY,
boot_file ? : DEFAULT_BOOT_FILE,
core_file ? : DEFAULT_CORE_FILE,
+ backup_file ? : DEFAULT_BACKUP_FILE,
root_dev, dest_dev, must_embed, force, fs_probe);
/* Free resources. */
@@ -806,6 +882,7 @@ main (int argc, char *argv[])
free (boot_file);
free (core_file);
+ free (backup_file);
free (dir);
free (dev_map);
free (root_dev);
^ permalink raw reply related [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-11 9:26 [PATCH] Backup old boot sectors before installation Zhu Yi
@ 2009-12-11 9:39 ` Felix Zielcke
2009-12-11 22:23 ` Carles Pina i Estany
2009-12-14 2:48 ` Zhu Yi
2009-12-24 21:21 ` Robert Millan
1 sibling, 2 replies; 19+ messages in thread
From: Felix Zielcke @ 2009-12-11 9:39 UTC (permalink / raw)
To: The development of GNU GRUB
Am Freitag, den 11.12.2009, 17:26 +0800 schrieb Zhu Yi:
> Add a feature to backup the old boot sectors before overwritting
> them with grub2 boot and core images. Users can later recover the
> previous boot sectors with grub-install --recover option.
>
> P.S. I found this might be a useful feature after I overwrote my
> second PGP encrypted hard disk (Windows XP installed) boot sectors
> by grub2 by mistake.
>
> Signed-off-by: Zhu Yi <yi.zhu@intel.com>
Someone already made a patch for this inside grub-setup
See here and also for the discussion of it:
http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00242.html
--
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-11 9:39 ` Felix Zielcke
@ 2009-12-11 22:23 ` Carles Pina i Estany
2009-12-14 2:48 ` Zhu Yi
1 sibling, 0 replies; 19+ messages in thread
From: Carles Pina i Estany @ 2009-12-11 22:23 UTC (permalink / raw)
To: The development of GNU GRUB
Hi,
On Dec/11/2009, Felix Zielcke wrote:
> Am Freitag, den 11.12.2009, 17:26 +0800 schrieb Zhu Yi:
> > Add a feature to backup the old boot sectors before overwritting
> > them with grub2 boot and core images. Users can later recover the
> > previous boot sectors with grub-install --recover option.
> >
> > P.S. I found this might be a useful feature after I overwrote my
> > second PGP encrypted hard disk (Windows XP installed) boot sectors
> > by grub2 by mistake.
> >
> > Signed-off-by: Zhu Yi <yi.zhu@intel.com>
>
> Someone already made a patch for this inside grub-setup
> See here and also for the discussion of it:
> http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00242.html
I like the idea, and I think that as Colin pointed it out it can be
useful.
I haven't watched to any of the implementations.
--
Carles Pina i Estany
http://pinux.info
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-11 9:39 ` Felix Zielcke
2009-12-11 22:23 ` Carles Pina i Estany
@ 2009-12-14 2:48 ` Zhu Yi
2009-12-14 2:58 ` Isaac Dupree
2009-12-14 2:59 ` kashyap garimella
1 sibling, 2 replies; 19+ messages in thread
From: Zhu Yi @ 2009-12-14 2:48 UTC (permalink / raw)
To: The development of GNU GRUB
On Fri, 2009-12-11 at 17:39 +0800, Felix Zielcke wrote:
>
> Someone already made a patch for this inside grub-setup
> See here and also for the discussion of it:
> http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00242.html
Thanks. If I knew this patch, I won't try to write one my own. I did do
some basic search and asked in #grub2 IRC before writing it though.
Anyway, I did a quick review for Garimella's patch. Both the ideas of
the two patches are the same: backup the mbr and boot sectors will be
overwritten by core.img to a file before grub2 overwrites them. The
implementations slightly differ in:
1. The format of the backup file.
The old boot sectors and the start of embed_region position is required
for both patches. Garimella also added some redundant fields (i.e. image
size and 0xff) for integrity checking. I think it's a good idea. But
something like a md5/sha1 checksum should be even better.
2. The image backup and recovery.
Both of the patches choose to backup the old boot sectors in
grub-setup.c. On the recovery, Garimella selected to do it in
grub-setup.c and I used grub-install script with dd(1). I don't think
this is a very big deal and either way is OK. The reason I choose
grub-install is I want to keep the grub-setup.c as clean as possible.
Because given the backup file format, one can recover it with dd(1) even
without any help with grub-setup.
3. The backup policy.
Garimella's patch backups every time before grub-setup overwrote the
boot sectors. There might be a problem when someone run
grub-setup/grub-install twice. So the backup image ends up with the
grub2 boot sectors. This makes the recovery for the "real" boot sectors
impossible. My patch won't overwrite if a previous backup image already
existed. grub-install will remove the backup image after a successful
recovery.
4. Blocklists installation.
This is not very important because blocklists is not recommended. To be
completeness, my patch backups the mbr if blocklists are used due to
embedding is not possible. This will be detected by grub-install as
well.
In conclusion, I believe this backup feature is useful and either
implementation should do the work. If we can merge the good parts of
them, we can get a better one. I just curious why the thread is stuck
since September. Any blocking issues with it? Can we keep the topic
moving forward? Your comments are highly welcome.
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 2:48 ` Zhu Yi
@ 2009-12-14 2:58 ` Isaac Dupree
2009-12-14 3:32 ` Zhu Yi
2009-12-14 2:59 ` kashyap garimella
1 sibling, 1 reply; 19+ messages in thread
From: Isaac Dupree @ 2009-12-14 2:58 UTC (permalink / raw)
To: The development of GNU GRUB
Zhu Yi wrote:
> 3. The backup policy.
>
> Garimella's patch backups every time before grub-setup overwrote the
> boot sectors. There might be a problem when someone run
> grub-setup/grub-install twice. So the backup image ends up with the
> grub2 boot sectors. This makes the recovery for the "real" boot sectors
> impossible. My patch won't overwrite if a previous backup image already
> existed. grub-install will remove the backup image after a successful
> recovery.
maybe the boot sector is small enough that we could just keep separate
additional backup files each time grub-setup/grub-install is used? e.g.
backup-1
backup-2
backup-3
or maybe using date/time instead of sequential numbering would be nicer.
-Isaac
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 2:48 ` Zhu Yi
2009-12-14 2:58 ` Isaac Dupree
@ 2009-12-14 2:59 ` kashyap garimella
2009-12-14 3:08 ` richardvoigt
2009-12-14 3:15 ` Zhu Yi
1 sibling, 2 replies; 19+ messages in thread
From: kashyap garimella @ 2009-12-14 2:59 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 2956 bytes --]
On Mon, Dec 14, 2009 at 8:18 AM, Zhu Yi <yi.zhu@intel.com> wrote:
> On Fri, 2009-12-11 at 17:39 +0800, Felix Zielcke wrote:
> >
> > Someone already made a patch for this inside grub-setup
> > See here and also for the discussion of it:
> > http://lists.gnu.org/archive/html/grub-devel/2009-09/msg00242.html
>
> Thanks. If I knew this patch, I won't try to write one my own. I did do
> some basic search and asked in #grub2 IRC before writing it though.
>
> Anyway, I did a quick review for Garimella's patch. Both the ideas of
> the two patches are the same: backup the mbr and boot sectors will be
> overwritten by core.img to a file before grub2 overwrites them. The
> implementations slightly differ in:
>
> 1. The format of the backup file.
>
> The old boot sectors and the start of embed_region position is required
> for both patches. Garimella also added some redundant fields (i.e. image
> size and 0xff) for integrity checking. I think it's a good idea. But
> something like a md5/sha1 checksum should be even better.
>
> 2. The image backup and recovery.
>
> Both of the patches choose to backup the old boot sectors in
> grub-setup.c. On the recovery, Garimella selected to do it in
> grub-setup.c and I used grub-install script with dd(1). I don't think
> this is a very big deal and either way is OK. The reason I choose
> grub-install is I want to keep the grub-setup.c as clean as possible.
> Because given the backup file format, one can recover it with dd(1) even
> without any help with grub-setup.
>
> md5/sha sum is a good idea. If you want, I can implement it.
> 3. The backup policy.
>
> Garimella's patch backups every time before grub-setup overwrote the
> boot sectors. There might be a problem when someone run
> grub-setup/grub-install twice. So the backup image ends up with the
> grub2 boot sectors. This makes the recovery for the "real" boot sectors
> impossible. My patch won't overwrite if a previous backup image already
> existed. grub-install will remove the backup image after a successful
> recovery.
>
I think this is questionable. Some prefer to backup only the previous copy
of mbr. Some prefer to save the oldest copy.
We can take the users' opinion.
> 4. Blocklists installation.
>
> This is not very important because blocklists is not recommended. To be
> completeness, my patch backups the mbr if blocklists are used due to
> embedding is not possible. This will be detected by grub-install as
> well.
>
>
> In conclusion, I believe this backup feature is useful and either
> implementation should do the work. If we can merge the good parts of
> them, we can get a better one. I just curious why the thread is stuck
> since September. Any blocking issues with it? Can we keep the topic
> moving forward? Your comments are highly welcome.
>
> The reason is very simple. If you are good user, you should have already
backed up your copy on your own. And this feature is not necessary.
-Garimella Kashyap
[-- Attachment #2: Type: text/html, Size: 3911 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 2:59 ` kashyap garimella
@ 2009-12-14 3:08 ` richardvoigt
2009-12-14 3:24 ` Isaac Dupree
2009-12-14 3:15 ` Zhu Yi
1 sibling, 1 reply; 19+ messages in thread
From: richardvoigt @ 2009-12-14 3:08 UTC (permalink / raw)
To: The development of GNU GRUB
>> In conclusion, I believe this backup feature is useful and either
>> implementation should do the work. If we can merge the good parts of
>> them, we can get a better one. I just curious why the thread is stuck
>> since September. Any blocking issues with it? Can we keep the topic
>> moving forward? Your comments are highly welcome.
>>
> The reason is very simple. If you are good user, you should have already
> backed up your copy on your own. And this feature is not necessary.
That opinion was voiced, then countered and I think even the author of
that opinion eventually retracted it.
An automatic backup is valuable both for savvy users who know how but
forgot, and for those who will find the backup and restore procedures
online only after their computer is bricked.
>
> -Garimella Kashyap
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 2:59 ` kashyap garimella
2009-12-14 3:08 ` richardvoigt
@ 2009-12-14 3:15 ` Zhu Yi
1 sibling, 0 replies; 19+ messages in thread
From: Zhu Yi @ 2009-12-14 3:15 UTC (permalink / raw)
To: The development of GNU GRUB
On Mon, 2009-12-14 at 10:59 +0800, kashyap garimella wrote:
> In conclusion, I believe this backup feature is useful and
> either
> implementation should do the work. If we can merge the good
> parts of
> them, we can get a better one. I just curious why the thread
> is stuck
> since September. Any blocking issues with it? Can we keep the
> topic
> moving forward? Your comments are highly welcome.
>
> The reason is very simple. If you are good user, you should have
> already backed up your copy on your own. And this feature is not
> necessary.
Is grub2 only designed for "good users"? I'm not. Or at least, Ubuntu
update-grub2 script is not. It messes up with the two disks (with
drivemap? not sure) in my laptop and overwrote PGP encrypted hard disk.
That's the motivation for me to write this patch. Boot sectors are
important. You know how to backup is one story. But when to backup is
another and even important in this case.
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 3:08 ` richardvoigt
@ 2009-12-14 3:24 ` Isaac Dupree
2009-12-14 3:35 ` Zhu Yi
0 siblings, 1 reply; 19+ messages in thread
From: Isaac Dupree @ 2009-12-14 3:24 UTC (permalink / raw)
To: The development of GNU GRUB
richardvoigt@gmail.com wrote:
> An automatic backup is valuable both for savvy users who know how but
> forgot, and for those who will find the backup and restore procedures
> online only after their computer is bricked.
hmm....
bootloader installation is often done by distro install-CDs.
Will the distro be smart enough to save these backups to the disk
somewhere sensible, rather than to the temporary in-memory filesystem?
I'm... Just being paranoid enough to ask this question -- I never quite
trust by install CDs not to install a bootloader, because I have to find
the right place in the GUI install sequence to disable doing so (and
hope that disabling works -- as a supposedly "advanced" option,
sometimes it's not been tested enough). Anything GRUB2 upstream can do
to make this less risky will make me happy!
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 2:58 ` Isaac Dupree
@ 2009-12-14 3:32 ` Zhu Yi
0 siblings, 0 replies; 19+ messages in thread
From: Zhu Yi @ 2009-12-14 3:32 UTC (permalink / raw)
To: The development of GNU GRUB
On Mon, 2009-12-14 at 10:58 +0800, Isaac Dupree wrote:
> maybe the boot sector is small enough that we could just keep
> separate
> additional backup files each time grub-setup/grub-install is used?
> e.g.
> backup-1
> backup-2
> backup-3
>
> or maybe using date/time instead of sequential numbering would be
> nicer.
Yup, I thought this before. This is certainly an option, but it also
requires the user to remember what is 1, 2, 3 or what did I do on date1,
date2, date3 on the recovery.
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 3:24 ` Isaac Dupree
@ 2009-12-14 3:35 ` Zhu Yi
2009-12-14 3:52 ` Isaac Dupree
0 siblings, 1 reply; 19+ messages in thread
From: Zhu Yi @ 2009-12-14 3:35 UTC (permalink / raw)
To: The development of GNU GRUB
On Mon, 2009-12-14 at 11:24 +0800, Isaac Dupree wrote:
> hmm....
> bootloader installation is often done by distro install-CDs.
>
> Will the distro be smart enough to save these backups to the disk
> somewhere sensible, rather than to the temporary in-memory
> filesystem?
The backup files will (normally) be stored in /boot/grub/ together with
grub.cfg and core.img. I assume it is not in memory. No?
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-14 3:35 ` Zhu Yi
@ 2009-12-14 3:52 ` Isaac Dupree
0 siblings, 0 replies; 19+ messages in thread
From: Isaac Dupree @ 2009-12-14 3:52 UTC (permalink / raw)
To: The development of GNU GRUB
Zhu Yi wrote:
> On Mon, 2009-12-14 at 11:24 +0800, Isaac Dupree wrote:
>> hmm....
>> bootloader installation is often done by distro install-CDs.
>>
>> Will the distro be smart enough to save these backups to the disk
>> somewhere sensible, rather than to the temporary in-memory
>> filesystem?
>
> The backup files will (normally) be stored in /boot/grub/ together with
> grub.cfg and core.img.
if it's there, then excellent, you are right. After all, /boot/grub
needs to be permanently on the disk in order for the installed
bootloader to work, also :-)
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-11 9:26 [PATCH] Backup old boot sectors before installation Zhu Yi
2009-12-11 9:39 ` Felix Zielcke
@ 2009-12-24 21:21 ` Robert Millan
2009-12-28 6:55 ` Zhu Yi
1 sibling, 1 reply; 19+ messages in thread
From: Robert Millan @ 2009-12-24 21:21 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: Zhu Yi
On Fri, Dec 11, 2009 at 05:26:01PM +0800, Zhu Yi wrote:
> Add a feature to backup the old boot sectors before overwritting
> them with grub2 boot and core images. Users can later recover the
> previous boot sectors with grub-install --recover option.
>
> P.S. I found this might be a useful feature after I overwrote my
> second PGP encrypted hard disk (Windows XP installed) boot sectors
> by grub2 by mistake.
I think making a backup is a fine idea, but I'd rather avoid the "option
creep". It doesn't hurt to simply dump the files in /boot/grub/. If user
later discovers that valuable data was overwritten, she can figure out
how to call dd just as she can figure out the right parameters for
grub-install.
--
Robert Millan
"Be the change you want to see in the world" -- Gandhi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-24 21:21 ` Robert Millan
@ 2009-12-28 6:55 ` Zhu Yi
2009-12-28 22:04 ` Isaac Dupree
0 siblings, 1 reply; 19+ messages in thread
From: Zhu Yi @ 2009-12-28 6:55 UTC (permalink / raw)
To: Robert Millan; +Cc: The development of GNU GRUB
On Fri, 2009-12-25 at 05:21 +0800, Robert Millan wrote:
> I think making a backup is a fine idea, but I'd rather avoid the "option
> creep". It doesn't hurt to simply dump the files in /boot/grub/. If user
> later discovers that valuable data was overwritten, she can figure out
> how to call dd just as she can figure out the right parameters for
> grub-install.
OK. My only concern is the start position of grub core.img (as in disk
sectors) is a variable (see find_usable_region_xxx). This ends up the
backup file is not a simple dump. I used below format in my patch.
<512 bytes MBR> + <U64 start position> + <sizeof(core.img) old sectors>
Option 2 is to put the start position in a separated file.
Option 3 is to use the information in boot.img (as I used in my patch as
a verification method) to get the start position, i.e. `od -j92 -N8 -An
-td8 $grubdir/boot.img`.
Option 4 is to backup everything from MBR to the end of core.img
(including the holes in the middle). This ends up with a bigger image.
Option 1~3 requires the recover has the knowledge of the backup file
format somehow, but a simple dd is enough for option 4. What do you
think?
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-28 6:55 ` Zhu Yi
@ 2009-12-28 22:04 ` Isaac Dupree
2009-12-29 3:21 ` Zhu Yi
0 siblings, 1 reply; 19+ messages in thread
From: Isaac Dupree @ 2009-12-28 22:04 UTC (permalink / raw)
To: The development of GNU GRUB
Zhu Yi wrote:
> On Fri, 2009-12-25 at 05:21 +0800, Robert Millan wrote:
>> I think making a backup is a fine idea, but I'd rather avoid the "option
>> creep". It doesn't hurt to simply dump the files in /boot/grub/. If user
>> later discovers that valuable data was overwritten, she can figure out
>> how to call dd just as she can figure out the right parameters for
>> grub-install.
>
> OK. My only concern is the start position of grub core.img (as in disk
> sectors) is a variable (see find_usable_region_xxx). This ends up the
> backup file is not a simple dump. I used below format in my patch.
>
> <512 bytes MBR> + <U64 start position> + <sizeof(core.img) old sectors>
>
> Option 2 is to put the start position in a separated file.
>
> Option 3 is to use the information in boot.img (as I used in my patch as
> a verification method) to get the start position, i.e. `od -j92 -N8 -An
> -td8 $grubdir/boot.img`.
>
> Option 4 is to backup everything from MBR to the end of core.img
> (including the holes in the middle). This ends up with a bigger image.
>
> Option 1~3 requires the recover has the knowledge of the backup file
> format somehow, but a simple dd is enough for option 4. What do you
> think?
If the partitioning had been changed in the mean time, 4 would overwrite
it with the older values. Similar problem for a weird setup with
partitions in between (I dunno, might be possible with GPT or other
weirdness).
I think option 2 or 3 is soundest. Option 2 would have three separate
files of information, (right?), and there must be a pretty
straightforwards `dd` option to skip to the correct start position.
Option 3 would omit the "start position" file... but that file is really
cheap, maybe we'd better keep things simple for restorers and stick with
three separate files.(Or, we could do something weird like putting
start-position somewhere in the filename of the backup.)
-Isaac
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-28 22:04 ` Isaac Dupree
@ 2009-12-29 3:21 ` Zhu Yi
2009-12-29 3:59 ` richardvoigt
0 siblings, 1 reply; 19+ messages in thread
From: Zhu Yi @ 2009-12-29 3:21 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: ml, rmh
On Tue, 2009-12-29 at 06:04 +0800, Isaac Dupree wrote:
> > Option 1~3 requires the recover has the knowledge of the backup file
> > format somehow, but a simple dd is enough for option 4. What do you
> > think?
>
> If the partitioning had been changed in the mean time, 4 would overwrite
> it with the older values. Similar problem for a weird setup with
> partitions in between (I dunno, might be possible with GPT or other
> weirdness).
Good point.
> I think option 2 or 3 is soundest. Option 2 would have three separate
> files of information, (right?), and there must be a pretty
> straightforwards `dd` option to skip to the correct start position.
> Option 3 would omit the "start position" file... but that file is really
> cheap, maybe we'd better keep things simple for restorers and stick with
> three separate files.(Or, we could do something weird like putting
> start-position somewhere in the filename of the backup.)
This requires the restorer to understand the role of each of the 3 (or
2) files and use `dd' twice with correct options. So an important thing
is, we need to document this somewhere. And I think the best place is to
"document" it in the grub-install script. Because this will enable the
not-so-advanced user to recover her boot sectors easily as well.
If we decide so, we go back to option 1 (my original implementation).
Because the backup file format is not important any more as it is
totally transparent to the restorers. Am I right?
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-29 3:21 ` Zhu Yi
@ 2009-12-29 3:59 ` richardvoigt
2009-12-29 7:21 ` Zhu Yi
0 siblings, 1 reply; 19+ messages in thread
From: richardvoigt @ 2009-12-29 3:59 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: ml, rmh
On Mon, Dec 28, 2009 at 9:21 PM, Zhu Yi <yi.zhu@intel.com> wrote:
> On Tue, 2009-12-29 at 06:04 +0800, Isaac Dupree wrote:
>> > Option 1~3 requires the recover has the knowledge of the backup file
>> > format somehow, but a simple dd is enough for option 4. What do you
>> > think?
>>
>> If the partitioning had been changed in the mean time, 4 would overwrite
>> it with the older values. Similar problem for a weird setup with
>> partitions in between (I dunno, might be possible with GPT or other
>> weirdness).
>
> Good point.
>
>> I think option 2 or 3 is soundest. Option 2 would have three separate
>> files of information, (right?), and there must be a pretty
>> straightforwards `dd` option to skip to the correct start position.
>> Option 3 would omit the "start position" file... but that file is really
>> cheap, maybe we'd better keep things simple for restorers and stick with
>> three separate files.(Or, we could do something weird like putting
>> start-position somewhere in the filename of the backup.)
>
> This requires the restorer to understand the role of each of the 3 (or
> 2) files and use `dd' twice with correct options. So an important thing
> is, we need to document this somewhere. And I think the best place is to
> "document" it in the grub-install script. Because this will enable the
> not-so-advanced user to recover her boot sectors easily as well.
>
> If we decide so, we go back to option 1 (my original implementation).
> Because the backup file format is not important any more as it is
> totally transparent to the restorers. Am I right?
Another option would be to start the backup file with "#!/bin/sh" ...
>
> Thanks,
> -yi
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-29 3:59 ` richardvoigt
@ 2009-12-29 7:21 ` Zhu Yi
2010-01-07 19:15 ` rmh
0 siblings, 1 reply; 19+ messages in thread
From: Zhu Yi @ 2009-12-29 7:21 UTC (permalink / raw)
To: The development of GNU GRUB
Cc: ml@isaac.cedarswampstudios.org, rmh@aybabtu.com
On Tue, 2009-12-29 at 11:59 +0800, richardvoigt@gmail.com wrote:
> > If we decide so, we go back to option 1 (my original
> implementation).
> > Because the backup file format is not important any more as it is
> > totally transparent to the restorers. Am I right?
>
> Another option would be to start the backup file with "#!/bin/sh" ...
Create this shell script in grub-setup.c? I don't see how this is less
invasive than changing grub-install script. But if everyone agree to add
the sharutils package dependency (for uuencode/uudecode), I can
implement this in V2.
Thanks,
-yi
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: [PATCH] Backup old boot sectors before installation
2009-12-29 7:21 ` Zhu Yi
@ 2010-01-07 19:15 ` rmh
0 siblings, 0 replies; 19+ messages in thread
From: rmh @ 2010-01-07 19:15 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: ml@isaac.cedarswampstudios.org
On Tue, Dec 29, 2009 at 03:21:08PM +0800, Zhu Yi wrote:
> On Tue, 2009-12-29 at 11:59 +0800, richardvoigt@gmail.com wrote:
> > > If we decide so, we go back to option 1 (my original
> > implementation).
> > > Because the backup file format is not important any more as it is
> > > totally transparent to the restorers. Am I right?
> >
> > Another option would be to start the backup file with "#!/bin/sh" ...
>
> Create this shell script in grub-setup.c? I don't see how this is less
> invasive than changing grub-install script. But if everyone agree to add
> the sharutils package dependency (for uuencode/uudecode), I can
> implement this in V2.
Erm, no, please don't do such a thing. C code is fine :-)
--
Robert Millan
"Be the change you want to see in the world" -- Gandhi
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2010-01-07 19:16 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-11 9:26 [PATCH] Backup old boot sectors before installation Zhu Yi
2009-12-11 9:39 ` Felix Zielcke
2009-12-11 22:23 ` Carles Pina i Estany
2009-12-14 2:48 ` Zhu Yi
2009-12-14 2:58 ` Isaac Dupree
2009-12-14 3:32 ` Zhu Yi
2009-12-14 2:59 ` kashyap garimella
2009-12-14 3:08 ` richardvoigt
2009-12-14 3:24 ` Isaac Dupree
2009-12-14 3:35 ` Zhu Yi
2009-12-14 3:52 ` Isaac Dupree
2009-12-14 3:15 ` Zhu Yi
2009-12-24 21:21 ` Robert Millan
2009-12-28 6:55 ` Zhu Yi
2009-12-28 22:04 ` Isaac Dupree
2009-12-29 3:21 ` Zhu Yi
2009-12-29 3:59 ` richardvoigt
2009-12-29 7:21 ` Zhu Yi
2010-01-07 19:15 ` rmh
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.