Managing Master Boot Record (MBR) Disk Partitions
The fdisk utility is used from the command line to view, create, or delete MBR partitions at the shell prompt. To use fdisk to create a new partition, first open a terminal session. Then, at the shell prompt, change to your root account by entering su – followed by your root user’s password.
At the shell prompt, enter fdisk device. For example, if you want to manage partitions on the first hard disk in your system, you would enter fdisk /dev/sda. At this point, you need to enter a command to tell fdisk what you want to do with the hard disk.
You can enter m at the command prompt to display a list of all available commands.
You can also display the partition table for a specified hard disk by entering fdisk device –l at the shell prompt. The output is similar to that shown here.
In the next example, a new hard disk (/dev/sdb) has been installed in the system and fdisk is being used to create a partition:
openSUSE:~ # fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x8239827b.
Command (m for help):
Notice that, because this is a new disk in the system, it has to be initialized with a disk label.
The fdisk utility takes care of this for you when you load the program. However, the change won’t
be applied until you write your changes to the disk.
With fdisk running, you have a Command: prompt that you can use to enter fdisk commands.
At this point, one of the best things you can do is to enter m to view the fdisk help. When you
do, a list of commands is displayed that you can use to perform actions with fdisk, as shown in
this example:
Command (m for help): m
Command action
a toggle a bootable flag
b edit bad disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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 disk label
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):
CAUTION You can enter d to delete an existing partition. Be very careful about using this action. Any data on that partition will be lost! Once the changes are committed to disk, they are not reversible. You can back off from changes made with fdisk without committing them to disk by entering q. With disk, q is your friend!
Before creating a partition, you should enter p to view any existing partitions on the disk. This
will help you determine whether there is sufficient space and, if there is, what number must be
assigned to a new partition created on the disk.
To create a new partition, you enter n. You can then specify whether you want to create a
primary disk partition or an extended disk partition. Any hard disk in your system can have up to
four partitions defined in its partition table. These can be either primary or extended partitions. If
you intend to create four partitions or fewer, you can simply use primary partitions.
However, if you want to create more than four partitions on the disk, you must create at least
one extended partition. Extended partitions are great. Within one extended partition, you can
create many logical partitions. This allows you to get around the four-partition limitation. The
general rule of thumb is to create your primary partitions first; then create your extended partition
using the remaining space on the drive and create your logical partitions within it.
To create a primary partition, enter p when prompted. To create an extended partition, enter e.
You are then prompted to specify a partition number, as shown in this example:
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
You need to specify the next available partition number for the partition being created. In
other words, if your disk already has two partitions on it, you would enter 3. In the preceding
example, no partitions currently exist on the drive, so I’ve entered 1 to create the first primary
partition. If you try to enter a partition number that has already being used by an existing parti-
tion, the fdisk utility will complain!
At this point, you must specify the size of the partition. This is done by specifying the beginning and ending cylinders. You first specify the cylinder on which you want to begin the partition.
By default, fdisk displays the next available cylinder. If you don’t have any partitions on the disk,
this will be cylinder 1. If you already have partitions on the disk, the next unused cylinder will be
listed. After specifying your start cylinder, you have several options for specifying the overall size
of the partition, as shown here:
Partition number (1-4, default 1): 1
First sector (2048-2097151, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
2097151
Partition 1 of type Linux and of size 1023 MiB is set
You can
• Enter the last cylinder to be used in the partition.
• Specify the size of the partition in gigabytes by entering sizeG. For example, you could
create an 800GB partition by entering 800G.
After specifying the size, you should verify your new partition by entering p. This will display
all partitions for the disk, as shown in the next example:
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xd489eb71
Device Boot Start End Blocks Id System
/dev/sdb1 2048 2097151 1047552 83 Linux
Command (m for help):
It’s important to note that, at this point, the partition hasn’t been written to disk. All changes
are saved in memory before being committed to disk. This allows you to tweak your partitions
before actually committing the changes.
Before committing the partition to disk, however, you may need to change the partition type.
Notice in the preceding example that the partition being created is a standard Linux partition by default. Usually, this is sufficient. However, suppose you were creating a swap partition. You would need to use a different type of partition. This is done by entering t and then entering the
ID of the partition type you want to change to. If you don’t know the ID number of the partition
type you want to use, you can enter l (lowercase L) to list all the valid partition types and their
associated ID numbers, as shown here:
Command (m for help): l
0 Empty
1 FAT12
2 XENIX root
3 XENIX usr
4 FAT16 <32M
5 Extended
6 FAT16
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
24 NEC DOS 81 Minix / old Lin bf Solaris
27 Hidden NTFS Win
82 Linux swap / So
c1 DRDOS/sec
39 Plan 9
83 Linux
c4 DRDOS/sec
3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec
40 Venix 80286 85 Linux extended c7 Syrinx
41 PPC PReP Boot 86 NTFS volume set da Non-FS data
42 SFS 87 NTFS volume set db CP/M / CTOS
8 AIX 4e QNX4.x 2nd part 8e Linux LVM
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS
df BootIt
e1 DOS access
e3 DOS R/O
e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD
ee GPT
ef EFI (FAT-12/16)
f0 Linux/PA-RISC
f1 SpeedStor
f W95 Ext'd (LBA)
10 OPUS
11 Hidden FAT12
54 OnTrackDM6
55 EZ-Drive
56 Golden Bow
a6 OpenBSD
a7 NeXTSTEP
a8 Darwin UFS
12 Compaq diagnost 5c Priam Edisk a9 NetBSD
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs
18 AST SmartSleep 65 Novell Netware b8 BSDI swap
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
f4 SpeedStor
f2 DOS secondary
fb VMware VMFS
fc VMware VMKCORE
fd Linux raid auto
For example, the ID for a Linux swap partition is 82. To change the type of the partition, you could
enter t and specify a partition ID of 82 if you wanted to change the partition to a swap partition.
You can also delete partitions using fdisk. To do this, enter d at the command prompt and then
specify the partition number you want to delete. Remember, any data that resides on this partition
will be lost once you commit the change to disk!
At this point, you’re ready to commit your partition to disk. If you’re unhappy with the parti-
tioning proposal, you can always enter q to quit without applying the changes. If you are happy,
however, you can apply your changes by entering w. This will commit the partition to disk and
exit fdisk, as shown in this example:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
openSUSE:~ #
It’s important to note here that you must reboot the system before the Linux kernel will
recognize the partition changes you made with fdisk. However, you can also use the partprobe
command at the shell prompt to force the kernel to recognize the new partition table without
rebooting. The syntax is partprobe –s. The –s option causes the partprobe command to show a
summary of devices and their partitions, as shown in this example:
openSUSE:~ # partprobe –s
/dev/sda: msdos partitions 1 2 3
/dev/sdb: msdos partitions 1
openSUSE:~ #
Now that you know how to manage partitions with fdisk, let’s look at creating GUID partitions.
No comments:
Post a Comment