Partition Practice RHEL7

To view the existing partitions:

#fdisk –l or parted –l

[root@localhost ~]# fdisk -l
 Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00048379
    Device   Boot   Start          End     Blocks   Id   System
/dev/sda1     *      2048      1050623     524288   83   Linux
/dev/sda2         1050624     42993663   20971520   83   Linux
/dev/sda3        42993664     84936703   20971520   83   Linux
/dev/sda4        84936704    209715199   62389248    5   Extended
/dev/sda5        84938752    101715967    8388608   83   Linux
/dev/sda6       101718016    105912319    2097152   83   Linux
/dev/sda7       105914368    122691583    8388608   82   Linux swap / Solaris
[root@localhost ~]#

Partition Administration using fdisk:
To enter into disk utility, the syntax is
#fdisk <disk name>
#fdisk /dev/sda

[root@localhost ~]# fdisk /dev/sda
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.


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

Creating a new partition:
#fdisk /dev/sda
  • Use p to list out the partition information first and
  • Use n to create a new partition.
  • Now use n to create a new partition and verify it again with p

[root@localhost ~]# fdisk /dev/sda
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.


Command (m for help): n
All primary partitions are in use
Adding logical partition 8
First sector (122693632-209715199, default 122693632):
Using default value 122693632
Last sector, +sectors or +size{K,M,G} (122693632-209715199, default 209715199): +500M
Partition 8 of type Linux and of size 500 MiB is set

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x00048379

Device Boot Start End Blocks Id System /dev/sda1 * 2048 1050623 524288 83 Linux /dev/sda2 1050624 42993663 20971520 83 Linux /dev/sda3 42993664 84936703 20971520 83 Linux /dev/sda4 84936704 209715199 62389248 5 Extended /dev/sda5 84938752 101715967 8388608 83 Linux /dev/sda6 101718016 105912319 2097152 83 Linux /dev/sda7 105914368 122691583 8388608 82 Linux swap / Solaris /dev/sda8 122693632 123717631 512000 83 Linux

Command (m for help):

Deleting a partition:
Let’s delete the partition we’ve created above i.e. /dev/sda8

  • Use d to delete a partition and specify the device name, in our case it is 7.

Command (m for help): d
Partition number (1-7, default 7): 7

Note: Never delete the system partitions i.e. 1-7

Every time you make a partition or delete a partition, the changes made has to be saved using w, otherwise the creation and deletion will not be considered to be happen. For practice purpose you can make any no. of partition and delete it and just quit using q so that it will not be saved.

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

Updating the partition table without restarting the system

After creating or deleting a partition 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.
#partprobe /dev/sda (OR)
#partx –a /dev/sda (OR)
#kpartx /dev/sda

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

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 name> <partition name>
#mkfs.ext4 /dev/sda7
(where sda7 is our newly created partition)

[root@localhost ~]# mkfs.ext4 /dev/sda8
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
128016 inodes, 512000 blocks
25600 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34078720
63 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

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

[root@localhost ~]# 
  • Likewise you can format the different partitions with different file systems like
  • #mkfs.ext3 /dev/sda8
  • #mkfs.vfat /dev/sda9

Mounting a partition:

Mounting is a procedure where we attach a directory to the file system. There are two types of mounting which will be used in Linux or any UNIX.
  • Temporary Mounting
  • Permanent Mounting
Temporary Mounting:
In a temporary mount point we will create a directory and mount it, but this mount point will last only till the system is up, once it is rebooted the mounting will be lost.
Syntax:
#mount <device name> <directory name (mount point)>
#mount /dev/sda8 /lb
[root@localhost ~]# mkdir /lb
[root@localhost ~]# mount /dev/sda8 /lb
[root@localhost ~]#

To View all the mounted partitions:
#mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=1916044k,nr_inodes=479011,mode=755)
/dev/sda1 on /boot type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sda6 on /home type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sda3 on /var type ext4 (rw,relatime,seclabel,data=ordered)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=386356k,mode=700)
gvfsd-fuse on /run/user/0/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=0,group_id=0)
/dev/sr0 on /run/media/root/RHEL-7.5 Server.x86_64 type iso9660 (ro,nosuid,nodev,relatime,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
/dev/sda8 on /lb type ext4 (rw,relatime,seclabel,data=ordered)
[root@localhost ~]#
  • Now we have successfully mounted the partition we can access it and can store the data
  • To add the data access the mount point
  • #cd /lb
  • Add the data and exit the directory

Leave a Reply

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