LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-12-2014, 05:15 AM   #1
mzzxx11
Member
 
Registered: Sep 2012
Posts: 78

Rep: Reputation: Disabled
Recovering the bootloader after reinstalling Windows 7 (debian stable)


I have a dual boot machine (Windows 7 and Debian).
W7 and debian are on the same HD but on diffferent partitions.
The debian partition is an LVM encrypted one.

The W7 needs reinstalling, and as I understand the process will overwrite the debian bootloader (grub).

Question: Is there a way to save the current bootloader and recover it after I've reinstalled W7, so I wont have to reinstall debian from scratch?.
I plan to re-install W7 on the same partition it is now, without overwriting the debian partition.

Thanks
 
Old 10-12-2014, 06:17 AM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by mzzxx11 View Post
I have a dual boot machine (Windows 7 and Debian).
W7 and debian are on the same HD but on diffferent partitions.
The debian partition is an LVM encrypted one.

The W7 needs reinstalling, and as I understand the process will overwrite the debian bootloader (grub).

Question: Is there a way to save the current bootloader and recover it after I've reinstalled W7, so I wont have to reinstall debian from scratch?.
yes, there is. You could just allow the Windows installer to overwrite your current bootloader, then, later, boot a Live Linux and just re-install GRUB from that live system.

If you want to do it the hard way, that's possible as well. But still, low-level work on the HDD always poses the risk of an accident, and so I strongly recommend to have a full backup before you start, just in case something happens!

USE AT YOR OWN RISK!

I assume you're using GRUB as a bootloader. GRUB is typically installed as two parts. One part occupies the MBR and a few of the following sectors before the beginning of the first partition, the other part is in /boot/grub of the Linux partition (or maybe in an extra partition that is mounted to /boot). During re-installation of Windows, the GRUB part inside the Linux partition remains unchanged, of course. So it should be sufficient to back up the sectors preceding the first partition and restore them later.
You have a Linux live system ready that you can boot off a CD or USB pen drive? Good.

Here's how I would do it.
  • From inside Linux (the currently installed system will be fine) issue the command
    Code:
    sudo fdisk -l
  • Note the starting sector of the first partition (/dev/sda1). On my system, it's 2048, but it may be different on yours, especially when your partitions are not aligned to 1MB-boundaries.
  • Run the following command, replacing <number> with the number you noted before.
    Code:
    sudo dd if=/dev/sda of=grub.bin bs=512 count=<number>
    Be aware that it's /dev/sda here, not sda1!!
  • Copy the file to an external media.

That's the preliminaries. Now you can re-install Windows, which will flatten the existing GRUB and replace it with its own bootloader. Once Windows is running again, ...
  • Boot your Live Linux from CD or USB, and have the previously saved grub.bin file ready
  • Issue the following command:
    Code:
    sudo dd if=grub.bin of=/dev/sda bs=512 count=<number>
    Again, make sure you don't write sda1, it's just sda.
  • Reboot your system. It should come up with the boot configuration exactly as it was before.

Again: That's pure theory, I haven't tested the procedure. Don't try it without having a verified backup for disaster recovery, just in case.

Quote:
Originally Posted by mzzxx11 View Post
I plan to re-install W7
Why are you going to do that in the first place? Are you experiencing trouble with your Windows installation?
If I were in your shoes, I'd rather try a system restore from inside Windows, or restore Windows from a previous known-good backup.

[X] Doc CPU
 
Old 10-12-2014, 06:46 AM   #3
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
Just in case you need to mount with live-cd, I would say practice this
http://ubuntuforums.org/showthread.php?t=940904
& chrooting
http://www.linuxquestions.org/questi...el-4175437864/
 
Old 10-12-2014, 07:14 AM   #4
mzzxx11
Member
 
Registered: Sep 2012
Posts: 78

Original Poster
Rep: Reputation: Disabled
Tnx for the reply.

DocCPU: what is the step-by-step procedure for easy option?

Say I've reinstalled W7 & it overwritten the boot sector. Now what?
 
Old 10-12-2014, 07:24 AM   #5
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by mzzxx11 View Post
DocCPU: what is the step-by-step procedure for easy option?

Say I've reinstalled W7 & it overwritten the boot sector. Now what?
Try a Google search. The procedure is described on many sites on the internet. For example:

http://ubuntuguide.net/how-to-restor...ws-xpvistawin7
http://community.linuxmint.com/tutorial/view/245
http://howtoubuntu.org/how-to-repair...ubuntu-live-cd

Though these tutorials specifically refer to Ubuntu or Linux Mint here and there, the procedure is the same for their ancestor Debian. Actually, for any distro using GRUB.

[X] Doc CPU
 
Old 10-12-2014, 07:54 AM   #6
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
If you get network running on live-cd right before chroot command you need to copy /etc/resolv.conf
Quote:
cp /etc/resolv.conf /mnt/debian/etc/resolv.conf
The live-cd has to be the same architecture as OS.

Last edited by EDDY1; 10-12-2014 at 07:56 AM.
 
Old 10-13-2014, 06:59 AM   #7
mzzxx11
Member
 
Registered: Sep 2012
Posts: 78

Original Poster
Rep: Reputation: Disabled
my current partitions are:

Code:
fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00077703

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   314574847   157286400    7  HPFS/NTFS/exFAT
/dev/sda2       314574848   324339711     4882432    b  W95 FAT32
/dev/sda3       324339712   325316607      488448   83  Linux
/dev/sda4       325316608   976771071   325727232   83  Linux

Disk /dev/mapper/sda4_crypt: 333.5 GB, 333542588416 bytes
255 heads, 63 sectors/track, 40550 cylinders, total 651450368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/sda4_crypt doesn't contain a valid partition table

Disk /dev/mapper/linuxroot: 20.0 GB, 19998441472 bytes
255 heads, 63 sectors/track, 2431 cylinders, total 39059456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/linuxroot doesn't contain a valid partition table

Disk /dev/mapper/linuxswap: 4999 MB, 4999610368 bytes
255 heads, 63 sectors/track, 607 cylinders, total 9764864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/linuxswap doesn't contain a valid partition table

Disk /dev/mapper/linuxhome: 308.5 GB, 308541390848 bytes
255 heads, 63 sectors/track, 37511 cylinders, total 602619904 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/linuxhome doesn't contain a valid partition table
what do I need to do after re-installing W7 to recover these?
The linux partitions are encrypted (LUKS)

tnx
 
Old 10-13-2014, 10:39 AM   #8
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
See post #3
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recovering root password in debian with grub bootloader JSR_tuxbox Linux - Newbie 4 12-09-2007 12:23 AM
reinstalling windows 98 with debian + lilo scroft Linux - Newbie 6 02-15-2007 05:10 PM
help with recovering bootloader... m_a_b Linux - General 12 01-17-2006 07:16 AM
Reinstalling the bootloader evilmonkey Linux - Software 2 12-10-2004 01:13 PM
reinstalling lilo bootloader free kevin Linux - Newbie 5 08-02-2004 04:14 PM


All times are GMT -5. The time now is 10:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration