Monday, August 27, 2018

partitioning - How to copy a bootable NTFS partition from one physical hard drive to another with Ubuntu?


I have a USB flash drive with Ubuntu 11.10 installed that I would like to use for the following task:


I have a hard drive with 4 partitions. The second one is formatted with NTFS and contains a fully functional Windows installation. I would like to copy that second partition to another physical hard drive (which is empty).


There's a catch however - I cannot have both hard drives physically connected to the computer at the same time. I have a third external hard drive however that will remain connected throughout the entire operation and has more than double the space of both of the other hard drives.


I realize there are a lot of things to consider here:



  • The process will obviously involve making some sort of "image" of the second partition, storing it on the external drive, and then copying the image to the new drive.


  • The partition that I am copying is bootable and should also be bootable when copied to the new drive. I can probably fix the MBR on the partition afterward if need be.


  • The old and new drives are not identical in make, model, or size. However, there is ample room for the second partition on the new drive.



Any advice on how to proceed or warnings for possible pitfalls would be greatly appreciated. Also, if I missed an important detail, please don't hesitate to ask for it.



(No extra software required, use the tools you have)




dd if=/dev/sda2 of=foo_file.img will create an exact replica of sda to a .img file that you specify.


Save it to an external device and restore it with dd if=foo_file.img of=/dev/sday.


Step by step



  1. Boot from the Ubuntu LiveCD and open the disk management tool (or use sudo fdisk -l from the terminal) to find out which disk you will be copying.


  2. Mount the external device you will save the .img file to, do not mount the disk you want to make the image from!


  3. Use dd if=/dev/sda2 of=foo_file.img, replace /dev/sda2 with the actual partition you want to copy and foo_image.img with a file located on the external disk you previously mounted.


  4. Reboot your PC removing the disk you made the image from and install the new disk in your PC. Boot the computer with the Ubuntu LiveCD.


  5. Mount the external disk that contains the .img file and open the disk tool to make sure about the device where we are going to write it to. (Probably will be using the same device path as the one you just removed). Don't even try to mount the new disk, there should be nothing to mount anyways!


  6. Use dd if=foo_file.img of=/dev/sdax to write the image you created and stored on to the external device to the new disk you just installed. Change sdax for the correct partition.


  7. Run gparted and resize your newly created partitions to accommodate the extra space in your new disk.


  8. Reboot and boot using your new disk.



After this is done you can keep the .img file as a backup till you make sure that everything is running.


I have used this method oh so many times now and not an issue, but you never know. Keep a backup around for some time.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...