In this article we will learn how to Create,See,Mount,Use and Delete a partition in RHEL6 linux without reboot.In RHEL5 we use PARTPROBE command to update the changes made in partition table but in RHEL6 PARTPROBE command doesn’t work, in RHEL6 we use PARTX command.Here in this article we see step wise how to create,configure,manage,mount,use and delete a partition in RedHat Enterprise 6 Linux.In this article we also learn how to create an extended partition in linux and then how to create logical partition in linux and use it to store data.
First see the Partition Table Structure before Partition Creation:
[root@localhost ~]# 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: 0x000e1624
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10240000 83 Linux
/dev/sda2 1275 1530 2048000 82 Linux swap / Solaris
Now Create New Partition using fdisk command line tool:
[root@localhost ~]# 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): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (1530-2088, default 1530):
Using default value 1530
Last cylinder, +cylinders or +size{K,M,G} (1530-2088, default 2088):
Using default value 2088
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: 0x000e1624
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10240000 83 Linux
/dev/sda2 1275 1530 2048000 82 Linux swap / Solaris
/dev/sda4 1530 2088 4482836 5 Extended
Command (m for help):
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1530-2088, default 1530):
Using default value 1530
Last cylinder, +cylinders or +size{K,M,G} (1530-2088, default 2088): +200M
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: 0x000e1624
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10240000 83 Linux
/dev/sda2 1275 1530 2048000 82 Linux swap / Solaris
/dev/sda4 1530 2088 4482836 5 Extended
/dev/sda5 1530 1555 201482 83 Linux
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1556-2088, default 1556):
Using default value 1556
Last cylinder, +cylinders or +size{K,M,G} (1556-2088, default 2088): +200M
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1582-2088, default 1582):
Using default value 1582
Last cylinder, +cylinders or +size{K,M,G} (1582-2088, default 2088): +400M
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: 0x000e1624
Device Boot Start End Blocks Id System
/dev/sda1 * 1 1275 10240000 83 Linux
/dev/sda2 1275 1530 2048000 82 Linux swap / Solaris
/dev/sda4 1530 2088 4482836 5 Extended
/dev/sda5 1530 1555 201482 83 Linux
/dev/sda6 1556 1581 208813+ 83 Linux
/dev/sda7 1582 1633 417658+ 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.
Explanation:
/dev/sda4 is an extended partition means /dev/sda4 itself cannot hold any data but several logical partition can be created inside an extended partition which can be mounted and used to storage data.Here in this example /dev/sda5,/dev/sda6 and /dev/sda7 are logical partition whome we can format,mount and use to store data in it.
Now Update The changes made in partition table without Reboot using partx command.
[root@localhost ~]# partx -v -a /dev/sda
device /dev/sda: start 0 size 33554432
gpt: 0 slices
dos: 7 slices
# 1: 2048- 20482047 ( 20480000 sectors, 10485 MB)
# 2: 20482048- 24578047 ( 4096000 sectors, 2097 MB)
# 3: 0- -1 ( 0 sectors, 0 MB)
# 4: 24578048- 33543719 ( 8965672 sectors, 4590 MB)
# 5: 24578111- 24981074 ( 402964 sectors, 206 MB)
# 6: 24981138- 25398764 ( 417627 sectors, 213 MB)
# 7: 25398828- 26234144 ( 835317 sectors, 427 MB)
reduced size of partition #4 to 63
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
added partition 4
added partition 5
added partition 6
added partition 7
Now Create a File system using mkfs:
[root@localhost ~]# mkfs.ext4 /dev/sda5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
50400 inodes, 201480 blocks
10074 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
180 days, whichever comes first. Use tune2fs -c or -i to override.
Now create a new directory and Mount newly created partition to use it.
[root@localhost ~]# mkdir /linux
[root@localhost ~]# mount /dev/sda5 /linux/
See the Mounted File System:
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 9.7G 2.7G 6.5G 30% /
tmpfs tmpfs 504M 420K 504M 1% /dev/shm
/dev/sda5 ext4 191M 5.6M 176M 4% /linux
Now to make this mounting Permanent we make a entry in /etc/fstab file.
As you can clearly see how to make entry in /etc/fstab file.If you are still confused just see the last line.
After creating a partition and using it for our purpose we may need to do delete it or destroy it.So now it’s time to learn how to Delete or Destroy a partition in RHEL6 Linux.
Step1:First Remove the permanent mount.
To remove a partition from permanent mount comment the line in /etc/fstab file or delete that line.
Step2:Then unmount it.
[root@localhost ~]# umount /linux/
Step3:Check whether it is unmounted or not using df command.
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda1 ext4 9.7G 2.7G 6.5G 30% /
tmpfs tmpfs 504M 420K 504M 1% /dev/shm
Step4:Now its time to Delete and Destroy partition using FDISK command line tool.
[root@localhost ~]# 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): d
Partition number (1-7): 5
Command (m for help): w
In above comand :d is used to delete partition and :w is to save the changes and write it to partition table.
[…] Read:HOW TO CREATE PARTITION IN LINUX. […]
LikeLike