3. fdisk - partition disks

fdisk is the program that splits the hard disk into partitions. You will create:

  • a 10 MB Linux partition below 1024
  • a DOS partition below 1024
  • a 32 MB SWAP partition
  • a 350 MB linux partition
  • across and beyond 1024

You will add new partitions (maybe delete old ones) and change the partition tag, which indicates the intended usage of each partition, eg

  • Partition tags:
  • 82 - Linux swap
  • 83 - Linux native (probably ext2)
  • 06 - DOS 16-bit >=32 M
  • db - CP/M
  • 65 - Novell Netware

You need to know the names of the disk devices, and the difference between a partition and a disk. eg /dev/hda is the entire disk, /dev/hda1 is partition one. /dev/hda5 is an extended partition. SCSI disk partitions have names like /dev/sda5.

NOTE: Your partition numbers, and disks will be completely different from mine. If you blindly follow this text, you will destroy your existing data. Switch BrainMode=ON

Check that /dev/hda5 exists in /dev, you might have to create the ones you need if they don't. See mknod(1) or /dev/MAKEDEV.

You need to know that EIDE drives are numbered a b c d, whether it's a CDROM or a disk. You can't run fdisk on a cdrom!

	fdisk /dev/hda	# look at first ide disk
-or-	fdisk /dev/hdc  # look at third ide disk (master on second ide)
-or-	fdisk /dev/sdb  # look at second SCSI disk

You probably won't need to know the disk geometry, (Cylinders/Heads/Sectors). Usually Linux gets the correct values automatically during boot directly from the EIDE drive. (those messages are kept in /var/log).

E-IDE disks are numbered a,b,c,d ... and SCSI disks are also (eg /dev/sda1), however SCSI disks are 're-numbered' from 'a' without gaps, whereas E-IDE disks aren't. IE a,b,c,d is the sequence of the SCSI disk, not the target LUN address.

Conversely, if you have 2 EIDE disks on the second controller, but only one on the first, there will be a gap, a,-,c,d. The difference is traditional SCSI behavior, which (thankfully) the EIDE driver doesn't do.

3.1 Documentation
3.2 FDISK - 1024 cylinders max
3.3 4 partitions per disk
3.4 30 MB swap partition
3.5 Deleting partitions
3.6 FDISK when INSTALLING LINUX
3.7 FDISK using lies

3.1

Documentation

3.2

FDISK - 1024 cylinders max

This is similar to the DOS fdisk program, but through a command line interface. It's very simple taken step by step, but there is an initial hurdle to overcome: DOS, BIOS and LILO (but not Linux) have a limitation of 1024 cylinders (#-MAX) on the disk. Your 1Gb disk is probably double that. FDISK will tell you this when starting,

This problem with 1024 cylinders is well known, and modern system-BIOS's will collaborate when faking the number of disk heads (usually 16 doubled up to 32). The trick is to tell the same lie to everyone. However, the Linux kernel (AFTER LILO has found and loaded it), asks the EIDE disks direct. see /usr/src/linux/drivers/block/README.ide

i.e. if you choose to lie, you will have to tell Linux about the lie - it knows the truth!

Personally, I prefer to create a 10 MB boot partition below 1024 and not use any lies at all.

LILO and the kernel are accessed by BIOS, which can only read the two disks on the first IDE cable. Create a partition BELOW 1024, but only 10MB, and make sure that the boot files get in there. Then you won't need to use any lies at all. If you do this, the disk can easily be moved to a different system, with different BIOS capabilities.

You may be lucky, and have the files on a partition that extends above 1024. (ie the partition reaches above 1024, but the files dont). However, your luck may later run out, and the kernel (or other boot files) get stored above 1024, and your system won't boot. You will then need your boot diskette (if you have one).

IE the easiest thing to do, is to not tell any lies at all, and create your DOS partitions and the boot partition below 1024 cylinders. Linux (after it has been loaded!) will get the real disk geometry, and use it.

