Disclaimer :
This handbook has been replaced by a newer version and is not maintained anymore.
|
[ << ]
[ < ]
[ Home ]
[ > ]
[ >> ]
4. Preparing the Disks
Content:
4.a. 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 the entire 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. These are known as
partitions.
The first partition on the first SCSI disk is /dev/sda1, the second
/dev/sda2 and so on.
The third partition on Sun systems is set aside as a special "whole disk"
slice. This partition must not contain a file system.
Users who are used to the DOS partitioning scheme should note that Sun
disklabels do not have "primary" and "extended" partitions. Instead, up to
eight partitions are available per drive, with the third of these being
reserved.
4.b. Designing a Partitioning Scheme
Default Partitioning Scheme
If you are not interested in drawing up a partitioning scheme, the table below
suggests a suitable starting point for most systems.
Note that a separate /boot partition is generally not
recommended on SPARC, as it complicates the bootloader configuration.
| Partition |
Filesystem |
Size |
Mount Point |
Description |
| /dev/sda1 |
ext3 |
<2 GByte |
/ |
Root partition. For sparc64 systems with older OBP versions, this
must be less than 2 GBytes in size, and the first partition on the
disk.
|
| /dev/sda2 |
swap |
512 MBytes |
none |
Swap partition. For bootstrap and certain larger compiles, at least 512
MBytes of RAM (including swap) is required.
|
| /dev/sda3 |
none |
Whole disk |
none |
Whole disk partition. This is required on SPARC systems. |
| /dev/sda4 |
ext3 |
at least 2 GBytes |
/usr |
/usr partition. Applications are installed here. By default this partition
is also used for Portage data (which takes around 500 Mbyte excluding
source code).
|
| /dev/sda5 |
ext3 |
at least 1GByte |
/var |
/var partition. Used for program-generated data. By default Portage uses
this partition for temporary space whilst compiling. Certain larger
applications such as Mozilla and OpenOffice.org can require over 1 GByte
of temporary space here when building.
|
| /dev/sda6 |
ext3 |
remaining space |
/home |
/home partition. Used for users' home directories. |
4.c. Using fdisk to Partition your Disk
The following parts explain how to create the example partition layout described
previously, namely:
| Partition |
Description |
| /dev/sda1 |
/ |
| /dev/sda2 |
swap |
| /dev/sda3 |
whole disk slice |
| /dev/sda4 |
/usr |
| /dev/sda5 |
/var |
| /dev/sda6 |
/home |
Change the partition layout as required. Remember to keep the root partition
entirely within the first 2 GBytes of the disk for older systems. There is also
a 15-partition limit for SCSI and SATA.
Firing up fdisk
Start fdisk with your disk as argument:
Code Listing 3.1: Starting fdisk |
# fdisk /dev/sda
|
You should be greeted with the fdisk prompt:
Code Listing 3.2: The fdisk prompt |
Command (m for help):
|
To view the available partitions, type in p:
Code Listing 3.3: Listing available partitions |
Command (m for help): p
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 8635 cylinders
Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda1 0 488 499712 83 Linux native
/dev/sda2 488 976 499712 82 Linux swap
/dev/sda3 0 8635 8842240 5 Whole disk
/dev/sda4 976 1953 1000448 83 Linux native
/dev/sda5 1953 2144 195584 83 Linux native
/dev/sda6 2144 8635 6646784 83 Linux native
|
Note the Sun disk label in the output. If this is missing, the disk is
using the DOS-partitioning, not the Sun partitioning. In this case, use s
to ensure that the disk has a sun partition table:
Code Listing 3.4: Creating a Sun Disklabel |
Command (m for help): s
Building a new sun disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Drive type
? auto configure
0 custom (with hardware detected defaults)
a Quantum ProDrive 80S
b Quantum ProDrive 105S
c CDC Wren IV 94171-344
d IBM DPES-31080
e IBM DORS-32160
f IBM DNES-318350
g SEAGATE ST34371
h SUN0104
i SUN0207
j SUN0327
k SUN0340
l SUN0424
m SUN0535
n SUN0669
o SUN1.0G
p SUN1.05
q SUN1.3G
r SUN2.1G
s IOMEGA Jaz
Select type (? for auto, 0 for custom): 0
Heads (1-1024, default 64):
Using default value 64
Sectors/track (1-1024, default 32):
Using default value 32
Cylinders (1-65535, default 8635):
Using default value 8635
Alternate cylinders (0-65535, default 2):
Using default value 2
Physical cylinders (0-65535, default 8637):
Using default value 8637
Rotation speed (rpm) (1-100000, default 5400): 10000
Interleave factor (1-32, default 1):
Using default value 1
Extra sectors per cylinder (0-32, default 0):
Using default value 0
|
You can find the correct values in your disk's documentation. The
'auto configure' option does not usually work.
Deleting Existing Partitions
It's time to delete any existing partitions. To do this, type d and hit
Enter. You will then be prompted for the partition number you would like to
delete. To delete a pre-existing /dev/sda1, you would type:
Code Listing 3.5: Deleting a partition |
Command (m for help): d
Partition number (1-4): 1
|
You should not delete partition 3 (whole disk). This is required. If
this partition does not exist, follow the "Creating a Sun Disklabel"
instructions above.
After deleting all partitions except the Whole disk slice, you should have a
partition layout similar to the following:
Code Listing 3.6: View an empty partition scheme |
Command (m for help): p
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 8635 cylinders
Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda3 0 8635 8842240 5 Whole disk
|
Creating the Root Partition
We're ready to create the root partition. To do this, type n to create a
new partition, then type 1 to create the partition. When prompted for
the first cylinder, hit enter. When prompted for the last cylinder, type
+512M to create a partition 512MBytes in size. Make sure that the
entire root partition fits within the first 2GBytes of the disk. You can see
output from these steps below:
Code Listing 3.7: Creating a root partition |
Command (m for help): n
Partition number (1-8): 1
First cylinder (0-8635): (press Enter)
Last cylinder or +size or +sizeM or +sizeK (0-8635, default 8635): +512M
|
Now, when you type p, you should see the following partition printout:
Code Listing 3.8: Listing the partition layout |
Command (m for help): p
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 8635 cylinders
Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda1 0 488 499712 83 Linux native
/dev/sda3 0 8635 8842240 5 Whole disk
|
Creating a swap partition
Next, let's create the swap partition. To do this, type n to create a new
partition, then 2 to create the second partition, /dev/sda2
in our case. When prompted for the first cylinder, hit enter. When prompted for
the last cylinder, type +512M to create a partition 512MB in size. After
you've done this, type t to set the partition type, and then type in
82 to set the partition type to "Linux Swap". After completing these
steps, typing p should display a partition table that looks similar to
this:
Code Listing 3.9: Listing of available partitions |
Command (m for help): p
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 8635 cylinders
Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda1 0 488 499712 83 Linux native
/dev/sda2 488 976 499712 82 Linux swap
/dev/sda3 0 8635 8842240 5 Whole disk
|
Creating the /usr, /var and /home partitions
Finally, let's create the /usr, /var and /home partitions. As before,
type n to create a new partition, then type 4 to create the
third partition, /dev/sda4 in our case. When prompted for the
first cylinder, hit enter. When prompted for the last cylinder, enter
+2048M to create a partition 2 GBytes in size. Repeat this process
for sda5 and sda6, using the desired sizes. Once
you're done, you should see something like this:
Code Listing 3.10: Listing complete partition table |
Command (m for help): p
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 8635 cylinders
Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda1 0 488 499712 83 Linux native
/dev/sda2 488 976 499712 82 Linux swap
/dev/sda3 0 8635 8842240 5 Whole disk
/dev/sda4 976 1953 1000448 83 Linux native
/dev/sda5 1953 2144 195584 83 Linux native
/dev/sda6 2144 8635 6646784 83 Linux native
|
Save and Exit
To save your partition layout and exit fdisk, type w:
Code Listing 3.11: Save and exit fdisk |
Command (m for help): w
|
Now that your partitions are created, you can continue with Creating Filesystems.
4.d. 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 is
used as default in this handbook, continue with Applying a Filesystem to a Partition.
Otherwise, read on to learn about the available filesystems...
Filesystems
Several filesystems are available, some are known to be stable on the
SPARC architecture. Ext2, ext3 and ext4, for example, are known to work well.
Alternate filesystems may not function correctly.
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. The mke2fs application uses the
"bytes-per-inode" setting to calculate how many inodes a file system should have.
By running mke2fs -T small /dev/<device> the number of inodes will
generally quadruple for a given file system as its "bytes-per-inode" reduces from
one every 16kB to one every 4kB. You can tune this even further by using
mke2fs -i <ratio> /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. 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. The mke2fs application uses the
"bytes-per-inode" setting to calculate how many inodes a file system should have.
By running mke2fs -j -T small /dev/<device> the number of inodes will
generally quadruple for a given file system as its "bytes-per-inode" reduces from
one every 16kB to one every 4kB. You can tune this even further by using
mke2fs -j -i <ratio> /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. Ext4 is the recommended all-purpose all-platform filesystem.
Applying a Filesystem to a Partition
To create a filesystem on a partition or volume, tools specific to the chosen
filesystem are available:
| Filesystem |
Creation Command |
| ext2 |
mke2fs |
| ext3 |
mke2fs -j |
For instance, to create the root partition (/dev/sda1 in our
example) as ext2, and the /usr, /var, and
/home partitions (/dev/sda4, 5
and 6 in our example, respectively) as ext3, you would use:
Code Listing 4.1: Applying a filesystem on a partition |
# mke2fs /dev/sda1
# mke2fs -j /dev/sda4
# mke2fs -j /dev/sda5
# mke2fs -j /dev/sda6
|
Activating the Swap Partition
mkswap is the command used to initialize swap partitions:
Code Listing 4.2: Creating a Swap signature |
# mkswap /dev/sda2
|
To activate the swap partition, use swapon:
Code Listing 4.3: Activating the swap partition |
# swapon /dev/sda2
|
Create and activate the swap with the commands mentioned above.
4.e. Mounting
Now that your partitions are initialized and are housing a filesystem, it is
time to mount them using the mount command. Don't forget to first
create the necessary mount directories for every partition you created. For
example:
Code Listing 5.1: Mounting partitions |
# mount /dev/sda1 /mnt/gentoo
# mkdir /mnt/gentoo/usr
# mount /dev/sda4 /mnt/gentoo/usr
# mkdir /mnt/gentoo/var
# mount /dev/sda5 /mnt/gentoo/var
# mkdir /mnt/gentoo/home
# mount /dev/sda6 /mnt/gentoo/home
|
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.
[ << ]
[ < ]
[ Home ]
[ > ]
[ >> ]
The contents of this document, unless otherwise expressly stated, are licensed under the CC-BY-SA-2.5 license. The Gentoo Name and Logo Usage Guidelines apply.
|