Site icon IT Tutorial

How To Extend LVM ( Logical Volume Manager) Disks on the Fly ( Online )

I wanted to share one of the real life disk operation, I think It will be very useful blog post.

 

1- After disk is added to the system by System Admin. We need to check it on system via command below

Note : In some cases you need to scan host adapters via command below to not reboot the server

List all host adapters under directory than scan all of them with echo command

ls -l /sys/class/scsi_host/

echo “- – -” > /sys/class/scsi_host/host0/scan

I have many disks in my system so I have just added last two disks to see the differences between disks which is formatted or not.

As you see below red highlighted area means that disk is formatted and its partition is “ /dev/sdi1 “ but recently added disk (/dev/sdj ) which have not that partition yet.

[root@localhost ~]# fdisk –l

Disk /dev/sdi: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 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: 0xa5d10ee3

Device Boot Start End Blocks Id System

/dev/sdi1 1 2610 20964793+ 83 Linux

Disk /dev/sdj: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x00000000

 

2- We will create partition with fdisk and then check it is created as mentioned before like dev/sdi1

[root@localhost ~]# fdisk /dev/sdj

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x655b6f2f.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won’t be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to switch off the mode (command ‘c’) and change display units to sectors (command ‘u’).

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-1305, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305):

Using default value 1305

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@localhost ~]# fdisk -l /dev/sdj

Disk /dev/sdj: 10.7 GB, 10737418240 bytes

255 heads, 63 sectors/track, 1305 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: 0x655b6f2f

Device Boot Start End Blocks Id System

/dev/sdj1 1 1305 10482381 83 Linux

 

3- We need to check file system (type) which is used before and according to this we will format new disk

 

4- Format it with below command

[root@localhost ~]# mkfs.ext4 /dev/sdj1

mke2fs 1.43-WIP (20-Jun-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 2620595 blocks

131029 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2684354560

80 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

 

5- Create physical volume

[root@localhost ~]# pvcreate /dev/sdj1

dev_is_mpath: failed to get device for 8:145

Physical volume “/dev/sdj1” successfully created

 

6- Check volume groups.

Note : We will add physical disk “/dev/sdj1” into the volume group “vgu02” in the next step

[root@localhost ~]# vgs

VG #PV #LV #SN Attr VSize VFree

VolGroup 2 2 0 wz–n- 39.50g 0

vgu02 1 1 0 wz–n- 30.00g 0

 

7- Now we will add newly created physical volume into the volume group that we need to extent. In this case it is vgu02

[root@localhost ~]# vgextend vgu02 /dev/sdj1

Volume group “vgu02” successfully extended

 

8- We will extend the VolumeGroup now

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/vgu02-lvu02

Extending logical volume vgu02 to 10.00 GB

Logical volume vgu02 successfully resized

 

Note : You can see our volume group is extended 10Gb more but this size is usable by O/S yet

 

9- Now resize the file system and chech it with df –h command and see the new size

[root@localhost ~]# resize2fs /dev/mapper/vgu02-lvu02

resize2fs 1.43-WIP (20-Jun-2013)

Filesystem at /dev/mapper/vgu02-lvu02 is mounted on /u02; on-line resizing required

old_desc_blocks = 2, new_desc_blocks = 3

The filesystem on /dev/mapper/vgu02-lvu02 is now 10482688 blocks long.

 

 

Do you want to learn Linux System Administration for Beginners, then read the following articles.

https://ittutorial.org/linux-administration-tutorial-for-beginners/

Exit mobile version