[Solved] Make Linode image bootable in VirtualBox (local PC)
error: no such partition grub rescue>
When I type 'ls' I get (hd0) (hd1) (hd2), but no partition information. And when I use 'ls (hd0)' it tells me "error: unknown filesystem."
"set root" and "set prefix" accept whatever I enter, but "insmod normal" complains "error: no such partition". (Of course, since 'ls' only sees drives without partitions.)
(hd0) [/dev/sda] has the root '/' partition (sda1 ext3) which contains the data from my linode.
(hd1) is a swap drive
(hd2) [/dev/sdc] has the /boot partition (sdc1 ext3), which has all the vmlinuz and initrd images, and a grub folder containing all the modules with a properly configured grub.cfg file. The grub file refers to the (hd0) uuid.
When I boot from a 10.04 Desktop ISO, I can read the contents of both (sda) and (sdc). To install the MBR, I've tried (after sudo su):
mount /dev/sda1 /mnt mount --bind /dev /mnt/dev mount --bind /sys /mnt/sys mount --bind /proc /mnt/proc mount /dev/sdc1 /mnt/boot chroot /mnt grub-install --root-directory=/mnt /dev/sda Installation finished. No error reported. update-grub Generating grub.cfg Found linux image: /boot/vmlinuz-2.6.32-62-generic Found initrd image: /boot/initrd.img-2.6.32-62-generic Found linux image: /boot/vmlinuz-2.6.32-38-generic Found initrd image: /boot/initrd.img-2.6.32-38-generic Found memtest86+ image: /memtest86+.bin done
While chrooted, vmlinuz and initrd.img symlinks located in '/' are correctly pointing to the /boot/xxxx-2.6.32-38-generic files.
So, everything seems normal from the above commends, yet when I boot without the LiveCD, I get the grub rescue prompt. [All the VirtualBox drives are in vdi format]
Is anyone able to shed some light as to what is going on?
Thanks in advance,
I downloaded the image in a virtual machine running U14.04. In it, I had a spare disk setup. After I downloaded the image, I then used DD to write the image to this disk.
The image had no kernel software (Linode keeps the kernel away from our access), so I've added that already. And this of course is why I'm having the above problem.
What I did:
* Using an existing VirtualBox machine with a spare drive.
I created a partition table on the spare drive and then put an ext3 partition on it. Wrote the Linode image to the first partition of the drive using DD.</list>
2. Created a new machine in VirtualBox (using a 'bridged network' interface)
Installed a fresh version of Ubuntu Server (10.04LTS in my case) with it configured it to use a separate boot partition Mounted the drive with the Linode image, from the above steps Used 'blkid' to list the UUID's of all the drives (including a SWAP drive). Edited /etc/fstab on the drive with the Linode image to mount (using UUID's) the Linode image as '/', the boot partition (from the fresh install) as '/boot' (with the boot flag set), and the swap drive Editted /boot/grub/grub.cfg where I replaced the UUID of the freshly installed '/' partition with the Linode image's UUID Installed Grub2 using 'apt-get install grub2' (not 'grub') ran 'grub-install /dev/sdc (the Linode image drive) ran 'update-grub' Shut the machine down and removed, in the VirtualBox GUI, the '/' partition of the fresh install (leaving the Linode image drive as the '/' partition) rebooted the machine (first time I did this using 'rescue mode' to enable me to discover the IP address the bridged network interface had configured) logged into the machine using PuTTY with the IP from the above step</list>
Now, optionally, I will need to upgrade the kernel.
Using an existing VirtualBox machine with a spare drive.
I created a partition table on the spare drive and then put an ext3 partition on it.
Wrote the Linode image to the first partition of the drive using DD.
The image you get from Linode does not have:
the /boot folder,
a kernel image, or
The general idea of what I figured would work was to get a fresh Ubuntu 10.04LTS VM running, and then switch the '/' partition it was using to my Linode version.
Stage 1 - Writing the Linode Image to a Drive
I used an existing VM (Ubuntu 14.04) with an extra empty drive added to in VirtualBox (VB). If you downloaded the Linode image using your host OS, you can us VB to setup the VM to share the folder where it's at.
I partitioned the empty drive using GParted.
I then used dd to write the image to it.
ls -l imagename #to get the size sudo fdisk /dev/sdX dd if=imagename of=/dev/sdXY
So now I had a drive with the Linode data on it. I could access it now, but not boot into it. I used blkid to get its UUID.
After shutting down this machine, I removed the drive with the Linode image from the VM using VB.
Stage 2 - Creating a surrogate Server
I created a new 10.04LTS server with 3 drives ( '/', '/boot', and 'swap') and made it boot from the '/boot' partition.
I needed access to the net to install Grub2 later, so I set the network settings (in VB) of this VM to use a 'bridged network' interface.
I took note of the UUID's of all 3 drives with the command blkid, as I would need to modify the /etc/fstab file later.
With the install completed, I shutdown the 10.04LTS VM.
Stage 3 - Adopting the Linode image into the surrogate
I added (in VB) the drive with the Linode image which I created earlier in the other VM to this fresh 10.04LTS VM.
I booted my fresh 10.04LTS install and after logging in, mounted the extra drive as per the above steps shown in Code in my OP. Note:: The devices referred to here might be inconsistent with what I posted later because I posted this before I got it working.
(These steps are required because you will notice that I chroot to the new '/' folder structure.)
(You will notice that the last mount command uses the '/boot' partition from the fresh install [recall I used 3 drives] and at the moment I have 4 drives attached.)
__Basically what you want to do is to mount the linode image (which is the '/' partition) as a sub-folder of the surrogate OS (which already has a '/' folder) and then make it the actual '/' folder using CHROOT. This is similar to what Jailkit does.
But because the Linode image doesn't have a '/boot' folder, you need to mount the surrogate's '/boot' folder into this. (Kind of a recursive arrangement)__
Stage 4 - Setup FSTAB and GRUB
I then edited the line in the /etc/fstab file which referred to the '/' partition.
# /etc/fstab: static file system information. # # <file system=""><mount point=""><type><options><dump><pass>proc /proc proc defaults 0 0 /dev/xvda / ext3 noatime,errors=remount-ro,usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0 0 1 /dev/xvdb none swap sw 0 0</pass></dump></options></type></mount></file>
In place of '/dev/xvda' I pasted 'UUID=xxxxxxx' where 'xxxxxxx' was the UUID of the drive with the Linode image.
The UUID is the best way to ensure which drive is allocated to what, so I think I did the same thing for the other drives.
Make sure the other UUIDs are right, and that the '/boot' partition has the 'boot' flag set.
I also had to edit the /boot/grub/grub.cfg file.
Here I replaced all UUID entries for the fresh '/' partition with the Linode UUID.
Now I needed to configure the MBR, so I installed Grub2 using 'apt-get install grub2' and
ran 'grub-install /dev/sdc' (the Linode image drive in my case).
(I'm a little sketchy on what I exactly did in Stage 4. I had tried so many variations which didn't work, and suddenly it did. AND, I haven't done it since. But the jist of what I've written worked for me. I have since rationalised things, and the FSTAB example above is how the VM is currently setup.)
Because I have password logins disabled on my server, I had to boot into rescue mode the first time to retrieve the server's IP address. After that I've been logging in using puTTY.
I hope the above helps you in some way.