MANAGING
PARTITIONS
What
is partition?
Partitioning is a means to divide a single hard
drive into many logical drives. A partition is a contiguous set of block on a
drive that are treated as an independent disk. A partition table is an index
that relates sections of the hard drive to partitions.
This tutorial shows you
how to actually partition your hard drive with the fdisk utility. Linux allows
only 4 primary partitions. You can have a much larger number of logical
partitions by sub-dividing one of the primary partitions. Only one of the
primary partitions can be sub-divided.
- Four primary partitions
- Mixed primary and logical partitions
The fdisk command is a text-based utility for
viewing and managing hard disk partitions on Linux. It’s one of the most
powerful tools you can use to manage partitions, but it’s confusing to new
users.
This tutorial about the basics of using fdisk to
manage a partition table.
List
Partitions
The fdisk -l
or parted -l commands lists the
partitions on your system.
[root@rahul
/]# fdisk -l
Disk
/dev/sda: 17.2 GB, 17179869184 bytes
255
heads, 63 sectors/track, 2088 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector
size (logical/physical): 512 bytes / 512 bytes
I/O
size (minimum/optimal): 512 bytes / 512 bytes
Disk
identifier: 0x000efa3d
Device Boot Start End Blocks
Id System
/dev/sda1 *
1 26 204800
83 Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000
83 Linux
/dev/sda3 1301 1562 2097152
82 Linux swap / Solaris
/dev/sda4 1562 2088 4228884 5
Extended
/dev/sda5 1562 1626 517837+
82 Linux swap / Solaris
/dev/sda6 1627 1691 522081
8e Linux LVM
/dev/sda7 1692 1756 522081
8e Linux LVM
/dev/sda8 1757 1821 522081
83 Linux
[root@rahul
/]#
|
You can add a disk’s device name to list only
partitions on it. For example, use the following command to only list
partitions on the first disk device:
# fdisk -l /dev/sda
Partition
Administration using fdisk:
To work on a disk’s partitions, you have to enter
command mode. You’ll need the device name of a disk from the fdisk -l command.
The following command enters command mode for the first disk device:
#
fdisk /dev/sda
[root@rahul
/]# fdisk /dev/sda
WARNING:
DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c')
and change display units to
sectors (command 'u').
Command
(m for help):
|
Using
fdisk Command Mode
In command mode, you use single-letter commands to
specify actions you want to take. Use m
to list out various options that can be used in fdisk.
Command
(m for help): m
Command
action
a
toggle a bootable flag
b
edit bsd disklabel
c
toggle the dos compatibility flag
d
delete a partition
l
list known partition types
m
print this menu
n
add a new partition
o
create a new empty DOS partition table
p
print the partition table
q
quit without saving changes
s
create a new empty Sun disklabel
t
change a partition's system id
u
change display/entry units
v
verify the partition table
w
write table to disk and exit
x
extra functionality (experts only)
Command
(m for help):
|
View
the Partition Table
Use p to
print the current partition table to the terminal from within command mode.
Command
(m for help): p
Disk
/dev/sda: 17.2 GB, 17179869184 bytes
255
heads, 63 sectors/track, 2088 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector
size (logical/physical): 512 bytes / 512 bytes
I/O
size (minimum/optimal): 512 bytes / 512 bytes
Disk
identifier: 0x000efa3d
Device Boot Start End Blocks
Id System
/dev/sda1 *
1 26 204800 83
Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000
83 Linux
/dev/sda3 1301 1562 2097152
82 Linux swap / Solaris
/dev/sda4 1562 2088 4228884 5
Extended
/dev/sda5 1562 1626 517837+
82 Linux swap / Solaris
/dev/sda6 1627 1691 522081
8e Linux LVM
/dev/sda7 1692 1756 522081
8e Linux LVM
/dev/sda8 1757 1821
522081 83
Linux
Command
(m for help):
|
Creating
a new partition
#fdisk
/dev/sda
Use p to
list out the partition table information first and
Use n to
create a new partition
Command
(m for help): n
First
cylinder (1757-2088, default 1757):
Using
default value 1757
Last
cylinder, +cylinders or +size{K,M,G} (1757-2088, default 2088): +500M
Command
(m for help): p
Disk
/dev/sda: 17.2 GB, 17179869184 bytes
255
heads, 63 sectors/track, 2088 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector
size (logical/physical): 512 bytes / 512 bytes
I/O
size (minimum/optimal): 512 bytes / 512 bytes
Disk
identifier: 0x000efa3d
Device Boot Start End Blocks
Id System
/dev/sda1 *
1 26 204800
83 Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000
83 Linux
/dev/sda3 1301 1562 2097152
82 Linux swap / Solaris
/dev/sda4 1562 2088 4228884 5
Extended
/dev/sda5 1562 1626 517837+
82 Linux swap / Solaris
/dev/sda6 1627 1691 522081
8e Linux LVM
/dev/sda7 1692 1756 522081
8e Linux LVM
/dev/sda8 1757 1821 522081
83 Linux
Command
(m for help):
|
Next, specify the sector of the disk you want the
partition to start at. Press Enter to accept the default sector, which is the
first free sector on the disk.
At Last, specify the last sector of the partition on
the disk. If you want to use up all available space after the initial sector,
just press Enter. You can also specify a specific size, such as +5G for a five
gigabyte partition or +512M for a 512 megabyte partition. If you don’t specify
a unit after the + sign, fdisk uses sectors as the unit. For example, +10000
results in the end of the partition being 10000 sectors after its beginning.
How
to delete partition ?
Use the d command to delete a partition. You’ll be
asked for the number of the partition you want to delete, which you can get
from the p command. For example, if I wanted to delete the partition at
/dev/sda8, I’d type 8.
Command
(m for help): d
Partition
number (1-8): 8
Command
(m for help): p
Disk
/dev/sda: 17.2 GB, 17179869184 bytes
255
heads, 63 sectors/track, 2088 cylinders
Units
= cylinders of 16065 * 512 = 8225280 bytes
Sector
size (logical/physical): 512 bytes / 512 bytes
I/O
size (minimum/optimal): 512 bytes / 512 bytes
Disk
identifier: 0x000efa3d
Device Boot Start End Blocks
Id System
/dev/sda1 *
1 26 204800
83 Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 26 1301 10240000
83 Linux
/dev/sda3 1301 1562 2097152
82 Linux swap / Solaris
/dev/sda4 1562 2088 4228884 5
Extended
/dev/sda5 1562 1626 517837+
82 Linux swap / Solaris
/dev/sda6 1627 1691 522081
8e Linux LVM
/dev/sda7 1692 1756 522081
8e Linux LVM
Command
(m for help):
|
Saving
the partition changes
- Use w to write the changes you’ve made to disk.
- Use q if you want to quit without saving changes.
Command
(m for help): w
The
partition table has been altered!
Calling
ioctl() to re-read partition table.
WARNING:
Re-reading the partition table failed with error 16: Device or resource busy.
The
kernel still uses the old table. The new table will be used at
the
next reboot or after you run partprobe(8) or kpartx(8)
Syncing
disks.
[root@rahul
/]#
|
If you Like post then share and comment please And if you have any suggestion for me do comment .
Post a Comment