Linux Virual Machines : Add additional storage and extend LV with the additional space.

In this post I am explaining about the procedure to add 20G to /applocal volume configured in Virtual Linux Machine.  A new Disk sdb is partitioned as sdb1 and it was allocated to LVM from outside, and after the reboot the disk is visible to Linux as /dev/sdb.

 The procedure to increase the /applocal involves following steps.

 

1. Verify the hard disk information from linux

 

[root@Gurkulindia-VM-Linux ~]# fdisk -l
Disk /dev/sda: 11.8 GB, 11811160064 bytes
255 heads, 63 sectors/track, 1435 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 1436 11427840 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/sdb: 42.9 GB, 42949672960 bytes <== New disk can be seen
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964761 83 Linux <== Currently having single partition of Linux

2. Verify the existing LV information

 

root@Gurkulindia-VM-Linux ~]# lvdisplay
— Logical volume —
LV Name /dev/datavg/applocalvol
VG Name datavg
LV UUID SFchwv-BPVy-MuVR-rA2p-MaOC-P8oq-YGPT7B
LV Write Access read/write
LV Status available
# open 1
LV Size 19.99 GB ß Only 20G seen
Current LE 5118
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:2

The additional disk space is already visible through fdisk (20G), so we just needed to create an additional partition (/dev/sdb2) from that space:

3. Partition the new Disk to create a new partition as sdb2

 

[root@Gurkulindia-VM-Linux applocal]# fdisk /dev/sdb
The number of cylinders for this disk is set to 5221.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
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
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (2611-5221, default 2611):
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-5221, default 5221):
Using default value 5221
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964761 83 Linux
/dev/sdb2 2611 5221 20972857+ 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.
Syncing disks.

 

4. Change partition ID to Linux LVM, so that disk can be added to LVM

 

[root@Gurkulindia-VM-Linux applocal]# fdisk /dev/sdb
The number of cylinders for this disk is set to 5221.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964761 83 Linux
/dev/sdb2 2611 5221 20972857+ 83 Linux
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
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): t
Partition number (1-4): 2
Hex code (type L to list codes): L
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964761 83 Linux
/dev/sdb2 2611 5221 20972857+ 8e Linux LVM
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.
Syncing disks.

At this point, needed to reboot the system to read the new partition table. (partprobe did not work)

After the reboot:

[root@Gurkulindia-VM-Linux ~]# fdisk -l
Disk /dev/sda: 11.8 GB, 11811160064 bytes
255 heads, 63 sectors/track, 1435 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 102400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 14 1436 11427840 8e Linux LVM
Partition 2 does not end on cylinder boundary.
Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964761 83 Linux
/dev/sdb2 2611 5221 20972857+ 8e Linux LVM  <– the one we created in previous fdisk operation
[root@Gurkulindia-VM-Linux ~]#

5. You can now add the new partition to LVM and extend the FS

 

Create PV from the Operating system disk sdb2

[root@Gurkulindia-VM-Linux /]# pvcreate /dev/sdb2
Physical volume “/dev/sdb2” successfully created

Extend the Volume Group “datavg” with the newly created PV.

[root@Gurkulindia-VM-Linux /]# vgextend datavg /dev/sdb2
Volume group “datavg” successfully extended

Extend the Logical Volume “applocalvol” to 40GB

[root@Gurkulindia-VM-Linux /]# lvextend -L +20G /dev/datavg/applocalvol
Extending logical volume applocalvol to 39.99 GB
Logical volume applocalvol successfully resized

 Extend the Filesystem of “applocalvol” online ( supports only in LVM 2.2 or later)

[root@Gurkulindia-VM-Linux /]# resize2fs -p /dev/datavg/applocalvol
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/datavg/applocalvol is mounted on /applocal; on-line resizing required
Performing an on-line resize of /dev/datavg/applocalvol to 10483712 (4k) blocks.
The filesystem on /dev/datavg/applocalvol is now 10483712 blocks long.

Now check the finally extended filesystem size with DF

[root@Gurkulindia-VM-Linux /]# df -kh /applocal
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/datavg-applocalvol
           40G 7.7G 30G 21% /applocal    <– New size is 40GB

Check the “datavg” volume group , for the no. of PVs and Total VG size

[root@Gurkulindia-VM-Linux ~]# vgdisplay datavg
— Volume group —
VG Name datavg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.99 GB
PE Size 4.00 MB
Total PE 10238
Alloc PE / Size 10238 / 39.99 GB
Free PE / Size 0 / 0
VG UUID GfGP60-7bXy-L1SD-nSvY-d0Jz-9qkG-ebzqUD

 

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

7 Responses

  1. Hduong says:

    I can’t login to the members login anymore. Any change on that?
    And i would like you to ccver how to build Linux ESX and virtual machines. Thanks.

  2. Mahesh says:

    Hi Ram,

    If the additional disk is added if the VM is up .Not required to reboot.You can scan with
    rescan-scsi-bus.sh or echo “- – -” > “/sys/class/scsi_host/host(x)/scan” and the rest is same for extending lvm

  3. Guy says:

    As Jerry said, we have turned our attention pv cell advantage to focus on.

  4. thanks , nice tutorial

  1. October 6, 2015

    […] Read – Add additional storage and extend Logical Volume in a VM […]

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us