(Virtual HDDs/VirtualBox) I messed up the /dev/sdX of my Linux virtual drive; how do I fix it?

07
2014-07
  • user3758800

    I'm having a bit of trouble porting my Linux physical partition to a VDI for running it in VirtualBox. First of all, Linux Mint Petra was on the same HDD as my Windows 7 and I was able to dual-boot fine. But then I wanted to port the Linux partition to a virtual drive.

    I tried resizing it using EaseUS before porting, which is probably what messed some settings, I would suspect. However I successfully performed a backup of the partition using EaseUS (PBD file); converted it to a VHD file and finally, converted the VHD file to VDI.

    Now, when I try booting from the VDI/VHD, I get an error: Missing operating system. FATAL: INT18: BOOT FAILURE.

    When I boot from Linux ISO I see this in the partition section:

    enter image description here

    As you can see, there are two devices there: sda1 and sda5; the latter seems to be overlapping the former, which shouldn't be the case. I can confirm that /dev/sda5 was the correct physical partition when dual-booting.

    I tried repairing things using Boot Repair Disk, but to no avail.

    How do I ensure that VirtualBox successfully locates the OS device/partition and fix the /dev/sdXY overlap?

    Cheers

  • Answers
  • user3758800

    Ok so I figured it out with some help from a friend. At the time of my issue I had the physical partition in a 50gig VDI file, which was not booting due to the error mentioned in the OP. The used space on the drive was 20gig, which included my Linux install + my files. I managed to not only boot it up again, but resize the 50gig partition to 20gig in a new dynamically allocated VDI drive.

    To fix, I created a brand new VM (let's call it hurrdurr) with dynamically allocated drive of max size 35gig and I proceeded to load Linux Mint from the install ISO. I loaded up Gparted using superuser (sudo gparted) and proceeded to do the following:

    • Created 512MB ext2 partition with label "boot"
    • Created 8192MB swap partition with label "hurrswap"
    • Created 28gig ext4 partition using the remainder of the space with label "derp"

    Then, I installed Linux Mint on the virtual drive. When it asks what you want to do, eg Erase disk and install Mint/Ubuntu (this will wipe the drive)/install alongside /Something else, choose something else. It will load up a Gparted-style section where you get to see the partitions of your drive. I double clicked the "boot" partition, checked the Format box and made sure the mount point was /boot. Then for the swap area I just left it the way it was (note, I chose to have an 8gig swap area because I has 8gig of rams on this machine and it's usually good to have the swap size equivalent to your installed ram) and for my ext4 partition, I made sure the format box was checked and the mount point was "/".

    I installed Mint and this effectively configured the boot and the GRUB and the everything for me. Now it was time to overwrite the fresh install with my old one, because this way GRUB will know where to look to boot! So now, in a separate VM I configured VirtualBox to use the two virtual drives; the big 50gig partition and the fresh-install dynamically allocated one. I did this by going into Settings -> Storage -> Controller - IDE -> Add Hard Disk. This allowed me to select the two other VDI files. Then I booted into this separate install.

    Using sudo fdisk -l I could tell which /dev/sdWX and /dev/sdYZ to load in order to mount the fresh "derp" partition and the partition I wanted to copy over respectively. I used sudo mount /dev/sda5 /mnt/drv1 (I mkdir'd the drv1 befhorehand) and sudo mount /dev/sdb3 /mnt/drv2 (the "derp" partition). Now, here you can copy stuff over in two ways: One is with dd, which completely clones your partition with empty space. But I used the simple copy command cp to transfer my desired data + Linux from the 50gig partition. The command I used was sudo cp -a /mnt/drv1/* /mnt/drv2/ the -a is to tell cp to transfer all the files with all attributes intact. Once that transfer was done, I just booted in my hurrdurr VM and voila - GRUB successfully booted from that partition that I wanted to recover! Not just that, but because it's a dynamic drive, it's only 20gig as well.

    So in essence (tl;dr if I may):

    • Create new VM with correctly assigned partitions
    • Install the OS that was on the damaged drive
    • Boot up a VM which has access to both the damaged virtual drive and the new fresh install one
    • Mount the damaged and the fresh partitions
    • sudo cp -a the files over to the fresh install
    • Done.

    I hope this helps someone like me out there.

    Cheers


  • Related Question

    linux - How can I identify which device caused a `/dev` entry?
  • Questioner

    I have a Dell Inspiron 600M, from around 2004. The partition table looks like this:

       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1           6       48163+  de  Dell Utility
    /dev/sda2   *           7        3478    27888840    7  HPFS/NTFS
    /dev/sda3            3479        6838    26984449    5  Extended
    /dev/sda4            6839        7295     3670852+  db  CP/M / CTOS / ...
    /dev/sda5            3479        6694    25824256   83  Linux
    /dev/sda6            6694        6838     1159168   82  Linux swap / Solaris
    

    Does anyone know what sda1 and sda4 are for? I did not create them, so I imagine Dell installed them when the machine was built.


  • Related Answers
  • Journeyman Geek

    SDA1 is your restore partition - from which you can restore your system to a factory fresh state. I have no idea about SDA5 - it seems an odd filetype and might also be system utilities of some sort. Its an unusual location for it, since most partitions of the sort are before the main partition with the OS.