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

Zeth

November 29, 2009
Hi Jordan, yes that URL is gone now. I have a new contact form on this site.
Python CGI contact forms

Jordan

November 29, 2009
Zeth attention! Your form, http://zeth.me.uk/contact/, is not working The explorer says connecting ..but nothing happens Sorry for my poor English: I am Spanish Regards
Python CGI contact forms

Jordan

November 26, 2009
Sorry: tell me , not tellme (I'm spaniard) And http://zeth.me.uk/contact/ don't work
You got the touch, you got the power

David Jones

November 25, 2009
Your mad skillz are too l33t! for me. I specifically switched to Google Reader so that I could show people what blogs I read. But I couldn't work out how ...
How to find the fashionable blogs quickly

Brian R. Hickey

November 20, 2009
Symantec picked it up too.
How to bring down Internet Explorer with six words

Zeth

November 17, 2009
Thanks djm, I am the moose here. Christian, assuming one actually does Internationalise the countries, it should still work I guess, as the gettext stuff will happen before the list ...
Countries in Django

Phillip Temple

November 17, 2009
Good start, but: a) wouldn't I want None back rather than 'ZZ'? b) why not add a 'shortcut' boolean, then prepend flagged fields (plus usual '-----' separator) to the actual ...
Countries in Django

djm

November 17, 2009
Am I being a moose or did you mean: from whatever.countries import CountryField instead of from whatever.countries import CharField ? Good post though, cheers.
Countries in Django

Christian Joergensen

November 17, 2009
Wouldn't the ordering get messed up after i18n?
Countries in Django

Steve - Electronic Cigarettes Fan

November 17, 2009
Very well done. Is your blog just you writing? Nicely done, Steven.
Blogger vs Wordpress

vetetix

November 15, 2009
Sorry to bother you nearly two years after you wrote this blog article, but I can't manage to find how to modify an existing field. I am trying to change ...
Three Useful Python Bindings - ClamAV, Apt and Evolution

Manju

November 4, 2009
I am transferring some files using psftp to other device's FAT partition. But the filestamp of the file being transferred is modified to that of FAT device, after the transfer. ...
PuTTY Series: Using PSFTP

iki

November 2, 2009
or simpler: socket.gethostbyname_ex(socket.gethostname())[2]
How to find out your IP address in Python

iki

November 2, 2009
local_ip = set([ i[4][0] for i in socket.getaddrinfo(socket.gethostname(), None) if i[0] == 2 ])
How to find out your IP address in Python

Fred

November 2, 2009
testing rst ------------- - point 1
An Introduction to ReStructuredText

Ano

October 27, 2009
"You simply found the license of the StumbleUpon Toolbar for Internet Explorer." That's possible. I've got some more interesting information to add. Firstly, go to this page: https://addons.mozilla.org/en-US/firefox/addon/138 - this ...
Are your Firefox extensions proprietary software?

Ken

October 21, 2009
Stumbled in here at lunch. This is the best find of the week. Thanks.
Three classic command line tips

Jim

October 19, 2009
Thanks for the rtsp:// post - that's something that has been bugging me for a while!
Three classic command line tips

Zeth

October 18, 2009
Thanks for the comments guys. Great to see the all the gang are still here!
Three classic command line tips

Bubba

October 18, 2009
Is there any way psftp can return the true transfer rates oberved during the actual transfer?
PuTTY Series: Using PSFTP