You are not logged in.

#1 2012-07-08 16:04:02

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

GRUB2 install from a chroot environment and a loop device

I created a 10 GB raw .img, formatted it as EXT4 and "rsync'd" my system inside. The plan is to reinstall GRUB2 to its MBR and convert it to .vdi (VirtualBox). I know how to do all that, it's not as difficult as it sounds.

sudo modprobe loop
sudo losetup /dev/loop5 /media/Backup/backup.img
sudo mount -o offset=$((2048 * 512)) /dev/loop5 /mnt
cd /mnt
for i in /proc /sys /dev; do sudo mount -B $i .$i; done
sudo chroot .
sudo grub-install /dev/loop5
sudo grub-mkconfig -o /boot/grub/grub.cfg

(Interesting way to chroot, right?)

...except after converting the .img to .vdi (VBoxManage convertfromraw --format VDI /path/to/backup.img /path/to/backup.vdi), I'm getting:

GRUB loading.
Welcome to GRUB!

error: no such device: 557e19c8-e89b-4661-a1dc-2a3ce3b2064e
Entering rescue mode...
grub rescue> _

However, reinstalling it by hooking up a LiveCD to the VM works:

mount /dev/sda1 /mnt
cd /mnt
for i in /proc /sys /dev; do mount -B $i .$i; done
chroot .
grub-install /dev/sda
grub-mkconfig -o /boot/grub/grub.cfg

It seems to like /dev/sda more than /dev/loop5.

Why is that?


I should mention that the VM's UUID for /dev/sda is the same as /dev/loop5 on the computer.

Last edited by DSpider (2012-07-08 16:14:06)


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

#2 2012-11-19 18:43:41

hiob
Member
Registered: 2007-12-15
Posts: 19

Re: GRUB2 install from a chroot environment and a loop device

*bump* I know this thread is older then old, but I have exactly the same problem. It seems that there used to be a workaround (http://superuser.com/questions/130955/h … n-img-file) which has no effect anymore.
The reason I need to do it with loop is, that I'm writing a script for automated virtual-disk creation. So booting a live system is not an option.

Help anybody?

Offline

#3 2012-11-19 18:52:50

DSpider
Member
From: Romania
Registered: 2009-08-23
Posts: 2,273

Re: GRUB2 install from a chroot environment and a loop device

My advice is to use SYSLINUX instead of GRUB.

cd /mnt/Virtual
for i in /proc /sys /dev; do sudo mount -B $i .$i; done
sudo chroot .
sudo extlinux --install /boot/syslinux
sudo dd bs=440 conv=notrunc count=1 if=/usr/lib/syslinux/mbr.bin of=/dev/loop5
exit
sudo umount {proc,sys,dev,}

Don't forget to set the boot flag from gparted, or whatever you used to format the loopback device.


"How to Succeed with Linux"

I have made a personal commitment not to reply in topics that start with a lowercase letter. Proper grammar and punctuation is a sign of respect, and if you do not show any, you will NOT receive any help (at least not from me).

Offline

Board footer

Powered by FluxBB