LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Cloning USB drives using C++ (https://www.linuxquestions.org/questions/programming-9/cloning-usb-drives-using-c-791156/)

greenberet 02-23-2010 11:22 PM

Cloning USB drives using C++
 
Hi,

I have a device running Linux, which has a master USB and 16 Slave USB's.
I need to make the slaves identical to the master.

What i'm doing is reading bytes from the master by reading /dev/sd{master} and writing to /dev/sd{slaves} . I am doing this since I need to display progress of the operation.

Do you think this will pose any problems? Please comment on this technique....Is there any better technique?

Also, if the source drives size is smaller than the dest drive, will it create any problem....or will the USBs still be identical after that..


Thanks.

irmin 02-24-2010 02:39 AM

Hi,

just to make sure I understood your issue: You have a device running linux, that has 17 USB ports. The purpose of this device is to make a copy of usb mass-storage devices attached to the master USB port and write those copies to the slave USB ports?

There should be no problem in doing a bit-to-bit copy of the disk contents, as long as the final disk is at least of the same size as the source disk. I assume that the disks have a DOS partition table and that there are one or more partitions on it. If the final disk is larger than the source disk, there will be just unallocated space on the disk, that can be used, if the partition table of the final disk is modified afterwards, but not necessarily. So in this situation there should be no problem.

If the final disk is smaller than the source disk, then you can have serious problems, because you cannot store all information on the final disk. Your technique will yield an invalid paritition table and this means that it contains partitions, those boundaries may lay outside the disk. In this case, the filesystems may be usable, but need not to be. Partitions, which totally fit onto the final disk, will work as before.
So you can either copy only certain partitions (note: NTFS partitions need to start at the same position on both the final and source disk!).

Another possibility is to mount all partitions on the source disk and create them on the final disks such that all files will fit in them. Then copy only the files. This method is better and more robust.

greenberet 02-24-2010 03:00 AM

Thanks irmin,

Since I am doing a binary Copy from master to slave....im not concerned about partitions or partitions tables......as long as the slave become byte-for-byte identical to the master...the purpose has been achieved.

I am using the linux.sysfs_path property of the device(supplied by hal-get-property) to find out which port a particular storage device occupies

For eg.

/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2/3-2:1.0/host3/target3:0:0/3:0:0:0/block/sdb

By looking at 0000:00:1d:1/usb3....I find out the port in which the device is plugged. Is this method certain to work? Will any usb plugged into this particular port always have
"/sys/devices/pci0000:00/0000:00:1d.1/usb3" in its sys path?

Thanks,

irmin 02-24-2010 04:11 AM

The PCI device number will not change for sure (except when changing the system). I'm not 100% sure (only 99.9 %), that the bus number and port number (e.g.: 3-2) will not change too. I hope this helps. (Maybe the bus number changes on reboot, but I'm not sure.)


All times are GMT -5. The time now is 09:07 AM.