Author Topic: hard drive and partition  (Read 19432 times)

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
hard drive and partition
« on: August 09, 2011, 07:48:57 PM »
hey
do yall know where i can get more info on accessing hard drive and partition?
like how to set partition 1 or 2 or 3 active or inactive etc..
thanks

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: hard drive and partition
« Reply #1 on: August 09, 2011, 08:49:43 PM »
i found this yall
thestarman.pcministry.com
thanks yall

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: hard drive and partition
« Reply #2 on: August 09, 2011, 09:12:26 PM »
fdisk? Shouldn't be too difficult to do it yourself. Seems to me I have an example that does that - written for cpm-86 but I think I have a dos version, too... maybe even Nasm syntax. But I have no idea what the name is, so I can't find it at the moment. Roughly, read your MBR into a buffer. At offset 1BEh, you should find 4 entries of 16 bytes each. The first byte of each entry should be the "bootable" or "active" flag - 80h for "active", zero otherwise. Change 'em to suit. Write the buffer back to your hard drive. Reboot, and you should boot a different partition. Non-existant partitions should be all zeros. You would not want to mark such a partition "active"! So you may want to do some "checking" besides blindly writing 80h. You only want one "active" partition, so don't forget to overwrite the 80h in the "no longer active" partition. That should be about it.

Dreamaco seems to know a lot about this, so if he has different advice, follow his, not mine!

Best,
Frank


Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: hard drive and partition
« Reply #3 on: August 09, 2011, 09:57:26 PM »
thanks frank
thestarman explains alot i can look at the mbr and tell whats on all partitions .
i listen to all your advice and many  thanks

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: hard drive and partition
« Reply #4 on: August 09, 2011, 10:08:12 PM »
if i know its 1BEH ,1CEH,1DEH AND 1EEH can i change just the two places ?
or will i have to write all?
thanks yall

Offline dreamaco

  • Jr. Member
  • *
  • Posts: 19
Re: hard drive and partition
« Reply #5 on: August 10, 2011, 01:11:41 AM »
if i know its 1BEH ,1CEH,1DEH AND 1EEH can i change just the two places ?
or will i have to write all?
thanks yall

The layout I gave you earlier explains all in a simple fashion. Everything is there.
Each little bit is in there. :) And notice the usage of shifts to get the CHS right spread.
I post it here again: http://forum.nasm.us/index.php?topic=1170.msg4645#msg4645

Note: If you want Windows specifics, then code is even shorter to fit errormsgs, msglengths, and NTserial.
These are not part of MBR standard of course, its Windows doing what it wants with the total 446bytes code portion.

EDIT Forgot to answer your question;  If your drive has 2 or more parititions setup then its just a matter of changing those 4
locations as you said. The one you want to be booted should be 80h while others should be 0.
And this works perfectly as long as an Extended MBR's are not used. There are two (more or less) common types of "extended MBR's". If you have more than 4 partitions then you know you have some kind of extended MBR, as standard MBR can only fit 4.
Most people will never need to bother with extended MBR's as 4 partitions is quiet alot. That's my personal humble opionion. So I won't explain those. They are not needed. Shout If you still need some info on it I mayhap help you out.

EDIT I missed that Frank already had answered.. what he said I can only agree on.

Have a great day everyone!!
« Last Edit: August 10, 2011, 04:01:49 AM by dreamaco »

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: hard drive and partition
« Reply #6 on: August 10, 2011, 08:46:05 AM »
thanks dreamaco startman only answered the 80h and os  byte number five  looking back to your other post now i under stand what all of them stand for
thanks again

Offline flyhigh427

  • Jr. Member
  • *
  • Posts: 60
Re: hard drive and partition
« Reply #7 on: August 10, 2011, 10:06:13 PM »
hey dreamaco
and hey all
i use hxd editor to look at a backup of my mbr of my harddrive and then i look at a copy of c: drive .
why are they different? my backup works and the other is the ntfs boot sector
thanks 
Quote
  one is logical view and the other is physical view are they the same?
« Last Edit: August 10, 2011, 10:25:19 PM by flyhigh427 »

Offline dreamaco

  • Jr. Member
  • *
  • Posts: 19
Re: hard drive and partition
« Reply #8 on: August 12, 2011, 04:15:57 AM »
hey dreamaco
and hey all
i use hxd editor to look at a backup of my mbr of my harddrive and then i look at a copy of c: drive .
why are they different? my backup works and the other is the ntfs boot sector
thanks 
Quote
  one is logical view and the other is physical view are they the same?

I can answer that, it's really simple.

When you look at "physical devices" as many software refers, they really mean the true, thing, sector 0 really IS sector 0.
So you're actually looking at true sector 0.

When you look at "logical devices" as many software refer to, they really mean the PARTITIONS.
 
So looking at sector 0 on a logical, you look at first sector of that PARITION, that is, you're looking at that paritions first sector, its bootsector.

It's that simple :)

So when you're viewing somehting logical, you  never actually see the WHOLE drive, no you see that single parititon only. And first sector "seem" to be sector 0, but its instead the first sector of that one paritition. I was confused as hell first time I saw this in my life having noone telling me what I actually saw.

Try an expremint! view the physical drive, as here you see everything, look sector 0 .. you find MBR.. now try something like viewing sector 63 which is often the first sector of first parititon meaning.. the bootsector of first partition..
You end up seeing that sector 63 of physical is THE SAME as viewing the first sector of the logical..


Remember that's there's either a bootsector or a MBR on a drive. And, if there's a MBR .. there's always one bootsector PER existing partition (the first sector of that particular partition).

EDIT: Want to mention a sidenote to be more clear
No partitions means no logical devices.. Eg. If you stick an USB-key perhaps thinking it has no partitions, that it's just one solid thing.. Think again. It has probably been formatted FAT16/32/64/NTFS meaning it HAS an MBR and a single partition at least". Which makes up the drive. So even things with "no apperent paritions" will show up of course as a logical device as any partition should.Because they DO have partitions. Even if only one. Just a few FAT12-formatted ones has no MBR, does not today. And even those might have MRB if you wish. Long story short; expect to meet many MBR's and therefore see many "logical devices", but the physical view.. is the interesting one, you see eveything there including all parititons, check the MBR LBA fields to see where they are.


It's not hard at all, sorry if my explanation is abit messy. Just ask if wondering something , okay?

BTW great choice of tools; HxD is amazingly good.
« Last Edit: August 12, 2011, 12:10:09 PM by dreamaco »

Offline Eccentro

  • Jr. Member
  • *
  • Posts: 25
Re: hard drive and partition
« Reply #9 on: August 12, 2011, 06:17:25 PM »
Thanks dreamaco,

I never really understood the whole physical vs logical thing when it came to drives until now.  The question was in the queue, but it never occurred to me to ask it.  hehe.  Funny how that works.

You answered a question that I should have asked.   ;D

Offline dreamaco

  • Jr. Member
  • *
  • Posts: 19
Re: hard drive and partition
« Reply #10 on: August 14, 2011, 12:36:28 PM »
Thanks dreamaco,

I never really understood the whole physical vs logical thing when it came to drives until now.  The question was in the queue, but it never occurred to me to ask it.  hehe.  Funny how that works.

You answered a question that I should have asked.   ;D

Great :) and glad to hear!!