Results 1 to 4 of 4
hi,
i have two partitions and i would like to compare them to see it they are the same.
Is that possible?
Bye
Javi...
- 01-22-2010 #1Just Joined!
- Join Date
- Apr 2007
- Posts
- 22
Can i compare two partitions?
hi,
i have two partitions and i would like to compare them to see it they are the same.
Is that possible?
Bye
Javi
- 01-22-2010 #2
sure.
But it depends on the layer you define "same"
For this answer I assume
- /dev/sdb1 and /dev/sdc1 are the ones you want to compare
- both partitions are not mounted
- if they are mounted, you have the permission to read each file
You can test the two partitions on blocklevel.
ie:
But for this to produce the same hash, the partitons have to be *exactly* the same.Code:md5sum /dev/sdb1 md5sum /dev/sdc1
Even the slightest change in one of the files in either of the two,
will produce a different hash.
You can also test on filelevel.
There are probably already tools, that could be used for your purposes (tripwire maybe?),
but a quick-and-dirty solution can be this:
Code:mkdir ~/comparedir sudo mkdir /mnt/test_sdb1 sudo mkdir /mnt/test_sdc1 sudo mount -o ro /dev/sdb1 /mnt/test_sdb1 sudo mount -o ro /dev/sdc1 /mnt/test_sdc1 find -type f /mnt/test_sdb1 -exec md5sum {} 2>/dev/null \; >~/comparedir/tmp_sdb1_hashes find -type f /mnt/test_sdc1 -exec md5sum {} 2>/dev/null \; >~/comparedir/tmp_sdc1_hashes sudo umount /mnt/test_sdb1 sudo umount /mnt/test_sdc1 sudo rm -r /mnt/test_sdb1 sudo rm -r /mnt/test_sdb1 sort -k2 ~/comparedir/tmp_sdb1_hashes > ~/comparedir/sdb1_hashes sort -k2 ~/comparedir/tmp_sdc1_hashes > ~/comparedir/sdc1_hashes rm ~/comparedir/tmp_sdb1_hashes ~/comparedir/tmp_sdc1_hashes diff ~/comparedir/sdb1_hashes ~/comparedir/sdc1_hashesLast edited by Irithori; 01-22-2010 at 01:48 PM.
You must always face the curtain with a bow.
- 01-23-2010 #3
A note on using md5sum.
For most of your purposes, md5sum is probably all that you need. However, Irithori is not entirely correct that the data must be identical. md5 is a checksum, which means that the same hash USUALLY means identical content, but you can also have hash collisions where different data produces the same hash. See Wikipedia for more info. However, the usual way to get a hash collision is when someone is trying to attack you, so in your case you can probably assume that the same hash means the same content depending on what you are intending to do with this data.
With that in mind, Irithori's solutions will generally work.DISTRO=Arch
Registered Linux User #388732
- 01-27-2010 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,970
The probability of collisions on a large data set with md5sum is vanishingly small, unless as Cabhan mentions, someone is purposely trying to get one. There is also a number of other checksum implementations on most linux systems, such as sha1sum, sha512sum, et al that are less likely (in most cases) to have collisions. That said, if two partitions generate the same checksum (unlikely unless they point to the same disc area), then they are almost certainly identical. However, this is unlikely to happen since some directory/block information stored in the partition will refer to absolute disc block locations, so the likelihood than any two partitions are identical are the same is small, unless both discs are bit-image copies of each other.
So, it would be helpful to know what is your usage, and why do you need to do this?Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote

