4

I want to read bytes directly off a hard drive, preferably using python. How can I do this, provided it is even possible. Also, can I write directly to a hard drive, and how?

I want to do this to make a complete clone of a hard drive, and then restoring from that backup. I'm quite certain there are easier ways to get what I want done, and this is partly simply curiosity ;)

adisander
  • 43
  • 3
  • 1
    can you clarify what you mean by **'read directly off HD'?** You mean you want to read blocks as opposed to files? – tuxuday May 07 '12 at 08:41
  • Yes, I mean the bits and bytes as they're stored on the hard drive, no in files. Sorry about the confusion, it's the main reason I had problems searching for an answer to this. – adisander May 07 '12 at 08:46
  • 1
    The operating system doesn't necessarily permit you to do this. – Karl Knechtel May 07 '12 at 08:48

1 Answers1

5

On linux, you can open('/dev/sdX', 'r').

However, the easier way is using the dd commandline utility (but it will only work properly if both disks are exactly the same).

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • Thanks, the first part is definitely useful and probably what I'll end up using, if possible I'd like to back up straight from windwos though (which is whhat I'm backing up. No need to muck around with this with linux :) ). – adisander May 07 '12 at 08:50