Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1NSRuN-00005p-UO for mharc-grub-devel@gnu.org; Wed, 06 Jan 2010 04:10:27 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NSRuM-0008W7-88 for grub-devel@gnu.org; Wed, 06 Jan 2010 04:10:26 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NSRuH-0008Se-IN for grub-devel@gnu.org; Wed, 06 Jan 2010 04:10:25 -0500 Received: from [199.232.76.173] (port=37111 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NSRuH-0008ST-BI for grub-devel@gnu.org; Wed, 06 Jan 2010 04:10:21 -0500 Received: from mga11.intel.com ([192.55.52.93]:50526) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NSRuG-0003qo-Vm for grub-devel@gnu.org; Wed, 06 Jan 2010 04:10:21 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP; 06 Jan 2010 01:09:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.49,226,1262592000"; d="scan'208";a="761748866" Received: from debian.sh.intel.com (HELO localhost.localdomain) ([10.239.13.65]) by fmsmga001.fm.intel.com with ESMTP; 06 Jan 2010 01:10:10 -0800 From: Zhu Yi To: rmh@aybabtu.com Date: Wed, 6 Jan 2010 17:10:04 +0800 Message-Id: <1262769004-21960-2-git-send-email-yi.zhu@intel.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1262769004-21960-1-git-send-email-yi.zhu@intel.com> References: <1262769004-21960-1-git-send-email-yi.zhu@intel.com> X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: grub-devel@gnu.org, Zhu Yi , Zhu Yi Subject: [PATCH 2/2] Add grub-install --restore option X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Jan 2010 09:10:26 -0000 From: Zhu Yi Add the --restore option to restore the previous boot sectors from a backup image (created by grub-setup). A simple `dd` won't work when partitioning has been changed after the backup. In this case, a script is useful as it only restores the MBR and the boot sectors overwritten by core.img (embed region is excluded) to the install device. So this method is recommended even for advanced users. Signed-off-by: Zhu Yi --- util/i386/pc/grub-install.in | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) diff --git a/util/i386/pc/grub-install.in b/util/i386/pc/grub-install.in index 8a06213..4d0043e 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 +restore= 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 + --restore restore the previous boot sectors EOF if [ "${target_cpu}-${platform}" = "i386-pc" ] ; then cat <&2 usage @@ -203,6 +209,29 @@ else exit 1 fi +if test -f "$restore"; then + if test `stat -c%s $restore` -eq 512; then + dd if=$restore of=$install_device bs=512 count=1 + exit 0 + fi + start=`od -j92 -N8 -An -td8 $grubdir/boot.img` + + # Synaty check + if test $((`stat -c%s $restore` - $start * 512)) -ne \ + `stat -c%s $grubdir/core.img`; then + echo "Error: $restore doesn't match core.img, restore aborted." + exit 1 + fi + + # Restore + dd if=$restore of=$install_device bs=512 count=1 > /dev/null 2>&1 + dd if=$restore of=$install_device skip=512 seek=`expr $start \* 512` \ + bs=1 > /dev/null 2>&1 + rm -f $restore + echo "Restore boot sectors from $restore 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 -- 1.5.3.6