LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hi,

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,
Prasanth
 
Old 01-08-2005, 04:48 AM   #2
Inunu
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, 05:06 AM   #3
prasanthpooyath
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.

-Prasanth
 
Old 01-08-2005, 09:39 AM   #4
Inunu
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_hdc.sh: - Read first n sectors from hdc

Code:
#!/bin/sh
dd if=/dev/hdc of=$2 bs=512 count=$1
Save it into "read_hdc.sh", do a chmod 755 read_hdc.sh and run with ./read_hdc.sh 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 09:42 AM.
 
Old 01-08-2005, 10:53 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,506

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
  


Reply


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 10:14 PM
Access linux file system from windows.... johncsl82 Linux - Newbie 2 06-19-2004 10:16 AM
Reading raw hard disk sectors villie Programming 4 05-13-2004 12:18 AM
ho to access the windows file system from vmware pessanimahi Linux - Networking 2 09-18-2003 08:26 AM
Transparent access to file system n99joker Programming 2 08-21-2003 09:50 AM


All times are GMT -5. The time now is 03:05 PM.

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