How to increase root file system if it’s mounted with standard partition(By extending Space on same disk)

Before adding extra disk space

[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 8.8G 855M 7.5G 11% /
devtmpfs devtmpfs 480M 0 480M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 ext4 969M 95M 809M 11% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
├─sda1 8:1 0 1000M 0 part /boot
└─sda2 8:2 0 9G 0 part /
sr0 11:0 1 1024M 0 rom
[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 20965375 9457664 83 Linux

I am adding disk space

 

 

 

 

 

——————-After Adding Disk Space———

[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 8.8G 856M 7.5G 11% /
devtmpfs devtmpfs 480M 0 480M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 ext4 969M 95M 809M 11% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 20965375 9457664 83 Linux
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1000M 0 part /boot
└─sda2 8:2 0 9G 0 part /
sr0 11:0 1 7.2G 0 rom

[root@localhost ~]# resize2fs /dev/sda2
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 2364416 blocks long. Nothing to do!
[root@localhost ~]# pwd
/root
[root@localhost ~]# touch testing
[root@localhost ~]# cat >>testing
this is to check if any damage done on existing disk
[root@localhost ~]# cat testing
this is to check if any damage done on existing disk
[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): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 20965375 9457664 83 Linux

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux

Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2050048-41943039, default 2050048):
Using default value 2050048
Last sector, +sectors or +size{K,M,G} (2050048-41943039, default 41943039):
Using default value 41943039
Partition 2 of type Linux and of size 19 GiB is set

Command (m for help): p

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 41943039 19946496 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@localhost ~]# partprobe
Error: Partition(s) 2 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.

[root@localhost ~]# resize2fs /dev/sda2
resize2fs 1.42.9 (28-Dec-2013)
The filesystem is already 2364416 blocks long. Nothing to do!

[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 41943039 19946496 83 Linux
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 8.8G 856M 7.5G 11% /
devtmpfs devtmpfs 480M 0 480M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 ext4 969M 95M 809M 11% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0

[root@localhost ~]# reboot
mohammedrafi@NOC-RAFI:~$ ssh root@192.168.43.133
root@192.168.43.133’s password:
Last login: Thu Oct 13 08:58:03 2016 from 192.168.43.1

[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 8.8G 856M 7.5G 11% /
devtmpfs devtmpfs 480M 0 480M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 ext4 969M 95M 809M 11% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1000M 0 part /boot
└─sda2 8:2 0 19G 0 part /
sr0 11:0 1 7.2G 0 rom
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00063b47

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2050047 1024000 83 Linux
/dev/sda2 2050048 41943039 19946496 83 Linux
[root@localhost ~]# resize2fs /dev/sda2
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sda2 is now 4986624 blocks long.

[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 19G 864M 17G 5% /
devtmpfs devtmpfs 480M 0 480M 0% /dev
tmpfs tmpfs 489M 0 489M 0% /dev/shm
tmpfs tmpfs 489M 6.7M 483M 2% /run
tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda1 ext4 969M 95M 809M 11% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0

[root@localhost ~]# cat testing
this is to check if any damage done on existing disk

                                               Thanks for watching

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s