Anatomy of a hard drive: what really goes on inside your PC's storage

Cut out and keep: emergency partitioning

The fdisk program is much like the Vi text editor, but for partitioning: it's terse, minimal and available in virtually every distro. Start it (as root) by providing a drive path (to the device node) like this:

fdisk /dev/sda

In a typical Linux installation, /dev/sda refers to the first hard drive, while /dev/sdb refers to the second, and so forth. Enter p and you'll see a list of partitions on the drive, as in the screenshot.

Note here the Start and End columns, which show sectors in use. Each partition has a number, so sda1 is the first partition on the first drive, and sdb3 is the third partition on the second drive.

To delete a partition, enter D and you'll be prompted for the number.

To add a new partition, enter N. You'll be asked whether to make it primary (maximum 4) or extended; go for the former if you have room, for simplicity's sake.

Then enter a start sector number (taking into account the list earlier) and size. Back at the main prompt, enter P and you'll see the new partition in the list.

It has no ID at the moment, though, so enter T, then the partition number, and then Shift+ L to list available types. Enter 83 for a Linux partition, 82 for a swap partition, or 7 for a Windows (NTFS) partition. Now enter W to write the changes to disk, or Q to quit without writing.

Linux and Windows partitions on a hard drive

>An fdisk session, showing the Linux and Windows partitions on a hard drive.

A separate /home: yes or no?

One of the biggest choices you face when installing Linux and partitioning a hard drive is this: do you put the / home directory on a separate partition?

This is where user files live - that is, personal documents and settings for user accounts, as opposed to operating system files, which live in separate directories.

Some Linux distributions recommend using a separate partition, whereas others default to dropping everything into the same partition. So, what do you do? The answer depends on how you want to use your machine.

If you plan to try many different distros, and you're often installing new ones over the top of old ones, then it makes sense to have a separate /home partition.

In this way, you can do what you like with the operating system - upgrade it, downgrade it, or wipe it all and try some random new distro from the Faroe Islands.

Whichever Linux flavour you happen to be running, your personal files will always be there, stored safely on a separate part of the disk.

If you're careful, you can even have multiple Linux distributions on the same machine, all using the same partition for the /home directory after booting.

But why do we say you have to be careful? Well, think about settings and configuration files. If you do an ls -a in your home directory, for instance, you'll see a large number of hidden files and directories starting with full-stops - these store settings for programs. If you try to use the same settings between different versions of a program, it can really confuse that program.

For instance, let's say you have Distro A and Distro B on your machine. You boot Distro A and run FooProgram 2.0 for the first time, which creates a .fooprogram/ settings folder in your home directory.

Then you boot Distro B with the same home directory, and start FooProgram - but in this case, it's version 1.0. It'll get confused by differences in the configuration files, and could crash or corrupt data. Another potential problem with separate /home partitions is the size constraint.