Home / Redhat-LINUX / How to Create Partitions on Redhat Linux ?

How to Create Partitions on Redhat Linux ?

How to create a disk partitions on Redhat Linux using fdisk command utility ? Here we will see how to manage the disks in redhat Linux using fdisk command.It includes creating the partitions,deleting the partitions,switching the system ids and more.Since fdisk utilities has many options and this will confuse the Linux beginners.This tutorial will go through the basics of using fdisk to manage a partition table on Redhat Linux.Once you have created the partition table ,you need to format the partition using mkfs command to create a filesystem on it. 

1.Scan the new disks and FS LUNS on Redhat Linux.

2.List the available disks using fdisk command.

[root@mylinz ~]# fdisk -l |grep /dev/sd
Disk /dev/sda: 21.5 GB, 21474836480 bytes
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
/dev/sdb1 1 512 524272 8e Linux LVM
Disk /dev/sdc: 536 MB, 536870912 bytes
/dev/sdc1 1 512 524272 8e Linux LVM
Disk /dev/sdd: 536 MB, 536870912 bytes
/dev/sdd1 1 512 524272 8e Linux LVM
Disk /dev/sde: 536 MB, 536870912 bytes
Disk /dev/sdf: 5368 MB, 5368709120 bytes
Disk /dev/sdg: 106 MB, 106954752 bytes
Disk /dev/sdh: 637 MB, 637534208 bytes
[root@mylinz ~]#


3.To create a new primary partition on /dev/sdf,enter in to command mode.

[root@mylinz ~]# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x357b9750.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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):


4.List the available commands of 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):


5.Add a new partitions by selecting command “n”.Let me create a new primary partition.

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): 200M

Command (m for help): p

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux

Command (m for help):


6.Let me verify the system Id. The above output is showing  system id as 83. 

Command (m for help): l

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor

83 stands for Linux partition. If you want to use that partition on LVM , you need to select “8e”  as system id.

7.Write the changes to the disk, and verify the tables.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@mylinz ~]# fdisk -l /dev/sdf

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
[root@mylinz ~]#

8.Format the /dev/sdf1 using mkfs command and mount it.

[root@mylinz ~]# mkfs.ext4 /dev/sdf1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
100464 inodes, 401617 blocks
20080 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=415236096
13 block groups
32768 blocks per group, 32768 fragments per group
7728 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mylinz ~]# mount -t ext4 /dev/sdf1 /mnt
[root@mylinz ~]# df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/sdf1 1.6G 35M 1.4G 3% /mnt
[root@mylinz ~]#

9.If you want o create a additional partition on /dev/sdf, enter in to command mode again .Here Let me create a extended partition and under that create one logical partition.

[root@mylinz ~]# fdisk /dev/sdf

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): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 1
Partition 1 is already defined. Delete it before re-adding it.

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4):2
First cylinder (201-652, default 201):
Using default value 201
Last cylinder, +cylinders or +size{K,M,G} (201-652, default 652): 300

Command (m for help):
Command (m for help): P

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
/dev/sdf2 201 300 803250 5 Extended

Command (m for help):n
Command action
l logical (5 or over)
p primary partition (1-4)
L
First cylinder (201-300, default 201):
Using default value 201
Last cylinder, +cylinders or +size{K,M,G} (201-300, default 300): 250

Command (m for help): p

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
/dev/sdf2 201 300 803250 5 Extended
/dev/sdf5 201 250 401593+ 83 Linux

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@mylinz ~]#



10.Using the above methods ,you can create up to 4 primary/extended partitions and N number of logical partitions under extended partitions.For your information, you can’t format the extended partitions directly. You need logical partitions under that.

[root@mylinz ~]# mkfs.ext4 /dev/sdf2
mke2fs 1.41.12 (17-May-2010)
mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).

[root@mylinz ~]#

11.We have already created the logical partition(/dev/sdf5) and just need to  format it.

[root@mylinz ~]# mkfs /dev/sdf5
mke2fs 1.41.12 (17-May-2010)
Could not stat /dev/sdf5 --- No such file or directory

The device apparently does not exist; did you specify it correctly?
[root@mylinz ~]#

12.If you are getting the above errors,Re-read the partition tables using below commands.

[root@mylinz ~]# kpartx /dev/sdf
sdf1 : 0 3212937 /dev/sdf 63
sdf2 : 0 2 /dev/sdf 3213000
sdf5 : 0 803187 /dev/sdf 3213063
[root@mylinz ~]#
[root@mylinz ~]#
[root@mylinz ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdd (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdf (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@mylinz ~]#

13.In the above case, you need un-mount the mounted filesystem from that disk.

[root@mylinz ~]# df -h /mnt
Filesystem Size Used Avail Use% Mounted on
/dev/sdf1 1.6G 35M 1.4G 3% /mnt
[root@mylinz ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdd (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdf (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@mylinz ~]# umount /mnt
[root@mylinz ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdd (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@mylinz ~]#

14.Try to create a filesystem on /dev/sdf5 ,

[root@mylinz ~]# mkfs.ext4 /dev/sdf5
mke2fs 1.41.12 (17-May-2010)
warning: 183 blocks unused.

Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
100744 inodes, 401409 blocks
20079 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
49 block groups
8192 blocks per group, 8192 fragments per group
2056 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@mylinz ~]# mkdir /mnt2
[root@mylinz ~]# mount -t ext4 /dev/sdf5 /mnt2
[root@mylinz ~]# df -h /mnt2
Filesystem Size Used Avail Use% Mounted on
/dev/sdf5 380M 11M 350M 3% /mnt2
[root@mylinz ~]#

15.If you getting error again ,kernel may not be able to re-read the disk partition table,So you need to reboot the system.

16.Creating new partition for LVM. (i.e changing the system id).

[root@mylinz ~]# fdisk /dev/sdf

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): n
Command action
l logical (5 or over)
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (301-652, default 301):
Using default value 301
Last cylinder, +cylinders or +size{K,M,G} (301-652, default 652):
Using default value 652

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): t
Partition number (1-5): 3
Hex code (type L to list codes): L

0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor

Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
/dev/sdf2 201 300 803250 5 Extended
/dev/sdf3 301 652 2827440 8e Linux LVM
/dev/sdf5 201 250 401593+ 83 Linux

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@mylinz ~]#

That’s it . Now you will be very familiar  to create a new primary,logical and extended partitions using fdisk.

Are wondering how to delete the partitions using fdisk ? Here you go …

[root@mylinz ~]# fdisk /dev/sdf

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): p

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
/dev/sdf2 201 300 803250 5 Extended
/dev/sdf3 301 652 2827440 8e Linux LVM
/dev/sdf5 201 250 401593+ 83 Linux

Command (m for help): d
Partition number (1-5): 3

Command (m for help): p

Disk /dev/sdf: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0x357b9750

Device Boot Start End Blocks Id System
/dev/sdf1 1 200 1606468+ 83 Linux
/dev/sdf2 201 300 803250 5 Extended
/dev/sdf5 201 250 401593+ 83 Linux

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@mylinz ~]#


Hope this post is informative to you. Thank you for visiting UnixArena.

VMTURBO-CLOUD-CAPACITY

Leave a Reply

Your email address will not be published. Required fields are marked *