How to Update newly created partition – How to Formatting a partition with file system

Updating a partition

After creating or deleting a partition the the changes will be effected in the partition table only after the restart of the system. But there is a way to avoid this circumstance. We can use partprobe or partx command to update the partition information without restarting the system.



How to Update newly created partition – How to Formatting a partition with file system

Frirst check the newly created partition


[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



Now update the partition using the following unix commands.
  •  # partprobe /dev/sda

                Or
  • #partx –a /dev/sda

                Or
  • #kpartx /dev/sda


[root@rahul /]# partx -a /dev/sda
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
BLKPG: Device or resource busy
error adding partition 6
BLKPG: Device or resource busy
error adding partition 7
BLKPG: Device or resource busy
error adding partition 8
[root@rahul /]#



[root@rahul /]# kpartx  /dev/sda
sda1 : 0 409600 /dev/sda 2048
sda2 : 0 20480000 /dev/sda 411648
sda3 : 0 4194304 /dev/sda 20891648
sda4 : 0 2 /dev/sda 25085952
sda5 : 0 1035675 /dev/sda 25086015
sda6 : 0 1044162 /dev/sda 26121753
sda7 : 0 1044162 /dev/sda 27165978
sda8 : 0 1044162 /dev/sda 28210203
[root@rahul /]#


Note: In RHEl6 partprobe is not functioning properly, so it is recommended to use partx command only.

Now then we have learnt creating and updating a partition. Lets see how to format a partition with a particular file system

Formatting a partition with ext4  filesystem

After creating a partition we need to assign some file system to it so that we can start storing the data into it. To format a partition the following syntax is used.
  • #mkfs.<file system type> <partition name>
  • #mkfs.ext4 /dev/sda7 (where sda7 is our newly created partition)


[root@rahul /]# mkfs.ext4 /dev/sda8
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
130560 inodes, 522080 blocks
26104 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
                8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@rahul /]#


Likewise you can format the different partitions with different file systems like
  • #mkfs.ext3 /dev/sda8


 [root@rahul /]# mkfs.ext3 /dev/sda8
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
130560 inodes, 522080 blocks
26104 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2040 inodes per group
Superblock backups stored on blocks:
                8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@rahul /]# ^C

  •  #mkfs.vfat /dev/sda9


[root@rahul /]# mkfs.vfat /dev/sda8
mkfs.vfat 3.0.9 (31 Jan 2010)



Note : Even after formatting the partition we cannot add the data into the partition. In order to add the data in the partition it is required to be mounted.
  •                                            How to mount a partition.

If you Like post then share and comment please And if you have any suggestion for me do comment .


Post a Comment