Partitioning
Installing Gentoo - Partitioning
Linux has a very simple yet elegant tool to set up the partitions on your hard drive called fdisk. This is similar to the legacy dos-based fdisk.exe application, with the exception that it is very fast, supports almost all hard disk devices, and actually works. In case you didn't read the previous section, make sure you disconnect any drives containing precious data before proceeding.
Before you can start partitioning, you need to determine what the system recognized your hard drive as during bootup. There are three general types of device nomenclature for system disks, depending on the hardware type, interface type, and kernel version. To accommodate multiple devices, the Linux kernel enumerates devices using letters. Traditionally,
- hdx -> IDE devices. The first device would be hda, the second hdb, and so on. IDE CDRoms will also fall under this paradigm.
- sdx -> SATA devices. The first device would be sda, the second sdb, and so on.
- mdx -> RAID devices. You'd have to set this up in a later step; for now, one of the above should apply.
If you aren't sure what type of device you have, IDE hard drives have a wide ribbon cable about 2 inches wide and a standard power connector, where SATA drives have a smaller cable attachment and different type of power connector. If you are virtualizing Gentoo, chances are the virtual hard disk controller is IDE/ATA, so your virtual hard disk will be recognized as /dev/hda. Most new systems utilize SATA drives so that is what we will use as an example in this guide. The first device detected via a SATA connection would be designated /dev/sda.
A note on partitions
While many partitioning configurations are possible, this guide focuses on partitioning the primary hard disk into three partitions: a boot partition, a swap partition, and a root partition.
The boot partition is a small partition that houses your system boot manager, such as GRUB or LILO, and the Linux kernel. While it is possible to have the boot manager and kernel on the same partition as the root, it isn't advisable since if the partition becomes corrupt, or you overwrite your files, your system can no longer boot. Keeping a small, separate boot partition is an excellent way to ensure you'll be able to boot and perform maintenance on your system no matter what happens.
The swap partition is an area dedicated as a work area for the kernel. Its equivalent in Windows would be the pagefile, otherwise known as "virtual memory", which Windows will expand as it sees fit (often to the point of filling your disk). Obviously, the more swap space available to the kernel, the easier it will be for it to manage the swap space. Choosing the size of the swap partition also depends on how much RAM is installed in your system. If you don't have a lot of RAM, a bigger swap partition is advisable. In this example, we'll use a swap partition size of half a gigabyte: 512M.
The root partition would be the equivalent of your C: drive in Windows. It contains the base Linux system components, and serves as an object to which other partitions can be mounted. Some users like to spread the Linux filesystem over multiple drives and partitions, but in this example we will keep it simple and simply fill the remainder of the space on the disk with the partition we'll use for root.
To start fdisk and begin partitioning your hard disk,
# fdisk /dev/sda
...where /dev/sda is the alias the system has assigned for your hard disk. You'll now be greeted by the fdisk shell. You can type m to see the commands that are available to you. If you have existing partitions, you may want to delete them by entering d. Once any existing partitions have been removed from the disk, we will start by creating the boot partition.
Command (m for help): n
We are creating a standard partition
Command action e extended p primary partition (1-4) p
This will be the first partition
Partition number (1-4): 1
We want to start at the first block, so press enter at the next prompt. (Note the value of ? depends on the size of your disk.)
First cylinder (1-?, default 1):
Next we set the size of the boot partition to 64 megabytes.
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-?, default ?): +64M
Since this is our boot partition, we'll need to set it to active.
Command (m for help): a Partition number (1-4): 1
We've now created our boot partition. Now we'll set up the swap partition.
Command (m for help): n Command action e extended p primary partition (1-4) p
This will be the second partition in our configuration
Partition number (1-4): 2
As before, press enter at the next prompt, starting the partition at the next available block, and make the partition 512 megabytes in size.
First cylinder (?-?, default ?):
Using default value ?
Last cylinder, +cylinders or +size{K,M,G} (1-?????, default ?????): +512M
For the kernel to recognize this partition as a swap partition, we'll need to set the correct partition type.
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris)
Now that we've created the boot and swap partitions, we'll create the root partition using the rest of the space on the disk.
Command (m for help): n Command action e extended p primary partition (1-4) p
This will be our third partition
Partition number (1-4): 3
At the next few prompts, just press enter to go with the defaults, which will start the partition at the next available block and utilize all the remaining blocks.
First cylinder (?-?, default ?):
Using default value ?
Last cylinder, +cylinders or +size{K,M,G} (1-?, default ?):
Our partitions have now been created. But before we can apply filesystems to them, we'll need to save our partition layout and let fdisk apply them to the physical device.
Command (m for help): w
Optional: using RAID
At this point you have the option to use mdadm, the software RAID package for linux, if you have multiple drives.
Once fdisk has finished creating the new partitions, we'll be ready to Apply Filesystems.