I have an image I made of a partition with a linux install. It's just the partition, not an image of the whole disk. I have also converted the dd image to a VDI.
I can boot the VDI by using a super-grub ISO and log in to root. But when look at the lsblk output, I see that root ("/") is mounted on /dev/sda not /dev/sda1 as I would expect. So where do I tell grub-install to install grub?
[Solved] how do I install grub when root is on /dev/sda
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: how do I install grub when root is on /dev/sda
All images must be whole disk images. A partition doesn't have a partition map (required by the BIOS and GPT BIOS), it has no early boot code, and it doesn't have the additional partitions every OS requires. Sure, it has a filesystem that can be accessed in various ways, just not as the boot drive in a working PC.
Re: how do I install grub when root is on /dev/sda
Your reply led me to the answer, thanks!
First, follow the first part of this blog post: https://blog.filippo.io/converting-a-pa ... isk-image/
Then convert to a vdi:
Then create a virtualbox VM with the vdi and a super-grub iso. Use super-grub to boot the partition on the vdi. Log in to the VM as root and install grub to the MBR:
Shutdown and remove the super-grub iso. Good to go!
First, follow the first part of this blog post: https://blog.filippo.io/converting-a-pa ... isk-image/
Code: Select all
user@debian:/tmp$ dd if=/dev/zero of=whole_disk.img count=1 bs=1MiB
user@debian:/tmp$ pv partition.img >> whole_disk.img
user@debian:/tmp$ fdisk whole_disk.img
user@debian:/tmp$ # n p 1 a w
Code: Select all
user@debian:/tmp$ vboxmanage convertfromraw whole_disk.img whole_disk.vdi --format VDI
Code: Select all
root@vm_machine:~$ grub-install
-
- Site Moderator
- Posts: 39134
- Joined: 4. Sep 2008, 17:09
- Primary OS: MS Windows 10
- VBox Version: PUEL
- Guest OSses: Mostly XP
Re: how do I install grub when root is on /dev/sda
Well done for solving the problem.
The only thing missing from the blog: most Linux drives IME also have a swap partition. It usually follows the user volume though IMHO it makes much more sense to have it before (that way the user volume can be enlarged and shrunk as it is moved to new drives, without that damn swap partition getting in the way).
Otherwise the blog was interesting. I had no idea that Linux (or just Debian?) fdisk allows you to partition an image file without having to mount it as a virtual drive.
The only thing missing from the blog: most Linux drives IME also have a swap partition. It usually follows the user volume though IMHO it makes much more sense to have it before (that way the user volume can be enlarged and shrunk as it is moved to new drives, without that damn swap partition getting in the way).
Otherwise the blog was interesting. I had no idea that Linux (or just Debian?) fdisk allows you to partition an image file without having to mount it as a virtual drive.