LPI Linux Certification in a Nutshell (25 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
13.2Mb size Format: txt, pdf, ePub
Managing partitions

Linux has two basic options for partitioning disk
drives. The
fdisk
command is a text-based program
that is easy to use and exists on every Linux distribution. It is also
required for Exam 101. Another option you may wish to explore after
mastering
fdisk
is
cfdisk
,
which is still a text-mode program but uses the
curses
system to produce a
GUI-style display.

Creating filesystems

Once a disk is partitioned, filesystems may be created
in those partitions using the
mkfs
utility.
mkfs
is a frontend program for
filesystem-specific creation tools such as
mkfs.ext2
and
mkfs.msdos
,
which are in turn linked to
mke2fs
and
mkdosfs
, respectively.
mkfs
offers a unified frontend, while the links provide convenient names.
The choice of which executable to call is up to you.

Creating swap partitions

Swap partitions are necessary if you want your Linux
system to have access to virtual memory. Virtual memory is a section
of the hard disk designated for use as memory when the main system
memory (the RAM) is all in use. The common formula for determining the
amount of
swap space you need has usually been twice the amount of
RAM your system has. Although swap is not required by Linux, at least
128 MB is recommended for some spooling functions. On the other hand,
memory-intensive applications may recommend much more, based on
variables such as the number of users, database tables/sizes, or other
application configuration guidelines. It is important to know what the
system will be used for when considering swap space.

The command to create a swap partition is
mkswap
. This command prepares a partition for use
as Linux swap space and is needed if you plan to fully configure a
disk from scratch. It is also required if you need to add an
additional swap partition.

Name

fdisk

Syntax
fdisk [
device
]
Description

Manipulate or display the partition table for
device
using a command-driven
interactive text interface.
device
is a
physical disk such as
/dev/hda
, not a
partition such as
/dev/hda1
. If omitted,
device
defaults to
/dev/hda
. Interactive commands to
fdisk
are a single letter followed by a
carriage return. The commands do not take arguments, but instead
start an interactive dialog. Commands that operate on a partition
will request the partition number, which is an integer. For
primary and extended partitions, the partition number is from 1 to
4. For logical partitions, which are available only when the
extended partition already exists to contain them, the partition
number is from 5 to 16.

When making changes to the partition table,
fdisk
accumulates changes without writing
them to the disk, until it receives the write command.

Frequently used commands
a

Toggle the
bootable
flag on/off
for a primary partition.

d

Delete a partition. You are prompted for the partition
number to delete. If you delete a logical partition when
higher-numbered logical partitions exist, the partition
numbers are decremented to keep logical partition numbers
contiguous.

l

List the known partition types. A table of partition
types is printed.

m

Display the brief help menu for these commands.

n

Add a new partition. You are prompted for the
partition type (primary, extended, or logical). For primary
and extended partitions, you are asked for the partition
number (1–4). For logical partitions, the next logical
partition number is selected automatically. You are then
prompted for the starting disk cylinder for the partition
and are offered the next free cylinder as a default.
Finally, you are prompted for the last cylinder or a size,
such as
+300M
. By
default, new partitions are assigned as Linux
ext2
, type 83. To create another
partition type, such as a swap partition, first create the
partition with the
n
command, and then
change the type with the
t
command.

Note

Note that
fdisk
displays
options for extended and primary partition types if an
extended partition does not yet exist. If the extended
partition already exists,
fdisk
displays options for logical and primary partition
types.

p

Display the partition table as it exists in memory.
This depiction will differ from the actual partition table
on disk if changes have not been saved.

q

Quit without saving changes.

t

Change a partition’s system ID. This is a hex number
that indicates the type of filesystem the partition is to
contain. Linux
ext2
partitions are type
83, and Linux swap partitions are type 82.

w

Write (save) the partition table to disk and exit. No
changes are saved until the
w
command
is issued.

Example 1

Display the existing partition table on
/dev/hda
without making any changes:

#
fdisk /dev/hda
Command (m for help):
p
Disk /dev/hda: 255 heads, 63 sectors, 1027 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 250 2008093+ 83 Linux
/dev/hda2 251 280 240975 82 Linux swap
/dev/hda3 281 1027 6000277+ 5 Extended
/dev/hda5 281 293 104391 83 Linux
/dev/hda6 294 306 104391 83 Linux
/dev/hda7 307 319 104391 83 Linux
Command (m for help):
q
#

In this configuration,
/dev/hda
has two
primary partitions,
/dev/hda1
, which is
bootable, and
/dev/hda2
,
which is the swap partition. The disk also has an extended
partition
/dev/hda3
, which contains three
logical partitions,
/dev/hda5
,
/dev/hda6
, and
/dev/hda7
. All other primary and logical
partitions are Linux
ext2
partitions.

Example 2

Starting with a blank partition table, create a bootable
primary partition of 300 MB on
/dev/hda1
, the
extended partition on
/dev/hda2
containing
the remainder of the disk, a logical partition of 200 MB on
/dev/hda5
, a logical swap partition of 128 MB
on
/dev/hda6
, and a logical partition on
/dev/hda7
occupying the remainder of the
extended partition:

#
fdisk /dev/hda
Command (m for help):
n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
1
First cylinder (1-1027, default 1): Enter
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1027, default 1027):
+300M
Command (m for help):
a
Partition number (1-4):
1
Command (m for help):
n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4):
2
First cylinder (40-1027, default 40): Enter
Using default value 40
Last cylinder or +size or +sizeM or +sizeK (40-1027, default 1027): Enter
Using default value 1027
Command (m for help):
n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (40-1027, default 40):
Enter
Using default value 40
Last cylinder or +size or +sizeM or +sizeK (40-1027, default 1027):
+200M
Command (m for help):
n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (79-1027, default 79): Enter
Using default value 79
Last cylinder or +size or +sizeM or +sizeK (79-1027, default 1027):
+128M
Command (m for help):
t
Partition number (1-6):
6
Hex code (type L to list codes):
82
Changed system type of partition 6 to 82 (Linux swap)
Command (m for help):
n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (118-1027, default 118): Enter
Using default value 118
Last cylinder or +size or +sizeM or +sizeK (118-1027, default 1027):
Enter
Using default value 1027
Command (m for help):
p
Disk /dev/hda: 255 heads, 63 sectors, 1027 cylinders
Units = cylinders of 16065 * 512 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 39 313236 83 Linux
/dev/hda2 40 1027 7936110 5 Extended
/dev/hda5 40 65 208813+ 82 Linux swap
/dev/hda6 66 82 136521 83 Linux
/dev/hda7 83 1027 7590681 83 Linux
Command (m for help):
w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
#

