-MAIN-MENU-  
Appal Home
Appal.org
  -MAIN-MENU-  
Search The Website
-*-

How To Migrate a Linux Formatted Virtualbox .vdi Image to Linux Filesystem   Posted: March 27, 2014
How To Migrate a Linux Formatted Virtualbox .vdi Image to Linux Filesystem

As root, clone the vdi disk to an intermediate RAW file,next
mount that with losetup and use fdisk to locate the
main partition, then mount that as a linux filesystem.

This example shows the migration of a VirtualBox .vdi image of a Linux
based installation to a bootable disk. In this example the bootable
destination disk is an 8GB USB3 wear-leveling thumb drive, suitable
for use as a main file system. While 8GB is relatively small, the OS will
fit in a fraction of that space. Additional storage can be mounted like any
other Linux system.

###################################
Create the destination partition:
###################################
*Use an 8GB a USB stick, make sdc1, the same size
*as the .vdi image
mkfs.ext3 /dev/sdc1
df
* shows "/dev/sdc1 7479776 17112 7076056 1% /media/sdc1"

###################################
Choose a source, and a temp dir:
###################################
* Change to the .vdi dir, e.g.: /vboxn/dmz_2#
* to verify the source file
ls
* returns "dmz_2.vbox dmz_2.vbox-prev dmz_2.vdi Logs"
* This example uses /media/sdb1/dmz_2.raw.img for the temp/intermediate image file

###################################
Clone the drive to RAW image:
###################################
vboxmanage clonehd dmz_2.vdi /media/sdb1/dmz_2.raw.img --format RAW
* shows "0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%"
* "Clone hard disk created in format 'RAW'. UUID: c0031b52-db31-42a5-9045-7b627a800ab5"

###################################
Setup loopback dev & see partitions:
###################################
losetup /dev/loop1 /media/sdb1/dmz_2.raw.img
fdisk -lu /dev/loop1
*Shows "/dev/loop1p1 * 2048 15788031 7892992 83 Linux"

###################################
Setup 2nd loopback dev @ partition 1:
###################################
*Now create a second loopback device starting at the offset for the partion located above (@ block 2048)
losetup /dev/loop2 /media/sdb1/dmz_2.raw.img -o $((2048*512))

###################################
Mount the loop2 device:
###################################
mount /dev/loop2 /media/sdd1

###################################
CD & List the dir:
###################################
cd /media/sdd1
ls
*"bin dev home lib lost+found mnt proc run selinux sys usr vmlinuz"
*"boot etc initrd.img lib64 media opt root sbin srv tmp var"

###################################
Copy the Linux system from the VirtualBox to the destination drive:
###################################
* Mount the destination drive
mount /dev/sdc1 /media/sdc1
* Change to the destination drive
cd /media/sdc1
* Copy the linux system from /media/sdd1 to /media/sdc1
cp -a -x /media/sdd1/* .

###################################
Repair grub.cfg:
###################################
* Edit the USB drive's /boot/grub.cfg
* Delete all the "search" lines and substitute "root=/dev/sda1" (or whatever the root partition is) for the UUID=... parameters in all lines. This is a temporary fix to enable the first boot.

###################################
Move the USB drive to the target motherboard and boot:
###################################
* Unmount the 8GB USB drive
cd /
umount /media/sdc1
* Unplug the USB stick and plug it into the target motherboard. If there are other
drives cabled to that motherboard, you may need to sort out the disk order or unplug
them for the moment to assert the USB drive as /dev/sda. You are ready to boot.
* Now try to boot the image.
* Once booted, fix the grub setup:
/usr/sbin/update-grub

###################################
The USB drive should be bootable and running
###################################
* The basic migration is complete.
umount /media/sdd1
* unmount the loop devices made with losetup above:
losetup -d /dev/loop2
losetup -d /dev/loop1
* If you are done with that migration, remove the intermediate RAW image.
rm /media/sdb1/dmz_2.raw.img
* If you continue to use the VirtualBox .vdi image for development, repeat this
proceedure to migrate your changes to the target (USB) drive.






   All Postings
BROWSE       Headlines and Postings

Privacy Policy
Webmaster & Acknowledgments
Copyright (C) 2002,2016 W.S. Herrick and/or Respective Copyright Holders