|
1.
Introduction to Block Devices
Block Devices
We'll take a good look at disk-oriented aspects of Gentoo Linux
and Linux in general, including Linux filesystems, partitions and block devices.
Then, once you're familiar with the ins and outs of disks and filesystems,
you'll be guided through the process of setting up partitions and filesystems
for your Gentoo Linux installation.
To begin, we'll introduce block devices. The most famous block device is
probably the one that represents the first drive in a Linux system, namely
/dev/sda. SCSI and Serial ATA drives are both labeled
/dev/sd*; even IDE drives are labeled /dev/sd* with
the new libata framework in the kernel. If you're using the old device
framework, then your first IDE drive is /dev/hda.
The block devices above represent an abstract interface to the disk. User
programs can use these block devices to interact with your disk without worrying
about whether your drives are IDE, SCSI or something else. The program can
simply address the storage on the disk as a bunch of contiguous,
randomly-accessible 512-byte blocks.
Partitions
Although it is theoretically possible to use a full disk to house your Linux
system, this is almost never done in practice. Instead, full disk block devices
are split up in smaller, more manageable block devices. On ${arch}
systems, these are called partitions.
Itanium systems use EFI, the Extensible Firmware Interface, for booting. The
partition table format that EFI understands is called GPT, or GUID Partition
Table. The partitioning program that understands GPT is called "parted", so
that is the tool we will use below. Additionally, EFI can only read FAT
filesystems, so that is the format to use for the EFI boot partition, where the
kernel will be installed by "elilo".
Advanced Storage
The ${arch} Installation CDs provide support for LVM2.
LVM2 increases the flexibility offered by your partitioning setup.
During the installation instructions, we will focus on "regular" partitions,
but it is still good to know LVM2 is supported as well.
1.
Designing a Partitioning Scheme
Default Partitioning Scheme
If you are not interested in drawing up a partitioning scheme for your system,
you can use the partitioning scheme we use throughout this book:
| Partition |
Filesystem |
Size |
Description |
| /dev/sda1 |
vfat |
32M |
EFI Boot partition |
| /dev/sda2 |
(swap) |
512M |
Swap partition |
| /dev/sda3 |
ext3 |
Rest of the disk |
Root partition |
If you are interested in knowing how big a partition should be, or even how
many partitions you need, read on. Otherwise continue now with partitioning
your disk by reading Using parted to Partition your
Disk.
How Many and How Big?
The number of partitions is highly dependent on your environment. For instance,
if you have lots of users, you will most likely want to have your
/home separate as it increases security and makes backups easier.
If you are installing Gentoo to perform as a mailserver, your
/var should be separate as all mails are stored inside
/var. A good choice of filesystem will then maximise your
performance. Gameservers will have a separate /opt as most gaming
servers are installed there. The reason is similar for /home:
security and backups. You will definitely want to keep /usr big:
not only will it contain the majority of applications, the Portage tree alone
takes around 500 Mbyte excluding the various sources that are stored in it.
As you can see, it very much depends on what you want to achieve. Separate
partitions or volumes have the following advantages:
-
You can choose the best performing filesystem for each partition or volume
-
Your entire system cannot run out of free space if one defunct tool is
continuously writing files to a partition or volume
-
If necessary, file system checks are reduced in time, as multiple checks can
be done in parallel (although this advantage is more with multiple disks than
it is with multiple partitions)
-
Security can be enhanced by mounting some partitions or volumes read-only,
nosuid (setuid bits are ignored), noexec (executable bits are ignored) etc.
However, multiple partitions have disadvantages as well. If not configured
properly, you will have a system with lots of free space on one partition and
none on another. Another nuisance is that separate partitions - especially
for important mountpoints like /usr or /var - often
require the administrator to boot with an initramfs to mount the partition
before other boot scripts start. This isn't always the case though, so YMMV.
There is also a 15-partition limit for SCSI and SATA, unless you use GPT
labels.
As an example partitioning, we show you one for a 20GB disk, used as a
demonstration laptop (containing webserver, mailserver, gnome, ...):
Code Listing 1.1: Filesystem usage example |
$ df -h
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda5 ext3 509M 132M 351M 28% /
/dev/sda2 ext3 5.0G 3.0G 1.8G 63% /home
/dev/sda7 ext3 7.9G 6.2G 1.3G 83% /usr
/dev/sda8 ext3 1011M 483M 477M 51% /opt
/dev/sda9 ext3 2.0G 607M 1.3G 32% /var
/dev/sda1 ext2 51M 17M 31M 36% /boot
/dev/sda6 swap 516M 12M 504M 2% <not mounted>
|
/usr is rather full (83% used) here, but once
all software is installed, /usr doesn't tend to grow that much.
Although allocating a few gigabytes of disk space for /var may
seem excessive, remember that Portage uses this partition by default for
compiling packages. If you want to keep /var at a more reasonable
size, such as 1GB, you will need to alter your PORTAGE_TMPDIR variable
in /etc/make.conf to point to the partition with enough free space
for compiling extremely large packages such as OpenOffice.
1.
Using parted to Partition your Disk
The following parts explain how to create the example partition layout
described previously, namely:
| Partition |
Description |
| /dev/sda1 |
EFI Boot partition |
| /dev/sda2 |
Swap partition |
| /dev/sda3 |
Root partition |
Change your partition layout according to your own preference.
Viewing the Current Partition Layout
parted is the GNU partition editor.
Fire up parted on your disk (in our example, we use
/dev/sda):
Code Listing 1.1: Starting parted |
# parted /dev/sda
|
Once in parted, you'll be greeted with a prompt that looks like this:
Code Listing 1.1: parted prompt |
GNU Parted 1.6.22
Copyright (C) 1998 - 2005 Free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
Using /dev/sda
(parted)
|
At this point one of the available commands is help, which you should use
if you want to see the other available commands. Another command is
print which you should type next to display your disk's current partition
configuration:
Code Listing 1.1: An example partition configuration |
(parted) print
Disk geometry for /dev/sda: 0.000-34732.890 megabytes
Disk label type: gpt
Minor Start End Filesystem Name Flags
1 0.017 203.938 fat32 boot
2 203.938 4243.468 linux-swap
3 4243.469 34724.281 ext3
|
This particular configuration is very similar to the one that we recommend
above. Note on the second line that the partition table is type is GPT. If it
is different, then the ia64 system will not be able to boot from this disk.
For the sake of this guide we'll remove the partitions and create them anew.
Removing all Partitions
Note:
Unlike fdisk and some other partitioning programs which postpone committing
changes until you give the write instruction, parted commands take effect
immediately. So once you start adding and removing partitions, you can't
simply quit without writing them... they've already been written.
|
The easy way to remove all partitions and start fresh, which guarantees that we
are using the correct partition type, is to make a new partition table using the
mklabel command. After you do this, you will have an empty GPT partition
table.
Code Listing 1.1: Creating a new partition table |
(parted) mklabel gpt
(parted) print
Disk geometry for /dev/sda: 0.000-34732.890 megabytes
Disk label type: gpt
Minor Start End Filesystem Name Flags
|
Now that the partition table is empty, we're ready to create the
partitions. We will use a default partitioning scheme as discussed previously.
Of course, don't follow these instructions to the letter if you don't want the
same partitioning scheme!
Creating the EFI Boot Partition
We first create a small EFI boot partition. This is required to be a FAT
filesystem in order for the ${arch} firmware to read it. Our
example makes this 32 MB, which is appropriate for storing kernels and
elilo configuration. You can expect each ${arch} kernel to
be around 5 MB, so this configuration leaves you some room to grow and
experiment.
Code Listing 1.1: Creating the boot partition |
(parted) mkpart primary fat32 0 32
(parted) print
Disk geometry for /dev/sda: 0.000-34732.890 megabytes
Disk label type: gpt
Minor Start End Filesystem Name Flags
1 0.017 32.000 fat32
|
Creating the Swap Partition
Let's now create the swap partition. The classic size to make the swap
partition was twice the amount of RAM in the system. In modern systems with
lots of RAM, this is no longer necessary. For most desktop systems, a 512
megabyte swap partition is sufficient. For a server, you should consider
something larger to reflect the anticipated needs of the server.
Code Listing 1.1: Creating the swap partition |
(parted) mkpart primary linux-swap 32 544
(parted) print
Disk geometry for /dev/sda: 0.000-34732.890 megabytes
Disk label type: gpt
Minor Start End Filesystem Name Flags
1 0.017 32.000 fat32
2 32.000 544.000
|
Creating the Root Partition
Finally, let's create the root partition. Our configuration will make the root
partition to occupy the rest of the disk. We default to ext3, but you can use
ext2, jfs, reiserfs or xfs if you prefer. The actual filesystem is not created
in this step, but the partition table contains an indication of what kind of
filesystem is stored on each partition, and it's a good idea to make the table
match your intentions.
Code Listing 1.1: Creating the root partition |
(parted) mkpart primary ext3 544 34732.890
(parted) print
Disk geometry for /dev/sda: 0.000-34732.890 megabytes
Disk label type: gpt
Minor Start End Filesystem Name Flags
1 0.017 32.000 fat32
2 32.000 544.000
3 544.000 34732.874
|
Exiting parted
To quit from parted, type quit. There's no need to take a separate step
to save your partition layout since parted has been saving it all along. As you
leave, parted gives you reminder to update your /etc/fstab, which we'll
do later in this guide.
Code Listing 1.1: Quit from parted |
(parted) quit
Information: Don't forget to update /etc/fstab, if necessary.
|
Now that your partitions are created, you can continue with Creating Filesystems.
1.
Creating Filesystems
Introduction
Now that your partitions are created, it is time to place a filesystem on them.
If you don't care about what filesystem to choose and are happy with what we use
as default in this handbook, continue with Applying a Filesystem to a Partition.
Otherwise read on to learn about the available filesystems...
Filesystems
The Linux kernel supports various filesystems. We'll explain ext2, ext3, ext4,
ReiserFS, XFS and JFS as these are the most commonly used filesystems on Linux
systems.
ext2 is the tried and true Linux filesystem but doesn't have metadata
journaling, which means that routine ext2 filesystem checks at startup time can
be quite time-consuming. There is now quite a selection of newer-generation
journaled filesystems that can be checked for consistency very quickly and are
thus generally preferred over their non-journaled counterparts. Journaled
filesystems prevent long delays when you boot your system and your filesystem
happens to be in an inconsistent state. If you intend to install Gentoo on a
very small disk (less than 4GB), then you'll need to tell ext2 to reserve enough
inodes when you create the filesystem by running mke2fs -T small
/dev/<device>.
ext3 is the journaled version of the ext2 filesystem, providing metadata
journaling for fast recovery in addition to other enhanced journaling modes like
full data and ordered data journaling. It uses an HTree index that enables high
performance in almost all situations. In short, ext3 is a very good and
reliable filesystem. Ext3 is the recommended all-purpose all-platform
filesystem. If you intend to install Gentoo on a very small disk (less than
4GB), then you'll need to tell ext3 to reserve enough inodes when you create the
filesystem by running mke2fs -j -T small /dev/<device>.
ext4 is a filesystem created as a fork of ext3 bringing new features,
performance improvements and removal of size limits with moderate changes
to the on-disk format. It can span volumes up to 1 EB and with maximum file
size of 16 TB. Instead of the classic ext2/3 bitmap block allocation ext4 uses
extents,
which improve large file performance and reduce fragmentation. Ext4 also provides
more sophisticated block allocation algorithms (delayed allocation and multiblock
allocation) giving the filesystem driver more ways to optimise the layout of data
on the disk. The ext4 filesystem is a compromise between production-grade code
stability and the desire to introduce extensions to an almost decade old
filesystem.
JFS is IBM's high-performance journaling filesystem. JFS is a light,
fast and reliable B+tree-based filesystem with good performance in various
conditions.
ReiserFS is a B+tree-based journaled filesystem that has good overall
performance, especially when dealing with many tiny files at the cost of more
CPU cycles. ReiserFS appears to be less maintained than other filesystems.
XFS is a filesystem with metadata journaling which comes with a robust
feature-set and is optimized for scalability. XFS seems to be less forgiving to
various hardware problems.
Applying a Filesystem to a Partition
To create a filesystem on a partition or volume, there are tools available for
each possible filesystem:
| Filesystem |
Creation Command |
| vfat |
mkdosfs |
| ext2 |
mkfs.ext2 |
| ext3 |
mkfs.ext3 |
| ext4 |
mkfs.ext4 |
| reiserfs |
mkreiserfs |
| xfs |
mkfs.xfs |
| jfs |
mkfs.jfs |
For instance, to have the boot partition (/dev/sda1 in our
example) as vfat and the root partition (/dev/sda3 in our example)
as ext3, you would run the following commands:
Code Listing 1.1: Applying a filesystem on a partition |
# mkdosfs /dev/sda1
# mkfs.ext3 /dev/sda3
|
Activating the Swap Partition
mkswap is the command that is used to initialize swap partitions:
Code Listing 1.1: Creating a Swap signature |
# mkswap /dev/sda2
|
To activate the swap partition, use swapon:
Code Listing 1.1: Activating the swap partition |
# swapon /dev/sda2
|
Create and activate the swap with the commands mentioned above.
1.
Mounting
Now that your partitions are initialized and are housing a filesystem, it is
time to mount those partitions. Use the mount command. Don't forget to
create the necessary mount directories for every partition you created. As an
example we mount the root and boot partition:
Code Listing 1.1: Mounting the root partition |
# mount /dev/sda3 /mnt/gentoo
|
Note:
Unlike some of the other architectures supported by Gentoo, /boot
is not mounted on ia64. The reason for this is that the EFI boot partition will
be automatically mounted and written by the elilo command each time that
you run it. Because of this, /boot resides on the root filesystem
and is the storage place for the kernels referenced by your elilo
configuration.
|
Note:
If you want your /tmp to reside on a separate partition, be sure to
change its permissions after mounting: chmod 1777 /mnt/gentoo/tmp. This
also holds for /var/tmp.
|
We will also have to mount the proc filesystem (a virtual interface with the
kernel) on /proc. But first we will need to place our files on the partitions.
Continue with (Installing the Gentoo
Installation Files).
|