Cloning a VirtualBox openSUSE image

I recently tried to clone an openSUSE VirtualBox image. I thought it would be as simple as just copying the virtual disk image (vdi) file and create a new virtual machine based on it. So that’s what i did. But when i tried to couple the new hard disk file to the virtual machine VirtualBox gave me the following error:

Apparently a new virtual disk image in VirtualBox needs a unique identifier key. So after some research i found out it’s possible to make a clone of a hard disk that has a different unique identifier. But unfortunately that’s not all of the story. You have to make some additional changes to the clone to make it all work. So here are the steps you need to follow to make a successful clone.

1. Clone the hard disk

To clone the hard disk open a terminal window and issue the following command:

VBoxManage clonevdi <original>.vdi <clone>.vdi

2. Create a new Virtual Machine

Now create a new virtual machine with basically the same settings as the original virtual machine and couple it to the new cloned virtual disk image. As this image has been given a new unique identifier, you should have no problem registering it now.

3. Alter the hard disk identifiers

Having cloned the virtual disk image, i thought i was ready to roll. But on startup i encountered the following problem:

Apparently part of the UUID of the virtual disk image is used to identify the hard disk on startup. We have to change these references to their appropriate new ids.

3a. Startup in rescue mode

To startup the openSUSE vm in rescue mode insert the iso file you used for installation in the CD Drive of the vm. Upon startup select the Rescue System option from the menu.

3b. Mount the hard disk

Login as root and mount the hard disk (on my system this was /dev/sda2, this could be different on your system) via the following command:

mount /dev/sda2 /mnt

3c. Alter the identifiers

Now first find out what the new identifier of the hard disks should be. Issue the following command

hdparm -i /dev/sda

Note the identifier called SerialNo. This is the one you need. On my system it was VBa79c17fb-f28bb7c1.
Now there are 2 files you need to alter. First edit the file /mnt/etc/fstab and alter all the identifiers between /dev/disk/by-id/ata-VBOX_HARDDISK_ and -partx with the new identifier.
Next make corresponding changes to the file /mnt/boot/grub/menu.lst.
After this you can reboot the system

shutdown now -r

4. Repair your network settings

If you made no typos, openSUSE should start up with no problems. There’s one piece of configuration to do though. The clone has messed up the network configuration. This can be easily repaired via the YaST GUI tool. Open it and select Network Devices > Network Settings. You should see 2 Ethernet Controllers. One of them is not configured. Configure this controller with default settings and delete the other one. Now your clone is ready for use.


About Roger Goossens
I'm an integration consultant with a strong affiliation for JEE and open source development.

9 Responses to Cloning a VirtualBox openSUSE image

  1. Steve says:

    This is good, but I use VirtualBox to teach networking to students. This workaround is messy. Any chance that a fix will be forthcomming?

    • Hey Steve, i agree that it’s a messy way to make a virtual box clone, but i don’t think that this qualifies as a bug so a “fix” won’t be forthcoming. It’s just the way open-suse works. I’m pretty sure though that cloning an image of another linux distribution, eg. ubuntu, is a lot easier and doesn’t involve the altering of the hard disk identifiers, which is the most error prone step here.

  2. S. Whitmore says:

    Very useful! It would be great if the virtual machine clone process in VirtualBox could handle this automatically, but that might be asking a bit much (and do we really want VirtualBox touching our fstab files?). I’ve added a link to this page from the “technical fixes” section of my site.

  3. Basic says:

    Thank you for that! It just saved a lot of time. Cloning ubuntu btw is a lot easier 🙂

  4. Ash says:

    BRAVO SIR! This is a great doc, and is something I have been trying to figure out for a while. I did not do the CLI clone process, but the GUI clone function. I was able to follow this guide,and with the exception of having to learn VI on the fly, it went very well. You are a gentleman and a scholar!

  5. The Learner says:

    This procedure no longer work with Suse12.2 because /mnt/boot/grub/menu.lst disappeared with the adoption of GRUB2.
    Solution is to make a clone by VirtualBox, which will slowly boot to a terminal because of the wrong VBdisk number.
    Once there, it suffice to enter ROOT passwod followed by STARTX to access the newly created VBclone in a graphical mode.
    Following than your instructions in 3b & 3c easely solve the problem but the requested changes must be made in /boot/grub2/ since /mnt/boot/grub/menu.lst no longer exists.
    I sincerely appreciated your very unique solution to solve this problem and without which I would probably be still scratching my head.

  6. The Learner says:

    oups… I forgot to mention that the ROOT password used is the one from the VirtualBox guest used to make the clone.

  7. Pingback: VirtualBox Cloning of SUSE Hard Disk UUID Problem | scoder

  8. sancelot says:

    you have to remove uuid dependency, in this case you will not have any problems cloning.

    Some linux understanding skills are mandatory. or you will not being able to reboot if you made an error.

    this works for opensuse 13.2 :

    edit /etc/default/grub and add :

    modify GRUB_CMD_LINE_DEFAULT (that may depends on your setup) :
    GRUB_CMD_LINE_DEFAULT=”root=/dev/sda1 disk=/dev/sda ….”

    edit /etc/fstab, replace all /dev/disk/by-uuid lines with corresponding physic /dev/sda partitions , eg for / :

    /dev/sda1 / ext4 acl 1 1

    update grub launching :
    grub2-mkconfig -o /boot/grub2/grub.cfg

    if everything goes well, you should being able to reboot with any problems.

    Then you can clone this machine many times without any problems

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: