[kwlug-disc] Converting a running Linux box to a Virtual Machine

William Park opengeometry at yahoo.ca
Sat May 15 01:39:20 EDT 2010


On Sat, May 15, 2010 at 12:20:19AM -0400, Chris Frey wrote:
> 1) Decide how big you want your disk.  Let's assume 40gigs.
> 
> 2) Create your sparse disk file
> 
> 	dd if=/dev/zero of=disk.img count=1 seek=40000000000 bs=1
> 
> 3) Partition it
> 
> 	/sbin/fdisk -u ./disk.img
>

> 5) Calculate the number of cylinders
> 
> 	40000000000 / 255 / 63 / 512 = 4863 cylinders
> 
> 6) Set the cylinders to make fdisk happy
> 

> 7) Calculate the size of your partition
> 
> 	78124094 - 62 = 78124032 sectors
> 	78124032 * 512 = 39999504384 bytes
> 
> 8) Create your filesystem
> 
> 	dd if=/dev/zero of=fs.img count=1 seek=39999504384 bs=1
> 	/sbin/mkfs.ext3 ./fs.img
> 
> 9) Insert filesystem into a single disk
> 
> 	# this will take a while, but preserves sparseness
> 	cp --sparse=always <(head -c 32256 disk.img ; cat fs.img) finaldisk.img
> 
> 	# top up the resulting file
> 	dd if=/dev/zero of=finaldisk.img count=1 seek=40000000000 bs=1

Hi Chris,

I don't understand this last 'dd'.  Why are you writing 1 byte at the
end?

-- 
William

> 
> 10) Become root and do a loopback mount
> 
> 	Note: sector 0 is unused, and is 63 sectors * 512 bytes per sector =
> 		32256 bytes
> 
> 	mount -t ext3 -o loop,offset=32256 /tmp/finaldisk.img /mnt/loop
> 
> 11) Copy over all necessary files... /etc, /dev, /bin, /boot, /usr, etc.
> 	Good old tar or 'cp -a' will do the trick.
> 
> 12) Unmount





More information about the kwlug-disc mailing list