Note the use of defaults for the partition start cylinders
and for end cylinder selections, indicated by
Enter
in this example. Other partition
sizes are specified in megabytes using responses such as
+128M
.

Note

If you are attempting to create partitions for other
operating systems with the Linux
fdisk
utility, you could run into a few problems. As a rule, it is
safest to prepare the partitions for an operating system using
the native tools of that operating system.

As you might expect, using
fdisk
on a
working system can be dangerous, because one errant
w
command can render your disk useless. Use
extreme caution when working with the partition table of a
working system, and be sure you know exactly what you intend to
do and how to do it.

On the Exam

You should understand disk partitions and the process of
creating them using
fdisk
.

Name

mkfs

Syntax
mkfs [-t
fstype
] [
fs_options] device
Description

Make a filesystem of type
fstype
on
device
. If
fstype
is omitted,
ext2
is used by default. When called by
mkfs
, these programs are passed any
fs_options
included on the command
line. It is common to see references to commands such as
mkfs.ext2
,
mkfs.ext4
, or
mkfs.xfs
. These are all aliases for mkfs,
specifying a specific kind of filesystem you wish to
create.

Frequently used options
-c

Check
device
for bad blocks
before building the filesystem.

-L
label

Set the volume label for the filesystem (ext-based
filesystems only).

-n
label

Set the 11-character volume label for the filesystem
(
mkdosfs
only).

-q

Uses
mkfs
in quiet
mode, resulting in very little output.

-v

Used to enter verbose mode.

-j

Create an
ext3
journal file
(
mkfs.ext2
only). Using
-t
ext3
or running
mkfs.ext3
has the same effect as using the
-j
option.

Example 1

Using defaults, quietly create an
ext2
partition on
/dev/hda3
:

#
mkfs -q /dev/hda3
mke2fs 1.14, 9-Jan-1999 for EXT2 FS 0.5b, 95/08/09
#
Example 2

Create an
ext2
filesystem labeled
rootfs
on existing partition
/dev/hda3
, checking for bad blocks and with
full verbose output:

#
mkfs -t ext2 -L rootfs -cv /dev/hda3
mke2fs 1.27 (8-Mar-2002)
Filesystem label=rootfs
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
26208 inodes, 104422 blocks
5221 blocks (5.00%) reserved for the super user
First data block=1
13 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 16385, 24577, 32769, 40961, 49153,
57345, 65537, 73729, 81921, 90113, 98305
Running command: badblocks -b 1024 -s /dev/hda3 104422
Checking for bad blocks (read-only test): done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Additional options are available in the
mke2fs
and
mkdosfs
programs, which may be needed to fine-tune specific filesystem
parameters for special situations. In most cases, the default
parameters are appropriate and adequate.

Other books

Espada de reyes by Nancy V. Berberick
Bloodsucking fiends by Christopher Moore
A Christmas Bride by Susan Mallery
False Impressions by Laura Caldwell
Broken Vessels by Andre Dubus
You're the One That I Want by Susan May Warren