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.

  1. 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.

  1. 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.

  1. 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.

  1. 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


What do you have to say?

Show Editing Help

About

Hello, my name is Zeth, I'll be your host here.

Command Line Warriors is about taking control of your own technology, it looks at our experiences of computing; especially using GNU/Linux, the Python programming language, the command-line and issues such as techno-ethics, best practices and whatever is cool now. If you take control of your technology then you are a Warrior too!

This site is your site too which means that you can contribute and get involved. You can leave comments using the facility provided. For me, the comments and discussions are by far the best part of the site. So please do have your say!

Latest Discussions

Cupcake

July 31, 2010
Good post! You helped me a lot with my school project! CountryField(blank = True) < (K)
Countries in Django

LeshaShampoo

July 30, 2010
it was very interesting to read commandline.org.uk I want to quote your post in my blog. It can? And you et an account on Twitter?
Email Syntax Check in Python

vemma2018

July 30, 2010
I find myself coming to your blog more and more often to the point where my visits are almost daily now!
On Comment Spam

layecenda

July 30, 2010
Hello. And Bye.test :) http://idfjhvihdfiphvlajbvhalibv.com
PuTTY Series: Adding PuTTY to your system path

scuba

July 30, 2010
I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.
On Comment Spam

Businesking

July 30, 2010
Great site and articles for hack for win, I said Amazing post
How not to program WSGI

Tehnoking

July 30, 2010
This is Great post to learn about the hack Thumbs-up for you :D
How not to program WSGI

Syabiltech

July 30, 2010
I think this articles for master...because very hard to learning, As blogger beginners like me.
How not to program WSGI

coffeeatea

July 30, 2010
Are you looking for coffee gifts? We can tell you more about the coffee gifts including coffee machines and coffee pods.
Introducing Soturi - yet another Django blog application

noni juice

July 30, 2010
I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.
On Comment Spam

Dion Moult

July 29, 2010
What I do know is that ever since I tried out Opera and put their tab bar on the left as a column, I've loved that layout. Back on Firefox ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

ZonaEntertainment

July 29, 2010
Wow useful articles, I'm read to learn about this and now I bookmark this to my Facebook, thanks for share!
How not to program WSGI

Giacomo

July 29, 2010
Honestly, I think both Mozilla and you are wrong :) This sort of concept adds overhead. A user would have to manage all this crap, constantly dragging and dropping, creating ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

Matija "hook" Šuklje

July 29, 2010
As a minimalist, you'll probybly moan if I mention KDE, but I'll do so anyway ;) The future I want (and actually see slowly fold out before me) is to ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

tahitian noni

July 28, 2010
Thank You For This Blog, was added to my bookmarks.
On Comment Spam

Rick

July 28, 2010
I already have piles. It's called A New Window.
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

Tech News

July 25, 2010
Thanks for this short tutorial...was auto-FTPing my files from my appserver to webserver for my tech news website. Everything was OK until someone hacked it. Hosting provider is now recommending ...
SFTP in Python: Really Simple SSH

naypalm

July 24, 2010
During the past 3-4 years, I and many others have enjoyed unlimited 2G/3G internet. But ever since the massive cult-like following of i Phone users in the US, most cellular ...
Calling time on mobile internet nonsense?

Steve

July 15, 2010
Very occasionally, you will run into a Java program that uses a lot of memory just to hold all the classes used. It turns out that the JVM uses a ...
Three classic command line tips

no

July 14, 2010
1. number one 2. number two 4. number four 3. number three 6. number six # first # second ## second-ay ## second-bee ### second-bee-one ### second-bee-two
An Introduction to ReStructuredText