User Tools

Site Tools


General Tips

Create Virtual Machine from Partition

  1. Boot into live cd.
  2. Create a new ext4 partition that is larger than the partition you want to virtualize (you may need to shrink it).
  3. dd the target partition into a file in the new partition you just created.
  4. Copy the vmdk to windows and create a new virtual machine with it

Copy Hard Drive

  1. Boot from live ubuntu cd.
  2. Figure out which /dev/sd* is the old drive and which is the new one.
    $ hdparm -I /dev/sda
    $ hdparm -I /dev/sdb
  3. If you're copying from a larger drive to a smaller drive, you should resize the partitions so they will fit on the smaller drive.
    $ gksudo gparted

    Now shrink the main partition so that it will fit on the new drive. You may want to restart the computer so the operating system can detect this change in partition before moving on.

  4. Run the magic dd command that copies the drive over.
    dd if=/dev/<old> of=/dev/<new> bs=512k conv=noerror

    If you want to see the progress while copying you can run:

    dd if=/dev/<old> bs=512k conv=noerror | pv -s 512G | dd of=/dev/<new> bs=512k conv=noerror

    You may want to limit the total amount copied by dd:

    dd if=/dev/<old> of=/dev/<new> bs=512k conv=noerror count=<number of blocks to copy>
  5. If you're running linux and your drive is not an IDENTICAL drive, you need to update the global partition table (GPT).
    parted /dev/<new>
    (parted)  print
      Warning: ...bad GPT...
      Fix/Ignore? Fix
    (parted) quit
  6. If you want to remove the old hard drive you're done. However, if you want to use both, you have some more work to do. It turns out, dd copies EVERYTHING, including the UUIDs of the drive partitions. This causes grub (or windows) to just pick a root partition to boot to. In order to make sure grub (or windows) boots to the new drive, you need to change the UUIDs. The best way to do this is to remove the partitions on the old drive.
    1. Boot into the live cd again.
    2. Use gparted to blow away the old partitions on the old hard drive. You can tell which is which by the unallocated space on each drive.
  7. At this point everything is in theory done, but you will probably still have trouble booting into the correct boot partition. The problems are mainly due to the shit that is UEFI, and we haven't quite figured out a nice way to deal with it.

Change UUID of HDD Partitions

The easiest way (albeit a little sketchy) is to change the UUID of the old drive, so that grub won't boot to it and you don't need to update grub at all.

To change the UUID of an ext partition:

tune2fs /dev/<old> -U `uuid`

For the boot partition, things are a tad more complicated. Apparently the way to do this is to manually change the UUID of an vfat partition. The idea is to copy the raw data that represents the UUID, manually edit it, and then write it back.

First, find the current UUIDs.


Now you need to copy the data (and save a backup while you're at it).

dd if=/dev/<old boot partition> of=~/superblock bs=512 count=1
dd if=/dev/<old boot partition> of=~/superblock_backup bs=512 count=1

Then, you need to use a hexeditor to modify the UUID in the superblock.

hexedit ~/superblock
  / <search for a byte of the old uuid>
  <type a number to change a byte of the old uuid>
  [ctrl+s] save the file
  [ctrl+c] to exit

Now, if you want to check everything is good, you can compare the two superblock files.

hexdump ~/superblock > ~/s_hex
hexdump ~/superblock_backup > ~/s_backup_hex
diff ~/s_hex ~/s_backup_hex

You should only see your change to the UUID.

Last you need to write it back.

dd if=~/superblock of=/dev/<old boot partition> bs=512 count=1
tips/general/start.txt · Last modified: 2013/05/25 17:51 by bradjc