Page 1 of 1

SOLVED Restored USB Key Not Booting

Posted: Sat Feb 22, 2014 12:10 am
by kbocek
So my plan was to use fsarchiver to back up a single linux file system containing the whole OS. I could then restore the OS to a new device and just restore the boot sector. As a test, I've installed CentOS 6 to a USB key. Boots and works fine. Single primary partition. Backed up using fsarchiver just fine. Save the first 466 bytes of the key which is the boot sector minus the partition table.

Took a new key. Created new partition with fdisk. Boot to systemrescuecd which includes fsarchiver. Restore of OS file system goes fine. No errors.

So I first try restoring the boot sector file with:

Code: Select all

$ dd if=bootsect466.bin of=/dev/sda bs=466 count=1
Key does *not* boot. I try marking partition bootable. Key still does not boot.

So I try the long way around installing the boot loader on another running system with the grub shell:

Code: Select all

$ grub --device-map=/dev/null
> device (hd0) /dev/sdd
> root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
> setup (hd0,0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
 Running "embed /boot/grub/e2fs_stage1_5 (hd0,0)"... failed (this is not fatal)
 Running "install /boot/grub/stage1 (hd0,0) /boot/grub/stage2 p /boot/grub/grub.conf "... succeeded
And the key still refuses to boot. At this point I am out of ideas. Does anyone have any ideas how to restore a root file system to a new device and reinstall the boot sector? The fsarchiver docs say use grub. I thought that's what I did.

SOLVED Restored USB Key Not Booting

Posted: Sat Feb 22, 2014 7:49 pm
by kbocek
After pondering this for a bit, I realized my error was in my command "setup (hd0,0)":

Code: Select all

$grub --device-map=/dev/null
grub> device (hd0) /dev/sdd
device (hd0) /dev/sdd
grub> root (hd0,0)
root (hd0,0)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)
setup (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"...  27 sectors are embedded.
succeeded
 Running "install /boot/grub/stage1 (hd0) (hd0)1+27 p (hd0,0)/boot/grub/stage2 /boot/grub/grub.conf"... succeeded
Done.
"setup (hd0,0)" installed the stage1 bootloader to the beginning of the first partition and *not* the beginning of the drive. Giving the command "setup (hd0)" installed the stage1 bootloader correctly. The USB key now boots correctly.

Re: SOLVED Restored USB Key Not Booting

Posted: Sun Feb 23, 2014 1:09 am
by kbocek
As a followup to my first post, my note about using dd to install the boot sector:

Code: Select all

$ dd if=bootsect466.bin of=/dev/sda bs=466 count=1
Was a mistake. First it was missing installing the stage 1.5 boot loader. I experimented with also using dd to copy the e2fs_stage1_5 file to the disk starting at block 1. But that too didn't result in a bootable key.

This was all because I was terrified of grub and it's unusual (hdx,x) nomenclature. But after learning how to force it to connect to my USB drives and going through this process several times I'm a lot more comfortable with it.

Use grub. It's the way to go.