31

I'm running Ubuntu Desktop 12.04, and I was wondering if it was possible to somehow take my whole filesystem (everything under /) and create an ISO from it. Then, perhaps, use that ISO as the file system of a VBox VM (obviously, it would have to be Ubuntu, and probably 12.04).

Basically, I've spent a lot of time configuring my development machine, but need to be able to work on it from whatever computer I happen to be at. VMs seem like the perfect solution. Thanks in advance!

3

7 Answers 7

13

It'd probably be easier to create a fresh VM, install Ubuntu on it, and then back up your dev box and restore the backup to the VM. That'd give you a VM you could run on any machine where VirtualBox is, or could be, installed.

That said, is there a reason you couldn't just open up VNC or SSH access to your existing dev box, and access it remotely? If possible, that might well be a simpler option -- at the least, it'd save you some suffering every time you want to use the dev box from a new machine.

Hope this helps!

3
  • Thanks @Aaron Miller (+1) - what backup tool might you recommend, and how does it work? Does it back my entire PC into some file that can then be used to overwrite the entire file system on the VM? Thanks again!
    – pnongrata
    Commented Oct 1, 2012 at 16:46
  • 1
    Glad to be of help! As for a backup tool -- man tar is what I'd recommend here; it's not the most welcoming interface, perhaps, but if you just tar up / on the dev box (making sure to avoid /proc, /sys, /dev, and /root via the --exclude option) and untar the result on your VM, you'll probably have about what you need. (I would, though, think hard in your shoes about whether it's possible to just bring across the development stuff without touching the rest -- perhaps copy /home/username across and do the rest via apt, for example. Always best to do the least amount of work necessary, I say.) Commented Oct 1, 2012 at 17:46
  • 2
    Though very informative and helpful, this suggestion should be a comment and not an answer. It does not answer the question.
    – dotancohen
    Commented Oct 2, 2012 at 6:13
28

you can dump your hd into an image with dd then convert the image to a vmdk or whatever.

apt-get install qemu (installs QEMU on debian/ubuntu)

qemu-img convert imagefile.dd -O vmdk vmdkname.vmdk

taken from: here

4
  • I don't know for sure if this will work but +1 and I'm going to try.
    – Mikey
    Commented Oct 1, 2012 at 18:27
  • 1
    You can also use the image in VirtualBox. Ubuntu normally installs drivers for various hardware (unlike Windows), making it more portable, so this will generally work. Commented Oct 1, 2012 at 19:51
  • 2
    This will not just work. The file /etc/fstab is the file your system reads to know what disks mount where. The disks are stored by a uuid, and when you make a new disk this won't be the same. You will need to edit this file on the new system to fix that. Also network cards will be renamed (that would happen anyways.) Commented Oct 1, 2012 at 20:51
  • Also to make the image, you should run a live cd with the disk not mounted. Store the image on another disk.
    – nikhil
    Commented Oct 5, 2012 at 16:09
10

I did this previously on a Windows XP machine, but I guess you can do it in Ubuntu as well. But it uses vmware, not virtualbox...

Install vmware-converter (free product) in your Ubuntu box. Then convert the physical system to a virtual system, after tweaking configuration settings.

After this, you have you virtualized image that can be 'played' with vmplayer.

2
  • 1
    VirtualBox will be able to use VMDKs created in this way.
    – bfhd
    Commented Oct 1, 2012 at 22:10
  • Doesn't work that well, you need a vmware server on your network to which it exports the image. I had no luck with it.
    – nikhil
    Commented Oct 5, 2012 at 16:10
5

Another option might be to clone your OS into a VirtualBox disk image:

vboxmanage createhd --filename foo.vdi --size 10240

modprobe nbd max_part=16
qemu-nbd -c /dev/nbd0 foo.vdi

# create a partition (will automatically produce a new device /dev/nbd0p1)
sfdisk -D /dev/nbd0 <<EOF
,,L,
EOF

mkfs -t ext2 /dev/nbd0p1
mount -o loop /dev/nbd0p1 /mnt

# clone your OS
rsync -aH --exclude mnt --exclude dev --exclude proc --exclude sys / /mnt/

# install the boot loader on the virtual disk
mount --bind /dev /mnt/dev
chroot /mnt grub-install /dev/sda

umount /mnt
qemu-nbd -d /dev/nbd0

rmmod nbd
4

So there are one of two ways to do this. To make an ISO directly you should use Remastersys. This is a tool that will allow you to create an ISO of the current system. You can then boot off the ISO and get that enviornemtn as a LiveCD. A good guide can be found here.

If you want to make a VHD (virtual hard disk) from the physical disk, they only tool I know of would be disk2VHD. That is a Windows only tool. However, you can also use the Linux tool dd. There is a good tutorial for this found here.

4

Copied from (http://karim-ouda.blogspot.com/2011/11/how-to-create-virtualbox-image-from.html)

sudo dd if=DRIVE | VBoxManage convertfromraw stdin FILENAME BYTES

Real Example

sudo dd if=/dev/sda | VBoxManage convertfromraw stdin MyLinuxImage.vdi 120034123776

Notes:

  1. To get the number of bytes in partition, you can use the following command sudo fdisk -l /dev/sda

  2. You need to use /dev/xxx not /dev/xxx1 or xxx2 so that the image contains MBR records

0

To start you can create a disk image using the partimage utility in a command line interface. After this I imagine you would be able to boot the newly create iso with VMware.

Using Partimage If you are using Ubuntu 12.04 or even 11.04, Partimage should be available from the Ubuntu software center. This installation method will allow you to easily search and install your selected software.

Step 1. Open the Ubuntu Software Center and locate the search bar in the top right hand corner of the window. Type "partimage" in the search bar then press enter. The partimage software package will be the first to display. Also returned from this search are partclone (utility to clone and restore a partition), partimage-server (use partimage across a network), and partimage-doc (partition image user documentation). You will want to click install and let the software center install the package for you.

Step 2. Open Terminal and enter the following command " sudo partimage", then enter your password and press enter.

Step 3. After entering your password the Partimage application should display in the Terminal window.

Step 4. Understanding the available options.

* Partition to save/restore -  A list of all available partitions on all drives able to be backed up from or restored to. You may only choose to operate on one partition at a time. 
* Image file to create/use - If creating a new image file enter the path and file name where the created back up will be written. If using an image file to restore a partition or drive enter the path to the mounted drive where the file is located. 
Action to be done: 
    (*) Save partition into a new image file - Choosing this option will tell Partition Image to create a backup .img file from the partition selected in "Partition to save/restore", and write the file to the path entered in "Image file to create/use."
    (  ) Restore partition from an image file - This option will write the image file from the path entered under "Image file to create/use", and write it to the partition and/or drive selected under "Partition to save/restore."
    (   ) Restore an MBR from the image file - This will restore the MBR to the drive selected under "Partition to save/restore" to the image file contained in the path under "Image file to create/use."
[  ] Connect to server - This option will allow you to connect to a remote server to read or write an image file.

Step 5. This screen is fairly self explanatory. You will first want to select the desired compression level if any. You may also change how the image will be split during the writing process. The default mode is to create a 2Gb files. The final option gives Part Image instructions on what to do if it finishes the job succesfully. Choose which ever option is most appropriate for your situation.

http://www.ubuntulinuxguide.com

1
  • Have you tried your solution?
    – user66001
    Commented Nov 11, 2015 at 15:22

You must log in to answer this question.

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