Friday, December 11, 2009

Cloning openSUSE VirtualBox Machines

... or "Waiting for device /dev/disk/by-ID/... to appear." problem

A guess many people have figured this out by now, but i still know a lot who have not, so here it goes.

There are a few caveats in cloning openSUSE or SLE VirtualBox machines. One is that openSUSE uses device ID in /etc/fstab and grub's menu.lst to reference your hard disk partitions. This is cool for physical machines, since no matter what the usual device name of your hard disk is (/dev/sda, sdb, hda, ...), the device ID always stays the same. When cloning the VirtualBox hard disk image, however, the device ID changes. This consequently causes a problem when booting your new machine with cloned image.

Another one concerns the network card's udev rules, which affect the device names. These are set to use MAC address to identify the card, which also changes when creating new virtual machine (new random MAC address is generated). After booting the cloned machine with this new network card, the original one becomes eth1, and the new one is not configured; you need to configure it, e.g. using YaST. Thanx to Mišo Žugec for this tip.

To avoid these problems, after installing a fresh openSUSE or SLE which i want to use for cloning, i change its /etc/fstab and /boot/grub/menu.lst to use the usual device files, and change the network card's udev rules from MAC to BusID. So, in nutshell, the cloning process looks like this:
  1. Boot the virtual machine you want to use as base for cloning.
  2. Replace the /dev/disk/by-id/...-partY with /dev/sdXY in /etc/fstab and /boot/grub/menu.lst.
  3. In YaST Network module, click Edit to edit the network card, open the Hardware tab, click Change in the Udev rules frame and select BusID instead of MAC address.
  4. Shut the machine down (from within the machine itself, not using VirtualBox's power off).
  5. Find the machine's .vdi hard disk file (usually under ~/.VirtualBox/ dir) and use VBoxManage clonevdi command to clone it, for example:
    (~/.VirtualBox/HardDisks)$ VBoxManage clonevdi my-perfect-oS11.2-base.vdi oS11.2-some-experiment.vdi
  6. Create new machine in VirtualBox GUI and attach the cloned disk image to it when asked. You can also copy an existing machine's .xml configuration file and change the hard disk UUID, or create a script that will do this for you.
You're ready to boot your clone now. Of course, if you cloned a machine still using the device ID for hard disk, you should still be able to boot it, if you pass the right root=/dev/sdXY and resume=/dev/sdXY parameters to grub. You can also reconfigure the network devices after booting. But preparing the base is more convenient, if you need to clone it often.

For more info see:
http://srackham.wordpress.com/cloning-and-copying-virtualbox-virtual-machines/
http://forgeftp.novell.com/lfl/.html/virtualbox.html

9 comments:

michal said...

You can also use labels, to prevent both /dev/sd? vs. /dev/hd? and /dev/disk/by-ID problems.

Unfortunately you have to add labels to your partitions by hand, using tune2fs, mkswap or other tools, depending on filesystem type.

Then, in YaST's Partitioner module, edit all mounted partitions and in 'fstab options' select 'Mount by Volume label' (you can also set it to 'Mount by Device name' here to achieve what Jano describes).

Using volume labels is just a tiny bit more flexible, because even if for some reason /dev/sda becomes /dev/sdb or whatever, the correct partition will still be available in /dev/disk/by-label/[volume-label].

Then, in the Boot Loader module in YaST, ask it to 'Propose new configuration' under Other. It will fix the menu and entries in /boot/grub/device.map and install the new menu.

BTW, Jano you forgot to mention device.map and installing grub to actually apply the changes.

bobo said...

培養健全孩子最好的方法是父母先成為健全的人。.........................

coolcool654 said...

Every why has a wherefore.........................................

優雅的 said...

灰心是動搖的開端,動搖是失敗的近鄰。..................................................

星美 said...

看看blog調整心情,又要來繼續工作,大家加油........................................

仁南 said...

KK777一夜激情聊天live show成人自拍貼圖自慰少婦自拍裸體圖片台灣色情成人網站情人視訊網情色留言板視訊美女免費視訊聊天室限制級極度震撼情色論壇色情特區自拍裸女貼圖潮吹性影片觀賞小穴情色片a圖片sex story性愛影片美女做愛成人色情網站性愛圖片成人情色貼圖全裸寫真集圖片走光圖女生陰毛自慰影片色情av1007成人色情聊天室女生自慰裸體照成人影音聊天台灣色情網站色情片打手槍情色天堂成人視訊聊天免費情色網站av網超性感辣妹激突成人論壇情色視訊聊天鹹濕成人網站av成人論壇免費美女視訊

佩昭彥怡 said...

「不可能」這個字詞,在聰明人的字典中是找不到的。......................................................

Michele C. said...

Very usefull, thank you very much

mz said...

Thank you Jano !
Excellent post !!!