I'm looking for a way to create a virtual block device that when accessed returns the XOR of two block devices. I feel like dmsetup would be used here somewhere but I can't find anything related to what I want.

Here's basically what I'm looking for

$ xxd /dev/sda # First real device
00000000: 01 23 45 67 ....
$ xxd /dev/sdb # Second real device of same size
00000000: ab cd ef ff ....
$ xordevices /dev/sda /dev/sdb
$ xxd /dev/mapper/sdaxorsdb # Virtual device
00000000: aa ee aa 98 ....

In this example, writing to /dev/mapper/sdaxorsdb would modify /dev/sdb in such a way that the xor of /dev/sda and /dev/sdb would be the newly written data.

Is this possible?

  • Of course it is possible, but I don't think anybody already did it, so you would have to do it yourself. Why would you want that?
    – RalfFriedl
    Aug 13, 2018 at 5:33
  • @RalfFriedl Mostly experimentation. You could have a random file equal to the size of the drive and use it as a novel form of encryption. Or do some rudimentary raid 4 stuff with 2 drives and a parity file.
    – Daffy
    Aug 13, 2018 at 22:22


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.