3.3

4 partitions per disk

You have a maximum of 4 partitions, though you can also have sub-partitions, which end up as /dev/hda5, 6, etc.

Linux will run in either primary or extended partitions. LILO also.

Presumably DOS is on a different disk or on the first partition of the disk, using 200 Mbytes or so. Then comes the Linux boot partition (10 Mb) then swap space (30 Mb) then the Linux root partition using 400 Mbytes. A full Slackware installation will use much more than that. You can get a bigger disk, a second disk (see later for how), or be selective in what you install.

Note that Slackware doesn't guide you to use a 10 MB boot area, this is a fix that you have to implement without it's suggestion, maybe with it's help.

If you put the 10 MB partition below DOS, it won't get in the way when you delete the DOS partition!

3.4

30 MB swap partition

30 Mb swap is reasonable, personally I have more, and on each disk! If I get desparate for file space, I can convert it, use it for all those down-loaded things, rebuild the cramped disk, copy the files back and convert it back to swap space.

If it's not in /etc/fstab it might not get used.

The swap partition has a partition tag type of 82 (HINT: in fdisk use the L and the T commands). Run mkswap on it during installation. This is MUCH safer than explicitly naming the device and block count in a file during system boot.

During system boot (in /etc/rc.d.rc.S) the command swapon -a finds all properly tagged partitions listed in /etc/fstab and uses them intelligently (rather than blindly). I prefer it when /etc/fstab controls swap.

Putting the swap space on a different disk is a good idea, as a disk head movement on the swap area won't effect the disk head on the program disk. IE put the swap partition on an otherwise unused (DOS) disk.

This helps to solve a compounded problem - when the system needs swap space for data, it saves memory by dropping and reloading program pages. If it has to reload swap pages, and program pages from the same disk, the disk head will be flying between partitions. However this is just a thought for those who have the choice.

If you are building a high spec machine, you should probably install binary and data files in a way that pushed them into one cylinder group, so that disk head movements are minimised.

How ? I don't know. Why ? Basically if all your main files fit into the first 100 MB, and your disk is 2 GIG, the head has to move 100/2000 of the width of the disk. ie 1/20, making the disk access time upto 20 times faster (350/2000 is 1/6).

You heard about it here first!

3.5

Deleting partitions

Not all versions of DOS FDISK can delete NON-DOS partitions. Linux can. IE an old DOS cannot delete a Linux partition, you need the BOOT/ROOT pair to run the linux fdisk, or a newer DOS.

Alignment to cylinder boundaries

Partitions are supposed to start on cylinder boundaries (head 0 sector 1), obviously the first partition has to leave room for the boot sectors, so the first track is left, and it starts with head 1 sector 1.

Some people wax-lyrical about disk performance when it IS or IS NOT aligned to track or cylinder boundaries. Outside of the operating system indexes, this is rubbish. Modern SCSI and EIDE drives have a geometry that VARIES. It's not a spiral, but the number of sectors per track varies depending on which track you are on. The drive itself lies about it's own geometry, by saying it has a SINGLE number of sectors per track, the truth is that the number of sectors per track varies, depending on which track you are on.

For this reason, the operating system cannot even be certain that a system buffer holds a 'single' track (or cylinder). It is 99% certain that 1 expected full track is broken across two real tracks, with a tiny head step between them.

Deep down, the operating system knows this, and simply requests sector 123456 of zillions, in a virtual linear space.

However the maths all comes out in the wash, especially when the drive's internal cache comes into play, and an optimizing OS will get it as close as can be.

In addition, modern drives do their own bad-block re-mapping, so occasionally a disk access will be invisibly diverted away from a scratched block to a previously reserved sector. NOTE: the disk does this itself, if it knows the sector is faulty. You still need to run mke2fs -c with the -c option to check each sector, and build a Linux list of bad blocks that the drive doesn't know about.

