Computer Music Politics Miscellany

Basic Hard Disk Partitioning

Hard Disk Partitions

Resources:

man pages or info pages:
dd, od, cfdisk, fdisk, sfdisk, gpart,
badblocks -o filename, mkfs -l filename
HOW-TOs:
Large-Disk-HOWTO
The GRUB manual

Note: The following information is reliable—for the most part. Be advised that messing with a hard disk at this level can be dangerous. If you hose your data, don't say I didn't warn you.

One method to read the HD:

  dd if=/dev/hda bs=512 count=1 conv=swab | od -A d -v -x | less

In the example above, dd will read the MBR of /dev/hda and od will format the output of dd using decimal offsets (-A d) and hexadecimal data (-x). Using conv=swab will swap each pair of bytes. This has the effect of correcting little-endians. (A discussion of big- and little-endians is beyond the scope of this document. Intel PCs are little-endians and you need to be familiar with the concept to understand how data is stored and represented.)

Notes:

The following is a dump of a typical hard disk Master Boot Record (see below for an explanation of MBR) produced with the command line:

 dd if=/dev/hda bs=512 count=1 | od -A d -v -x
 Offset             Contents of MBR
Decimal               Hexadecimal
-------  ---------------------------------------
0000000  ebfa 006c 0000 494c 4f4c 0001 0014 016b <-Code section
0000016  0000 0000 eda6 3ac5 2731 6e80 3201 8027   (446 bytes)
0000032  016e 2730 6e80 0101 0000 0000 0000 3400
0000048  8027 016e 2722 1180 2301 8027 0111 2724
0000064  1180 2501 8027 0111 2726 1180 2701 8027
0000080  0111 2728 1180 2901 8027 0111 0000 0000
0000096  0000 0000 0000 0000 0000 0000 0000 b800
0000112  07c0 d88e 068c 006a 3689 0068 1e89 006c
0000128  1688 006e 00b8 8e8a b9c0 0100 f629 ff29
0000144  f3fc eaa5 0098 8a00 8efa 8ed8 bcc0 b000
0000160  00b8 8e80 fbd0 0db0 57e8 b000 e80a 0052
0000176  4cb0 4de8 be00 0034 00bb fc10 89ad adc1
0000192  c289 c809 2074 e846 0043 0672 c381 0200
0000208  eaeb b050 e820 002a 8858 e8e0 0012 c031
0000224  c288 13cd cfeb 49b0 17e8 ea00 0000 8b00
0000240  c050 04e8 01e8 5800 0f24 3004 3a3c 0272
0000256  0704 ff30 0eb4 10cd 5ac3 5b59 f6c3 40c2
0000272  5474 e280 53bf 5251 08b4 13cd eb72 f088
0000288  885a 7316 8801 30f2 51f6 cd86 c5d0 c5d0
0000304  e580 8903 710e 5901 e183 f63f 01e1 93c8
0000320  f758 92f3 f1f6 c4fe 2688 0174 8892 8ad6
0000336  7316 3b01 7106 7701 8613 d0c4 d0c8 0ac8
0000352  7406 8901 5bc1 01b8 cd02 c313 315b f9c0
0000368  00c3 0000 0000 0000 0000 0000 0000 0000
0000384  0000 0000 0000 0000 0000 0000 0000 0000
0000400  0000 0000 0000 0000 0000 0000 0000 0000
0000416  0000 0000 0000 0000 0000 0000 0000 0000
0000432  0000 0000 0000 0000 0000 0000 0000 0180 <-Partition table
0000448  0001 fe83 0c3f 003f 0000 2f8e 0003 0000   (64 bytes)
0000464  0d01 fe83 193f 2fcd 0003 2fcd 0003 0000
0000480  1a01 fe83 263f 5f9a 0006 2fcd 0003 0000
0000496  2701 fe05 ffff 8f67 0009 0b98 025a aa55 <-Terminator
                                                   (2 bytes)
Note:
  1. Location 0000511 (512 bytes) is the end of the MBR.
  2. Each pair of bytes is reversed—see little-endian. Use “conv=swab” in the command line if you want the byte pairs in big-endian order.

MBR - Master Boot Record

Note: using dd, the MBR of the first HD is the first 512 bytes of /dev/hda.

  1. Code section (446 bytes)
  2. Partition table (for 4 partitions x 64 bytes/partition)
    /* There are 4 table entries that look like this in the MBR */
    /*  (CHS stands for Cylinder/Head/Sector)                   */
    struct partition {
       char active;   /* 0x80: bootable, 0: not bootable    */
       char begin[3]; /* 24 bit field; CHS for first sector */
       char type;
       char end[3];   /* 24 bit field; CHS for last sector  */
       int start;     /* 32 bit sector number (cnt from 0)  */
       int length;    /* 32 bit number of sectors           */
    };
    
    /*  C = 10 bits */
    /*  H = 8 bits  */
    /*  S = 6 bits  */
    
  3. Terminator aa55 hex (2 bytes): this seems to be absolutely necessary for the disk to be recognized as usable. After zeroing out a HD, Linux fdisk can write the aa55 making the disk valid in the eyes of MSDOS and Linux. Just use fdisk (or cfdisk) to write the partition table even if the disk has not been partitioned and shows only free space. The bytes aa55 will be written to terminate the MBR.

First Partition (accessed as /dev/hda1 with dd):

  1. Boot sector (512 bytes)

    followed by

  2. Actual data

Partitioning Software

fdisk (linux)

the man page says it is buggy and recommends cfdisk. However, this is the fdisk usually used by distributions to partition the HD initially.

cfdisk

curses front end for partitioning.

sfdisk

command line driven; recommended for experienced users.

MSDOS fdisk

will do different things depending on MSDOS version. The version supplied with MSDOS 6.x will not create more than one primary partition; the rest will have to be logical partitions. Some earlier versions can create four primary partitions. Another limitation is that fdisk will only see about 8 Gigs of a HD.

Use one of the hard disk utility programs supplied with Linux or FreeBSD to create more than one primary partition or partition a HD drive larger than 8 Gigs.


Suggestions

When creating a dual boot machine you should safeguard the MBR in such a way that it can be restored if necessary. There are several ways to do this:

  1. MSDOS method: use the MSDOS “fdisk /mbr” command to write a new MBR to the disk.
  2. Linux/Unix method: use dd to save the MRB to a file and restore it using dd when necessary.

Last updated: Saturday, 13-Sep-2014 01:47:38 UTC