Re: Read/Write bytes directly from hard drive

phil-news-nospam_at_ipal.net
Date: 04/23/05


Date: 23 Apr 2005 02:32:46 GMT

On Fri, 22 Apr 2005 21:48:19 -0000 Grant Edwards <grante@visi.com> wrote:
| On 2005-04-22, tom <tom@dbservice.com> wrote:
|> asharma wrote:
|>> We are writing a disk partitioner from scratch. We were not sure how to
|>> access any byte from the disk, including the master table or any other
|>> data. Are there any system calls that handle read/write operations?
|>>
|>
|> int fd = open("/dev/hda", O_SYNC);
|>
|> Read the first x bytes and you get the partition table of your first IDE
|> disk. Replace x with the size of your partition table.
|
| Be careful though. I seem to remember hearing Grub developers
| complain that the Linux filesystem code or buffer cache did
| something they didn't like with the first disk sector. I don't
| know the details, but the end result was that they couldn't
| reliably write to the boot sector when the drive had mounted
| partitions. I don't know if it was just the MBR or if the boot
| sectors within partitions were the problem. IIRC it wasn't an
| issue if no partitions on the disk were mounted.

I have been able to write sector 0 and change partitions even though some
partitions were mounted. I did not change any that were mounted, so I
cannot say that what is going on doesn't check for such a situation. But
what did not work was rereading the partition table to set up the new
partition size. I had to reboot.

-- 
-----------------------------------------------------------------------------
| Phil Howard KA9WGN       | http://linuxhomepage.com/      http://ham.org/ |
| (first name) at ipal.net | http://phil.ipal.org/   http://ka9wgn.ham.org/ |
-----------------------------------------------------------------------------


Relevant Pages

  • Re: 200GB IDE disk on old system
    ... the disk so biosroutines can load the kernel? ... Figures below won't work with BIOS for partitions not in cyl 1 ... BIOS sector numbering starts with sector 1 ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Hard drive recovery - better to COPY or use ACRONIS? pls help
    ... The other option, is various versions of "dd", to do a sector by sector ... If the display shows all green blocks, then the disk is relatively ... other numbered partitions, represent the primary partitions on the disk. ... For rescue, I recommend at least two spare disks, one for a simple ...
    (microsoft.public.windowsxp.general)
  • Re: Hard drive recovery - better to COPY or use ACRONIS? pls help
    ... File by file copying is likely no different, no matter what tool does it. ... The other option, is various versions of "dd", to do a sector by sector ... If the display shows all green blocks, then the disk is relatively ... other numbered partitions, represent the primary partitions on the disk. ...
    (microsoft.public.windowsxp.general)
  • Re: Upgrade Hard Drive - transfer data & partitions
    ... I have an adapter to hook up a SATA drive as USB - I use it for getting data off corrupted drives. ... for cloning just individual partitions and for making ... the contents of one disk to another. ... To do that style of "dumb" sector by sector transfer, ...
    (alt.comp.hardware.pc-homebuilt)
  • LVM on SW RAID for sarge - success
    ... I've just had success migrating Debian Sarge to root on LVM on RAID. ... First make sure the SCSI BIOS boots from the first disk. ... I made reiserfs on all the filesystem partitions and completed the ... The remaining two disks were partitioned and used to create RAID arrays ...
    (Debian-User)