Thursday, 6 February 2014

Creation of Partition in RHEL 6/Linux

Partitions are created on a single hard disk with required file system management like the local drives created in windows operating system.
Partitions are divided into three types:

1.      Primary Partition
2.      Extended Partition
3.      Logical partition

Primary partitions are limited to four partitions, extended partition can be created only once and Logical has an advantage as we can create eleven logical partitions.

Primary Partition

 To get experienced with primary partition in your hard disk follow the below procedure:

STEP 1: Create Primary Partition
STEP 2: Verify Partition Created
STEP 3: Apply File System
STEP 4: Create Mount Point
STEP 5: Make Permanent Mounting

STEP 1: To create a partition type the fdisk command as shown below and follow the guidelines.

root@demo ~]# fdisk -cu /dev/vda

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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First sector (9914368-12582911, default 9914368): (leave empty)
Using default value 9914368
Last sector, +sectors or +size{K,M,G} (9914368-12582911, default 12582911): +200M
Command (m for help): p
Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 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 identifier: 0x00076b5c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      526335      262144   83  Linux
/dev/vda2          526336     9914367     4694016   8e  Linux LVM
/dev/vda3         9914368    10323967      204800   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.


STEP 2: Check the partition is created and enter the “partx” command twice. Don’t be worried about the error; it’s a bug in RHEL linux 6

[root@demo ~]#  partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
[root@demo ~]#  partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3

STEP 3: Format the partition as per your requirement for the file system. Here I have taken ext4 file system.

[root@demo ~]# mkfs.ext4 /dev/vda3

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
51200 inodes, 204800 blocks
10240 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
2048 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.



STEP 4: Create a mount point .i.e. create a directory where you store file and folders then assign the directory as a mount point of the partition.

[root@demo ~]# mkdir /storage
[root@demo ~]# Mount the device.
[root@demo ~]# mount <device> <mountpoint>
[root@demo ~]# mount /dev/vda3 /storage
[root@demo ~]# df –h

Filesystem Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
                      3.3G  2.4G  758M  77% /
tmpfs                 499M  100K  499M   1% /dev/shm
/dev/vda1             248M   33M  203M  14% /boot
/dev/mapper/vgsrv-home
                      248M   11M  226M   5% /home
/dev/vda3             194M  5.6M  179M   4% /storage


STEP 5: If you want to make permanent mounting then add device name and its details into /etc/fstab file. It is helpful in case of  system crash for any .

[root@demo ~]# vim /etc/fstab

After addition of device details into the file check if there are any errors

[root@demo ~]# mount -a

[root@demo ~]# df –hT

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
              ext4    3.3G  2.4G  757M  77% /
tmpfs        tmpfs    499M  264K  499M   1% /dev/shm
/dev/vda1     ext4    248M   33M  203M  14% /boot
/dev/mapper/vgsrv-home
              ext4    248M   11M  226M   5% /home
/dev/vda3     ext4    194M  5.6M  179M   4% /storage



Extended Partition


STEP 1: Create Primary Partition
STEP 2: Verify Partition Created

STEP 1: To create a partition type the fdisk command as shown below and follow the guidelines.

# fdisk -cu /dev/vda

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First sector (10323968-12582911, default 10323968): (leave empty)
Using default value 10323968
Last sector, +sectors or +size{K,M,G} (10323968-12582911, default 12582911): (leave empty)
Using default value 12582911

Command (m for help): p

Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 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 identifier: 0x00076b5c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      526335      262144   83  Linux
/dev/vda2          526336     9914367     4694016   8e  Linux LVM
/dev/vda3         9914368    10323967      204800   83  Linux
/dev/vda4        10323968    12582911     1129472    5  Extended

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.


STEP 2: Check the partition is created and enter the “partx” command twice. Don’t be worried about the error; it’s a bug in RHEL linux 6

[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4

Logical partition


To create the logical partition, follow the procedure given below:

STEP 1: Create Primary Partition
STEP 2: Verify Partition Created
STEP 3: Apply File System
STEP 4: Create Mount Point
STEP 5: Make Permanent Mounting

STEP 1: To create a partition type the fdisk command as shown below and follow the guidelines.

[root@demo ~]# fdisk -cu /dev/vda

Command (m for help): n
First sector (10326016-12582911, default 10326016): (leave empty)
Using default value 10326016
Last sector, +sectors or +size{K,M,G} (10326016-12582911, default 12582911): +120M

Command (m for help): p

Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 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 identifier: 0x00076b5c

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048      526335      262144   83  Linux
/dev/vda2          526336     9914367     4694016   8e  Linux LVM
/dev/vda3         9914368    10323967      204800   83  Linux
/dev/vda4        10323968    12582911     1129472    5  Extended
/dev/vda5        10326016    10571775      122880   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.



STEP 2: Check the partition is created and enter the “partx” command twice. Don’t be worried about the error; it’s a bug in RHEL linux 6

[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5

STEP 3: Format the partition as per your requirement for the file system. Here I have taken ext4 file system.

[root@demo ~]# mkfs.ext4 /dev/vda5

mke2fs 1.41.12 (17-May-2010)
Could not stat /dev/vda5 --- No such file or directory

The device apparently does not exist; did you specify it correctly?

If the above error appears, then reboot the system.

[root@demo ~]# init 6

[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5
[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 4
BLKPG: Device or resource busy
error adding partition 5

[root@demo ~]# mkfs.ext4 /dev/vda5
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
30720 inodes, 122880 blocks
6144 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
15 block groups
8192 blocks per group, 8192 fragments per group
2048 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 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


STEP 4: Create a mount point .i.e. create a directory where you store file and folders then assign the directory as a mount point of the partition.

[root@demo ~]# mkdir /mystorage
[root@demo ~]# mount /dev/vda5 /mystorage/
[root@demo ~]# df –hT

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
              ext4    3.3G  2.4G  759M  77% /
tmpfs        tmpfs    499M  100K  499M   1% /dev/shm
/dev/vda1     ext4    248M   33M  203M  14% /boot
/dev/mapper/vgsrv-home
              ext4    248M   11M  226M   5% /home
/dev/vda3     ext4    194M  5.6M  179M   4% /storage
/dev/vda5     ext4    117M  5.6M  105M   6% /mystorage


STEP 5: If you want to make permanent mounting then add device name and its details into /etc/fstab file.

[root@demo ~]# vim /etc/fstab
[root@demo ~]# mount -a
After addition of device details into the file check if there are any errors

[root@demo ~]# mount -a
[root@demo ~]# df –hT

Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vgsrv-root
              ext4    3.3G  2.4G  759M  77% /
tmpfs        tmpfs    499M  260K  499M   1% /dev/shm
/dev/vda1     ext4    248M   33M  203M  14% /boot
/dev/mapper/vgsrv-home
              ext4    248M   11M  226M   5% /home
/dev/vda3     ext4    194M  5.6M  179M   4% /storage
/dev/vda5     ext4    117M  5.6M  105M   6% /mystorage




No comments:

Post a Comment