From Windows-Wimp to Command-Line Warrior. Part 11: Disk Partitioning, Gentoo handbook, page 4
1 September 2005
Earlier we looked at making room for the Gentoo install. Now we are going to use that space to make some partitions for the Gentoo system.
Read chapter 4 now, it outlines how to use the 'fdisk' tool to make some partitions and how to format those new partitions with valid filesystems.
This post is rather long. If you have installed a GNU/Linux system before and understand the explanation in the Gentoo handbook, then you probably don't need to read this. I have gone into extreme detail because it is important to understand what you are doing when it comes to making serious changes to your hard-disk.
An example setup
To see what this all means, lets use an example. I will now use the following command on my test pc,
> fdisk -l
This command lists all the information that fdisk knows. The first part of the results are some helpful information about the disk, its size and so on. After that we have a little table:
Device Boot Start End Blocks Id System /dev/hda1 * 1 3824 30716248+ c W95 FAT32 (LBA) /dev/hda2 3825 6863 24410767+ c W95 FAT32 (LBA)
The disk is an IDE disk called /dev/hda. At the moment this disk has two FAT32 partitions that are used by Windows, the first partition is called /dev/hda1, and the second is called /dev/hda2. I have decided to get rid of the second one and I have made sure there is nothing important there.
If you have a Sata or SCSI drive then your disk will be called something like /dev/sda (for the first disk, sdb for the second, sd, sdd etc). The fdisk -l command above will tell you what you have.
To begin changing the disk, I typed the following command:
> fdisk /dev/hda
This command opens an interactive version of fdisk for the hard-drive called 'hda'. After a somewhat irrelevant warning that I have a big disk that will not work with some versions of MS-DOS, Fdisk gives me a prompt like this:
> Command (m for help):
Typing 'm' gave me a full list of commands and typing 'p' printed out the table of partitions (the same as the table above). Next I pressed 'd' to delete a partition and then typed '2' to choose the second partition (called /dev/hda2).
Now my hard disk has only one partition, the Windows Partition:
Device Boot Start End Blocks Id System /dev/hda1 * 1 3824 30716248+ c W95 FAT32 (LBA)
(Note that Windows offers two filesystem formats, FAT32 and NTFS, so if your Windows partition is NTFS then it will say something like that, rather than FAT32).
Choosing Gentoo's partition sizes.
It is possible to make just one big partition for a GNU/Linux system. This however is not the normal approach. Here I will create three partitions for Gentoo.
- The /boot partition
The /boot partition (also just called boot) is where your startup files live. This includes Grub (the bootloader) and the Linux Kernel (the part of the GNU system that deals with and controls your hardware). On some other GNU systems (such as Fedora for example), you need to have quite a big boot partition.
Gentoo however requires very little (especially if you cook your own kernel - see later in this series). 32MB will allow you to hoard old copies of the Linux Kernel as you install new versions. If you are really short on space then you could use half of that, say 15MB.
- The Swap partition.
RAM is the computers memory, everything that it is thinking about and working on now. A GNU/Linux system like Gentoo can also have a swap partition which acts like additional RAM.
How big should it be? That is up to you. The time-honoured answer is "twice your RAM". However if you have an extreme amount of RAM then you may not ever need that much, also if you have a small hard-disk then the more that you give to the swap partition then the less you have for everything else.
- The root partition (/)
The root partition, often just called '/', is where everything else goes, give it as much space as you can spare, 1 Gb (just over 1000 or so MB) would be a minimum (I have managed with less than 400MB but it gets a bit painful when updating the system), up to 20Gb would be luxurious.
- Other Partitions.
For a personal workstation or home computer those partitions will do nicely. Some users create lots of different partitions for different things. In this guide we will keep it simple, the handbook offers a number of other schemes that you can read about.
Primary and Extended partitions
To begin adding new partitions, I typed 'n' to make a new partition. Fdisk then offers you a choice between making a primary partition or the extended partition. You can have up to four primary partitions in total, or you can have three primary partitions and a number of logical ones inside the extended partition.
Option 1, max four partitions:
hda1 Primary hda2 Primary hda3 Primary hda4 Primary
Here the disk is split into four primary partitions, which can be any size.
Option 2, partitions:
hda1 Primary hda2 Primary hda3 Primary (hda4 Logical extension) hda5 Logical hda6 Logical hda7 Logical hda8 Logical hda9 Logical ... And so on ..
In this version, the disk is split into three primary partitions, hda4 is split into as many logical partitions as you need (total 15 partition limit on Sata drives). Again all the partitions can be any size at all.
What is the difference between a primary and logical partitions? None for quality operating systems such as GNU/Linux and some BSD systems and so on. However DOS based systems such as Microsoft Windows may not like being put on a Logical Partition, so it is best put on a primary partition.
I created two more primary partitions, one for swap and one for boot. I then created the logical extension to fill the rest of the disk. I then made a logical partition inside the logical extension. In summary, here is what my disk looks like now:
Device Boot Start End Blocks Id System /dev/hda1 * 1 3824 30716248+ c W95 FAT32 (LBA) /dev/hda2 3825 4068 1959930 82 Linux swap / Solaris /dev/hda3 * 4069 4073 40162+ 83 Linux /dev/hda4 4074 19457 123571980 5 Extended /dev/hda5 4074 5411 10747453+ 83 Linux
The first partition holds Windows. The second partition is the GNU/Linux swap partition, I used the fdisk 't' command to change it to a swap partition (the hex code is 82).
The third partition is the boot partition, I used the 'a' command to make it a bootable partition (note that Windows needs to be bootable too). The fourth partition is the logical extension (which you completely forget about in day to day life).
The fifth partition is the root (/) partition where all the programs and files will go. I have saved a bit of room on the disk for a rainy day, in the future I will want to make more logical partitions and because I have used the logical extension I am able to.
Once you have setup your disk the way you want it, don't forget to write the table to disk using the 'w' command, otherwise you will have to do it all again!
Formatting the filesystems
Once your partitions have been setup, you need to format them with a filesystem.
There are more filesystem types than I care to know about. The main ones for any system are ext2 and ext3. For PPC (Apple Macs) there is also the HFS filesystem (alongside the above). ReiserFS, XFS, JFS are other potential filesystems that may (or may not) be available for your architecture, as well as the old FAT32 filesystem for x86 PCs, and many others that I have not bothered to learn about yet.
In this example we will make the boot partition ext2 and the root partition ext3. Ext3 has many advanced features that work well with larger drives; these features however require a little space, so if you already have a very small root partition then you should use ext2.
This command formats the boot partition (hda3) as ext2:
mke2fs /dev/hda3
This command formats the root (/) partition (hda5) as ext3:
mke2fs -j /dev/hda5
To format the swap partition (hda2), use this command:
> mkswap /dev/hda2
Don't forget to turn swap on now so the rest of the install process can use it:
> swapon /dev/hda2
Mounting the disks
The final stage in this marathon is to make the filesystems accessible to the LiveCD so that you can install files on them. This action is called 'mounting'. The first step is to mount the root partition:
> mount /dev/hda5 /mnt/gentoo
Then you need to make a boot directory in the root partition:
> mkdir /mnt/gentoo/boot
Next you need to associate the new boot directory with the boot partition:
> mount /dev/hda3 /mnt/gentoo/boot
If you have got to this point, well done, you have succeeded in designing and implementing your own custom filesystem layout. You are well on your way to becoming a Command Line Warrior!
Another way altogether
If you have found the above just too confusing, don't worry! Just type in the command 'cfdisk' and see it if makes more sense to you. Cfdisk is a menu- based way of setting up your hard-drive.



1 John Marshall says...
Does using MSDOS fdisk work with gentoo? If so how do I install gentoo into the partition I created with MSDOS? John
Posted at 7 a.m. on June 17, 2007