The 'active' partition tag, is used by software to pick which disk partition to boot (especially useful for DOS). However, the LILO boot-linux-loader can sit on any primary partition, and is a much easier way of selecting which partition to boot, and even which kernel to load.

If you decide to get rid of Linux, and revert to plain DOS, use the dos FDISK /MBR to write the DOS master boot record over the LILO boot code. OR leave LILO to boot DOS! Having to reload your DOS now, will tell you later that you DO have the correct set of disks to do it!

My LILO is installed over the master boot record (sector 0?) of the first disk, but you can put it as the first sector of a partition (or extended partition), LILO doesn't mind. In that case, the MBR boot code will be provided by DOS, OS/2, SVR4. system commander, or other (eg LILO!).

Both the DOS and LILO are split into two. The MBR block simply finds a second block to boot. DOS goes to the 'active' partition and boots the formatted system disk, or the LILO second part (which - thanks to careful coding - can also be the LILO 'first' part).

You can boot DOS from LILO, and vice verse. OS/2 and SVR4 may be more polarised. I don't have a win95 (WIN-311 + TCP/IP is OK for me).

I think that LILO is great, but it is infamous because it USED to have bugs, and it can leave the system unbootable if you drive it wrong. A prepared BOOT diskette is usually enough to get access to the CD to re-create a lost LILO diskette. A second machine can make that easier.

Chaining MBR's and BR's may be necessary with other operating systems, if in doubt, load Linux second as a taggable partition, and use the boot manager on the fussy system.

3.6

FDISK when INSTALLING LINUX

So now you're ready to meet fdisk, which is available on the BOOT + ROOT disk pair (see earlier in sys-build). It's just a plain text menu that does a simple job. The curses based version cfdisk does the same job, but pretends to make it easier by telling you less.

You will actually be using FDISK later, as part of the sys build.

Create new partitions, of the desired size, that start on logical cylinder boundaries. Set the partition id tags correctly. Remember the 1024 cylinder limitation (especially for DOS and LILO booting).

You can run mke2fs or mkswap on the partitions now, skip the next section.

3.7

FDISK using lies

Do not do this. This is a naff idea. I don't want to do it again, but I don't want to delete this text. It's a description of something that may have happened to a disk, not a recommendation of what to do to it.

It's for those systems that need more that 1024 cylinders for DOS, and don't have the drivers, so they DOUBLE the CHS ratios (needing only 600 cylinders or so).

Instead you should create a 10M boot partition and DOS upto 1024 (if that's what you want). After the 10M boot, linux doesn't mind, and it's better to not cause confusion by faking strange disk geometries. If you can, skip this and goto the next section.

Here is a sample session that prints out the tables for a system that uses disk-head-count doubling to fool BIOS. It's so that the warning messages won't scare you.

To view a disk with 16 heads used as a 32 head by BIOS: From the fdisk X menu set h option to 32 (or 48 or 64!).

fdisk will then make sense of the disk layout, when it has 'that' number of heads. Then create or delete partitions using that distortion option.

I don't know how change to heads to normal, without backing up and restoring all data. I guess you'd just double the information recorded in the fdisk tables to reflect the correct values, and hope you didn't get it wrong, and that it wasn't a bad idea. I relocated the data, and rearranged the disk.

##############################################################
##
## SAMPLE RUN OF FDISK TO SHOW 1024 CYLINDERS PROBLEM
##
##
## FDISK detects genuine geometry
##
## these comments are added later
##############################################################

root@trix> fdisk /dev/hda

This disk is larger than 1024, and may cause problems with:
1) software that runs at boot time (e.g., LILO)
2) booting and partitioning software form other OS's
   (e.g., DOS FDISK, OS/2 FDISK)

	##
	## show me the helpful menu
	##

