2

I need to take a live USB, that has Ubuntu 12.04 and a ton of customization on it, and create a virtual machine in Virtualbox from it. I ultimately actually want to get this installation up to Google Compute Engine, but I want to start by creating a local virtual machine first (I know how to get up to Google Cloud from Virtualbox, I just can't figure out how to get from the Live USB to Virtualbox)

Note: Remastersys isn't around anymore, so that's not an option.

I have spent a significant amount of time just trying to start over and reinstall everything, but many versions of things on there I can't find anymore. It's really just one problem after another.

Please let me know if you have any questions, and thank you for your help in advance.

Note: I had exported the drive as an .img, but even after converting to an .iso, virtualbox says "no bootable drive". (Obviously there's an issue with the boot sector. I'm assuming it might not be in the right place after the conversion)

2
  • There is a iso file to boot from vm and can boot from host usb, but i forgot the iso name, you can try to search from google or wait for 6 hours I will back home and give you the iso :)
    – Bilo
    Commented Jun 27, 2015 at 5:46
  • I am guessing you might be talking about Plop? I have that, and I can "boot" from the USB, and use it as a live USB, but unfortunately, that doesn't solve my problem. I need to get this running up on Google Cloud (compute engine). I need to create a virtual machine with a "copy on write" disk type, and then do a conversion on the .vdi file. If I do that with the plop bootloader, I will just end up loading plop into Compute Engine, and not my Ubuntu installation. Thank you though, I appreciate it! Commented Jun 27, 2015 at 6:13

2 Answers 2

0

I presume you are using Linux as your main OS. Insert your USB, do not mount it, then as sudo issue the following command:

     dd if=/dev/sdb of=/path/to/my/UbuntuImage.iso

Make sure you've got the right device: I assumed sdb above, do not make a mistake, it could be dangerous.

Now create a new VirtualBox VM, with a disk which is at least as large as the iso image. Insert two disks into the new VM: an Ubuntu live image (one of those you use to install Ubuntu on pcs) and the new iso image. This will require two drives, of course.

Boot from the live Ubuntu image, not the UbuntuImage.iso we just obtained. Select Try Ubuntu without installing it, open a terminal, then issue the command:

      sudo dd if=/dev/sdc of=/dev/sda

Very Important: the above assumes that /dev/sdc is your UbuntuImage.iso and that /dev/sda is the VM's HDD. In other words, the above assumes that the live Ubuntu image from which you booted is on /dev/sdb. You will have to check that these assumptions are correct, and, if not, change the above command accordingly. Failure to do so will mean overwriting an existing device.

When this is done, chroot into /dev/sda, and adapt /etc/fstab to your new disk. It is possible you will have to change the UUID's of the disks to be mounted, and/or the swap space.

Now leave che chroot, shutdown the VM, remove the two Ubuntus from the virtual drives, boot your VM: you should be good to go. If something goes wrong, please post error messages.

EDIT

Sorry, my chroot into /dev/sda was certainly too terse. Make sure that your live distro sees the newly-minted disk as /dev/sda, then remember which partition contained, in your original USB stick, the / (root) directory, say is it N. Then:

       sudo mount /dev/sdaN /mnt
       cd /mount 
       chroot .

This should do it. Either exit or Ctrl+D will let you out of chroot.

5
  • 'do not mount it' - that might happen automatically, I then suggest to use e.g. Ubuntu disks to unmount it.
    – Hannu
    Commented Jun 27, 2015 at 7:34
  • @Hannu A simple sudo umount /dev/sdb1 (if sdb1 is mounted, otherwise adjust accordingly) will do. Commented Jun 27, 2015 at 8:14
  • to the same effect, yes.
    – Hannu
    Commented Jun 27, 2015 at 8:16
  • I have done everything successfully except for chroot into /dev/sda. "chroot /dev/sda" gives "dev/sda: Not a directory". If I try to mount it first, I get "can't find /dev/sda in /etc/fstab or /etc/mtab". These commands, are of course, being run from the bash on the live image. What am I doing wrong here? Commented Jun 28, 2015 at 8:05
  • @LenPaulsen Please see my edit. Commented Jun 28, 2015 at 8:14
1

Have you tried making VMDK file that connects to phisical usb drive? It is very simple:

VBoxManage internalcommands createrawvmdk -filename /path/to/file.vmdk -rawdisk /dev/sda

where: /dev/sda is your usb drive. Then connect this file.vmdk to your virtual machine. It will work like an alias to usb drive. For more details check: https://www.virtualbox.org/manual/ch09.html#rawdisk

2
  • I have often seen this solution mentioned around, yet I never managed to make it work for me. Commented Jun 29, 2015 at 8:00
  • @MariusMatutiae: I use this very often. I have created special linux distro for one purpose and it is live usb. When I need to make some changes I start this distro in VirtualBox using createrawvmdk. But, for my own convenience, I use /dev/disk/by-id/* instead of /dev/sd*. So every USB drive has always the same name in my system. Commented Jun 29, 2015 at 8:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .