Create a New Partition in Linux
In most Linux systems, you can use the
fdisk
utility to create a new partition and perform other disk management operations.
Note:
To perform disk management operations using
fdisk
, you must have the
root
privileges.
As a tool with a text interface,
fdisk
requires typing the commands in the
fdisk
command line. The main
fdisk
commands are listed below:
Options
|
Description
|
m
|
Displays all available commands for
fdisk
.
|
p
|
Displays the list of existing partitions on your
hda
drive. Unpartitioned space is not listed.
|
n
|
Creates a new partition.
|
q
|
Exits
fdisk
without saving your changes.
|
l
|
Lists partition types.
|
w
|
Writes changes to the partition table.
|
To create a new partition:
-
Start a terminal.
-
Start
fdisk
:
# /sbin/fdisk /dev/hda
/dev/hda
stands for the hard drive you want to partition.
-
In
fdisk
, to create a new partition, type the following command:
n
-
When prompted to specify the
Partition type
, type
p
to create a primary partition or
e
to create an extended one. There may be up to four primary partitions. If you want to create more than four partitions, extend the last partition, and it will become a container for other logical partitions.
-
When prompted for the
Number
, in most cases, type
3
because a
typical
Linux virtual machine has two partitions by default.
-
When prompted for the
Start cylinder
, type a starting cylinder number or press
Return
to use the first cylinder available.
-
When prompted for the
Last cylinder
, press
Return
to allocate all the available space or specify the size of a new partition in cylinders if you do not want to use all the available space.
By default,
fdisk
creates a partition with a
System ID
of
83
. If you are unsure of the partition’s
System ID
, use the
l
command to check it.
-
Use the
w
command to write the changes to the partition table.
-
Restart the virtual machine:
reboot
-
When restarted, create a file system on the new partition. We recommend that you use the same file system as on your other partitions. In most cases it will be either the
ext3
or
ReiserFS
file system. For example, to create the
ext3
file system, run the following command:
/sbin/mkfs -t ext3 /dev/hda3
-
Create a directory that will be a mount point for the new partition. For example, to create a new directory and assign the name
data
to it, enter:
mkdir /data
-
Mount the new partition to the directory you have just created:
mount /dev/hda3 /data
-
Edit the
/etc/fstab
file to specify the information on the new partition. For example, you can add the following string to this file:
/dev/hda3 /data ext3 defaults 0 0
In this string,
/dev/hda3
is the partition you have just created,
/data
is a mount point for the new partition,
ext3
is the file type of the new partition. For the exact meaning of other items in this string, consult the Linux documentation for the
mount
and
fstab
commands.
|