Command (m for help): m
Command action

   a   toggle a boot-able flag			### 'active'
   c   toggle the dos compatibility flag
   d   delete a partition			### NOTE
   l   list known partition types
   m   print this menu
   n   add a new partition			### NOTE
   p   print the partition table
   q   quit without saving changes
   t   change a partition's system id		### NOTE
   u   change display/entry units
   v   verify the partition table		### NOTE
   w   write table to disk and exit
   x   extra functionality (experts only)	### second menu

	##
	## print out the fdisk partition list
	## also tells you
	##   16 heads
	##   63 cylinders
	## 1049 cylinders
	##

Command (m for help): p

Disk /dev/hdc: 16 heads, 63 sectors, 1049 cylinders
Units = cylinders of 1008 * 512 bytes

   Device Boot  Begin   Start     End  Blocks   Id  System
/dev/hdc1           1       1      48   24160+  82  Linux swap
Partition 1 does not end on cylinder boundary:
     phys=(23, 31, 63) should be (23, 15, 63)
/dev/hdc2          25      49    1048  504000   83  Linux native
Partition 2 does not end on cylinder boundary:
     phys=(523, 31, 63) should be (523, 15, 63)

	##
	## that looks scary to me
	## goto extended/expert mode and scare myself again
	## before setting 32 heads
	##

Command (m for help): x
Expert command (m for help): m
Command action

   b   move beginning of data in a partition
   c   change number of cylinders
   d   print the raw data in the partition table
   e   list extended partitions
   h   change number of heads
   m   print this menu
   p   print the partition table
   q   quit without saving changes
   r   return to main menu
   s   change number of sectors
   w   write table to disk and exit

Expert command (m for help): p

	##
	## still_yeuk:
	## still 16 heads:
	##

Disk /dev/hdc: 16 heads, 63 sectors, 1049 cylinders

Nr AF  Hd Sec  Cyl  Hd Sec  Cyl   Start    Size ID
 1 00   1   1    0  31  63   23      63   48321 82
Partition 1 does not end on cylinder boundary:
     phys=(23, 31, 63) should be (23, 15, 63)
 2 00   0   1   24  31  63  523   48384 1008000 83
Partition 2 does not end on cylinder boundary:
     phys=(523, 31, 63) should be (523, 15, 63)
 3 00   0   0    0   0   0    0       0       0 00
 4 00   0   0    0   0   0    0       0       0 00

	##
	## Now I'm seriously worried
	## gimme rose tinted specs please
	## 32 heads is double 16
	## Change number of heads and list again
	##
	## 32 heads:

Expert command (m for help): h
Number of heads (1-256): 32

print:
Expert command (m for help): p
phew:
Disk /dev/hdc: 32 heads, 63 sectors, 1049 cylinders

Nr AF  Hd Sec  Cyl  Hd Sec  Cyl   Start    Size ID
 1 00   1   1    0  31  63   23      63   48321 82
 2 00   0   1   24  31  63  523   48384 1008000 83
 3 00   0   0    0   0   0    0       0       0 00
 4 00   0   0    0   0   0    0       0       0 00

	##
	## thats better
	## return from 'expert' mode sub-menu
	## and list again
	##

Expert command (m for help): r
Command (m for help): p

Disk /dev/hdc: 32 heads, 63 sectors, 1049 cylinders
Units = cylinders of 2016 * 512 bytes

   Device Boot  Begin   Start     End  Blocks   Id  System
/dev/hdc1           1       1      24   24160+  82  Linux swap
/dev/hdc2          25      25     524  504000   83  Linux native

	##
	## future's so bright
	## we gotta wear shades
	## - or not -
	##

Command (m for help): q
root@trix:~# 

#################################################################

Remember that the above is only something you need to do, if you have to comply with DOS, and 1024 limits. Personally, I prefer to create a 10 MB BOOT partition below 1024, and also to create the DOS partition below 1024, without doubling (gives 0.5 GIG to DOS).

An interesting point, noticed by Ken Kragh, is that when fdisk accepted the heads doubled to 32, it didn't halve the reported number of cylinders in the header. This may be an fdisk bug, or a useful reminder of the original disk's values.