Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-08-2005, 05:28 AM   #1
LQ Newbie
Registered: Jan 2005
Posts: 2

Rep: Reputation: 0
How to access raw sectors on HDD with no file system?


I am new to Linux and this forum. So please bear with me if I asking something unsual.

I would like to know how to access data from raw sectors of a HDD which does not have a filesystem installed on it.

The setup is something like this. We have Linux installed on an HDD, called "HDD-A" hereafter and there is another HDD, "HDD-B" linked to this. HDD-B is raw, doesn't have a filesystem installed on it. There is data written directly on to the sectors of HDD-B. My question is, how to access the data on HDD-B from HDD-A, without mounting it. Hope the question is clear.

Hoping to get some quick answers..

Thank you,
Old 01-08-2005, 05:48 AM   #2
LQ Newbie
Registered: Jan 2005
Location: NZ
Distribution: Customized MDK 9
Posts: 13

Rep: Reputation: 0
Hi Parasanth.

You can begin with "dd" that directly copies (blocks of) bytes from one place to another. Suppose your HDD-B is detected as hdc by kernel (accessible in /dev/hdc), do

dd if=/dev/hdc of=<file name> bs=512 count=<# of sectors you want> skip=<#-th sector you want to begin>

e.g. To copy the MBR record (first sector) of hdc:

dd if=/dev/hdc of=img bs=512 count=1
Old 01-08-2005, 06:06 AM   #3
LQ Newbie
Registered: Jan 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Hi Kevin ,

Thanks for your suggestion.

Actually, I wanted to do this programmatically. And as I mentioned b4 I am totally new to Linux. Is this "dd" a linux command or a C routine? Can you give me some code samples, since I intend to do it programmatically.

Old 01-08-2005, 10:39 AM   #4
LQ Newbie
Registered: Jan 2005
Location: NZ
Distribution: Customized MDK 9
Posts: 13

Rep: Reputation: 0
It is a command. You can use it easily in a shell script. Check on its man page for more details. - Read first n sectors from hdc

dd if=/dev/hdc of=$2 bs=512 count=$1
Save it into "", do a chmod 755 and run with ./ 80 backup.img to copy the first 80 sectors of hdc into a file called "backup.img".

"dd" can be used to copy between virtually any two files, providing you have the access. It is also a common tool for doing floppy images/duplications as an option of many Linux distribution installation.

Last edited by Inunu; 01-08-2005 at 10:42 AM.
Old 01-08-2005, 11:53 AM   #5
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,721

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
Should you want to do it in C: just open /dev/hdc, lseek to the position you want to access and just read with the system calls of the same names.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Raw file system...???? avols143 General 4 07-02-2004 11:14 PM
Access linux file system from windows.... johncsl82 Linux - Newbie 2 06-19-2004 11:16 AM
Reading raw hard disk sectors villie Programming 4 05-13-2004 01:18 AM
ho to access the windows file system from vmware pessanimahi Linux - Networking 2 09-18-2003 09:26 AM
Transparent access to file system n99joker Programming 2 08-21-2003 10:50 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:44 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration