####[ How-Do-I Documents ]######################################
Sub : Initial Partitioning
How-Do-I do partitioning of my IDE Hard disk for a first-time
Linux install on a system with pre-existing Windows ?
################################################################
1 Introduction
1.1 This is a very common problem faced by most newbies. To
make matters more complicated, newer generation distros
with their "magic" intelligent mechanisms, make a hash
of things ... only to regret ... when it is too late.
1.2 The normal scene is something like this. Joe Ramaswamy
has a relatively new computer which came pre-laden with
Windows of some type. Either his neighbour gave him a
Linux distro, or one came along "free" with one of the
monthly computer mags ... and now he is prepared to try
out Linux on his spare E: or F: ... his friend confirms
that this can be done ... and the new distro with its
"intelligent" mechanisms and GUI installs confirms that
this is very much in order ....
2 The genesis of the problem
2.1 Joe sees things as C:, D:, E: etc, and his hard drive
adequately partitioned. What he does not know is the
fact that any fdisk under M$ has two problems:
o There is only ONE primary partition (which is taken
up by the M$ OS itself) with its boot loader on the
MBR (Master Boot Record) ... All other partitions are
made as Extended logicals.
o There are times when the partition boundaries are not
written correctly. Some versions of MS-DOS create a
first partition which does not begin on a cylinder
boundary, but on sector 2 of the first cylinder.
2.2 He diligently moves all his data from E: to D: and then
gets into the act of installing the Linux to E: or to
(/dev/hda6 as he learns on the way). His new distro, as
per claims does a perfect install. He even makes a boot
disk .... everything seems okay ... he can dual boot !
2.3 With some experience he has learnt that it is better to
have a separate /home (or even /usr). So he wants to
repartition. Runs disk-druid or cfdisk ... and Lo ! He
probably did something that he did not know, and now
the D: is not accessible !
3 Understanding the problem
3.1 The problem was that when the second OS (Linux) was in-
stalled, it was put in an extended-logical partition by
the intelligent new distro. The boot record was written
to the first sector of the EXTENDED partition. If he
was doing a dual boot through LILO it is obvious that
the MBR also had LILO record.
3.2 Every PRIMARY partition has its own boot record ... but
all the Extended-Logical partitions have only ONE boot
record, that of the mother EXTENDED partition. There is
no chance that a third boot record can be written. When
one re-partitions an extended partition, the partition
info is re-written on the boot record of the Extended
partition, which may result in loss of ALL data coming
under the EXTENDED partition inclusive of all logical
partitions coming under it. The only scope of recovery
is restoring the original configuration if the bounda-
ries are known.
4 Background to the solution
4.1 Every IDE hard disk can accept upto FOUR primary or
THREE primary and ONE extended partition. No hard disk
can have two Extended partitions ... there is no need
actually, because an Extended partition can have an
unlimited number of logical partitions under it.
4.2 M$ literature (for some reason) states that M$ fdisk
supports only ONE primary partition, and therefore it
creates only one, and makes it bootable. An undocu-
mented feature of MS-DOS 5.0 onwards is that multiple
Primary partitions are very much supported and can be
used by M$. Its own fdisk,however, does not create such
a system.
4.3 The golden rule is stated LOUD and clear:
"EVERY BOOTABLE OS SHOULD BE INSTALLED IN ITS OWN PRI-
MARY PARTITION WITH ITS OWN BOOT RECORD".
4.3.1 This avoids all boot-sharing conflicts. The role of
Extended partitions should be restricted for data and
swap only.
5 How to go about doing it
5.1 There is a major problem here. Since Joe already has a
working M$ system, he knows how to operate M$ fdisk ...
but that is inadequate here. The default installation
process of the intelligent GUI distro may not provide
for enough flexibility to do things manually .. Some do
provide for non-GUI access to legacy Linux fdisk, but
in may the fdisk program is symlinked to cfdisk or some
other "user-friendly" partitioning tool. Then, what is
the way out ?
5.2 Partition the HDD using a stand alone floppy based dis-
tro, using legacy linux fdisk program, and then install
the distro without further re-partitioning. There are
some strategies to be employed when calculating for the
space to be kept in various Linux partitions. These are
dealt in detail in another HDI.
5.3 For a stand-alone personal box there is no need to have
major sub-divisions into separate partitions. One large
/ (root), a reasonable /home and /swap is adequate. The
approximate space which should be catered for is:
o / (root) .... 2 to 4 GB, PRIMARY partition only.
o /home .... 500mb to 1 GB, Extended-logical will do
o /swap .... 2 to 3 times physical RAM. Extended log-
ical will also do.
5.4 The following disk sets are adequate, and provide for
the necessary tools to achieve the above:
o Slackware (root and boot disk sets)
o alfalinux (floppy based 2 disk distro)
o tomsrtbt (single floppy stand-alone distro)
5.4.1 All these are available off the net. The exact URL is
not being stated because versions change. Slackware is
available at http://www.slackware.com. The links for
the others can easily be found by searching at google
(http://google.com). All of the above cater for the
legacy linux fdisk program ... a bit terse, but defini-
tely the most flexible, and powerful.
6 Running fdisk
6.1 After you have booted, you are free to run fdisk with
the command:
#fdisk /dev/hda [obviously hda should be your target
drive (viz. Primary Master)]
6.2 Once in fdisk prompt, type in m (for menu) ... You will
get an output like this for help:
localhost:~#fdisk /dev/hda
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this men
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help):
6.3 The first command after this should be "p" (print part-
ition table). This will list your existing "/dev/hda1"
(C: under M$) as primary .... /dev/hda4 is the Extended
partition, and /dev/hda5 onwards are the logicals which
are placed under it. By all probabilities /dev/hda5 is
your existing M$ [D:].
6.4 To create three Primaries and ONE large extended, the
full Extended partition would have to be deleted. If
you have valuable data in M$ D: or E:, make sure these
are carefully backed up under temporary dirs under C:
6.5 After removing ALL essential data, and you are prepared
to delete the extended partition use the "d" command.Do
NOT touch partition No 1 even by mistake. That is your
M$ C:. You can do anything with Partition #2 onwards.
Once the mother Extended partition is deleted, all the
extended logicals under it are killed.
6.6 Now, play around with the "n" command, and create new
partitions. Remember as long as you do not touch the
first partition, or issue the "w" write command, you
can do no harm. Make, delete, do what you want. It is a
great learning experience for which you would be grate-
ful forever.
6.7 Once your partitions are created and you are happy that
it is as per your plans, press "q" and quit. This time
use your intelligent GUI based distro and install with-
out further partitioning. Make sure you mark the parti-
tion for Linux partitions carefully with the "t" comm-
and (Type 82 for swap and Type 83 for Native Linux is
to be clearly marked). Keep the bootable flag at hda1
presently.
7 A word of caution
7.1 Linux needs at least one partition, namely for its root
file system. It can use swap files and/or swap parti-
tions, but the latter are more efficient. So, usually
one will want a second Linux partition dedicated for
swap partition. On Intel compatible hardware, the BIOS
that boots the system can often only access the first
1024 cylinders of the disk. For this reason people with
large disks often create a third partition, just a few
MB large, typically mounted on /boot, to store the
kernel image and a few auxiliary files needed at boot
time, so as to make sure that this stuff is accessible
to the BIOS. There may be reasons of security, ease of
administration and backup, and testing to use more than
the minimum number of partitions stated above.
7.2 If your current /dev/hda1 (C:) is large, obviously, it
will be beyond the 1024-cylinder limit. My personal ad-
vice is to leave things alone. Do NOT try to carve a
/boot out of it, you are likely to damage C: for good.
There are programs like "fips" which do non-destructive
partitioning of M$ partitions. Remember, fips is okay
for 16 bit DOS for which it was made. 32-bit handling
capacity was appended in 1997, after which development
was ceased. It does not work for HPFS/ NTFS, so if your
M$ is NT, 2k or XP, fips is totally out.
7.3 You must be conscious of the fact, that you are likely
to have the 1024-voodoo problem if /dev/hda1 crosses
the 1024 cylinder BIOS limits, and may take the necess-
ary precaution of avoiding placing LILO (Linux Loader)
record on the MBR. Some of the newer BIOSes and LILO
versions beyond 22.x do not have the 1024-voodoo prob-
lem. This you will know by trial and error.
7.4 In case of suspicion of 1024-voodoo the recommendations
are:
o Install LILO on the 1st partition of the / partition
or /boot (if you created a separate one). Do NOT put
LILO record on the MBR.
o Make at least two boot floppies, so that you can boot
into Linux through bootable floppies.
o If the M$ installed is NT/ 2k/ XP, NEVER dual boot
with LILO. It is much easier and more elegant to mod-
ify boot.ini under M$, and achieve multiboot through
the M$ boot sequence. There is an HDI dedicated to
this aspect as well.
o Even if the M$ is plain DOS-5.x and beyond with Win-
3.1 or Win-9x/ ME, you can always dual boot with the
help of Loadlin, run from the M$ partition. Loadlin
has some distinct advantages:
- Can boot Linux from an UMSDOS install (on native M$
partition)
- has No 1024-voodoo problems
- like LILO and other boot loaders it can load Linux
from second or third hard disk as well
- Can boot QNX and BeOS without fuss
[Note : There is a HDI, dedicated to loadlin as well].
7.5 Once you have some experience on Linux and want to boot
through the native Linux system (LILO), you can put the
LILO boot record on the MBR with lilo -v. Make sure you
have a M$ rescue disk ready so that you are in a posi-
tion to reset things to M$ boot with "fdisk /mbr", if
things go wrong.
8 Summing things up
8.1 To sum up things, stated above:
o M$ fdisk is unreliable.
o Full Extended partition is to be deleted for a fresh
Linux install
o Do NOT trust any fancy GUI driven installation, do it
the hard way, manually.
o Every bootable OS should be installed in a PRIMARY
partition with its own boot record.
o Partition with the legacy Linux fdisk .. It has NEVER
been known to fail.
o Be conscious of the 1024-voodoo problem.
o Do NOT carve portions out of your existing M$ just to
cater for 1024-voodoo problems.
o If in doubt do NOT put LILO info on MBR (specially if
the M$ OS is NT/ 2k or XP).
o Always make boot floppies.
o Do NOT hanker over inability to achieve a LILO dual
boot. Dual boot through NT loader, and loadlin are
just as effective and less problematic in a dual boot
scenario.
9 Can't I use partition magic ?
9.1 Ofcourse you can. Only remember that partition magic
keeps a wafer size (2 mb) Primary partition for itself.
It can make at best 2 Primary and 1 Extended partition
which can be subdivided into numerous logicals. In this
case too, it is better to crosscheck the partitions cr-
eated with partition magic under Linux fdisk and set
the partition types correctly to 82 and 83.
################################################################
10 Kudos and Brickbats
10.1 This document is released under GFDL/ GPL license. You
are free to use and distribute this under terms of the
above license.
10.2 Any kudos and brickbats should be directed at:
USM Bish
29 Dec 2001