1

I am tasked with imaging 8 GB of data to a larger external drive, 100+ GB in C++.

My code is looping through all the sectors and copying from a .IMG to the disk itself. Clearly making a 100 GB image and looping through it would not yield any speed up compared to just copying the files.

Instead I took an image of an 8 GB drive. It is now apparent that I can't just write those 8 GB into the range 0-8 GB on the 100+ GB drive. My question is, what is the proper allocation to write this smaller data to a larger drive and how can I learn more about it?

  • The image of the 8GB drive can be written as a normal binary file on the larger hard drive. This is how windows 7 does partition image backups. – rcgldr Mar 14 '17 at 21:04
  • Right now I'm taking sector data 1 MB at a time and writing to the same sector location on the larger drive. Then at the end the drive is still empty –  Mar 15 '17 at 12:02

1 Answers1

1

In some cases you can, in fact, write the 8GB image to the 100GB drive without wasting the space on the 100GB drive. You need to meet two conditions:

  • The 100GB drive is completely empty, and it's okay to overwrite everything on it.
  • The image is a full disk image, not just a partition image.

If both those conditions are met, you first write the raw 8GB image to the 100GB drive, and then you use a tool like GParted to resize the filesystems and partitions on the 100GB disk. The GParted LiveCD will come in handy for this.

If you need to do this all in C++, a look at the parted/GParted source code will show you exactly how ridiculously complicated it can be do to this from scratch. However, you may be able to use the parted coded directly in yours depending on the license of your own code.

Andrew Klaassen
  • 206
  • 1
  • 8