Pages

Monday, March 30, 2020

How to increase space of / mount based on btrfs in Oracle Linux 7?


How to increase space of / mount based on btrfs in Oracle Linux 7?

It provide the step of active img file .
It additional step to increase the space of / mount . Because all OS module located in the mount


1. Stop VM

2. From Host OS , increase the size of img file using resize command

qemu-img resize new.img +11G

Output :
#qemu-img resize new.img +11G
Image resized.

3. Start VM

4. Check the current space

df -h

Output :
df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.4G 0 2.4G 0% /dev
tmpfs 2.4G 0 2.4G 0% /dev/shm
tmpfs 2.4G 8.3M 2.4G 1% /run
tmpfs 2.4G 0 2.4G 0% /sys/fs/cgroup
/dev/xvda3 11G 2.4G 6.3G 28% / ----> Size is 11G
/dev/xvda1 499M 115M 384M 24% /boot
tmpfs 489M 0 489M 0% /run/user/0
[root@dhcp-10-184-38-40 ~]#

5. Verify the resize command using fdisk -l

fdisk -l /dev/xvda

Output :
Disk /dev/xvda: 27.9 GB, 27917287424 bytes, 54525952 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: 0x000e4e76

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1030143 514048 83 Linux
/dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris
/dev/xvda3 9418752 31457279 11019264 83 Linux

it shows img size is increased by /dev/xvd3 not increased .

Our aim to increase the space of /dev/xvd3

if you run below command now , it will fail , so there is no free space in in partition


btrfs filesystem resize +11G /
Resize '/' of '+11G'
ERROR: unable to resize '/': no enough free space


6. run fdisk command on active / mount

d
3 ( mount on /)
n
p
a
p
w


fdisk /dev/xvda

Output :
fdisk /dev/xvda
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): d
Partition number (1-3, default 3): 3
Partition 3 is deleted

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

Command (m for help): a
Partition number (1-3, default 3): 3

Command (m for help): p

Disk /dev/xvda: 27.9 GB, 27917287424 bytes, 54525952 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: 0x000e4e76

Device Boot Start End Blocks Id System
/dev/xvda1 * 2048 1030143 514048 83 Linux
/dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris
/dev/xvda3 * 9418752 54525951 22553600 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.


7. partprobe to check

partprobe

Output :
Error: Partition(s) 3 on /dev/xvda 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.


8. resize using btrfs

btrfs filesystem resize max /

Output :
Resize '/' of 'max'.

9. partx -u -n 2 /dev/xvda

partx -u -n 2 /dev/xvda

Output :
no output .

10. checking partitions

cat /proc/partitions

Output :
major minor #blocks name

202 0 27262976 xvda
202 1 514048 xvda1
202 2 4194304 xvda2
202 3 11019264 xvda3.

11. Reboot of VM

12.resize using btrfs

btrfs filesystem resize max /

Output :
Resize '/' of 'max'.

13.check the file system

df -h .

Output :
Filesystem Size Used Avail Use% Mounted on
/dev/xvda3 22G 2.4G 18G 13% /

it is increased from 11G to 22G