HOW-TO: USE LINUX LVM TOOLS TO ADD DISK SPACE TO A VOLUME AFTER ADDING A VIRTUAL DISK.
After adding a virtual disk, you have to re-scan the SCSI bus on the Linux system to get it to give the new disk a device node:
Code:
STAGE>ls -l /sys/class/scsi_host
STAGE>echo "- - -" > /sys/class/scsi_host/host0/scan
In this case, the device was /dev/sdf, so fdisk that.
Code:
STAGE> fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 25847.
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)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
type "n" for "new partition"
Command (m for help): n
Make it a Primary partition:
Command action
e extended
p primary partition (1-4)
p
Now, select partition 1 and take the defaults for first and last cylinder:
Code:
Partition number (1-4): 1
First cylinder (1-25847, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-25847, default 25847):
Using default value 25847
Select "t" to change the partition type:
Command (m for help): t
Selected partition 1
You can look at the codes for possible partition types with an "L". Since this is a Linux LVM partition, it is code "8e" hex.
Code:
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 1 to 8e (Linux LVM)
Write the change to the partition table:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Check that /dev/sdf shows up as a Linux LVM partition:
Code:
STAGE> fdisk -l
Disk /dev/sda: 106 MB, 106037248 bytes
4 heads, 32 sectors/track, 1618 cylinders
Units = cylinders of 128 * 512 = 65536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 2 1601 102400 83 Linux
Disk /dev/sdb: 34.3 GB, 34360918016 bytes
88 heads, 6 sectors/track, 127104 cylinders
Units = cylinders of 528 * 512 = 270336 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 127101 33554432 82 Linux swap / Solaris
Disk /dev/sdc: 75.1 GB, 75167301632 bytes
111 heads, 60 sectors/track, 22043 cylinders
Units = cylinders of 6660 * 512 = 3409920 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 22044 73404416 8e Linux LVM
Disk /dev/sdd: 858.9 GB, 858993459200 bytes
53 heads, 35 sectors/track, 904432 cylinders
Units = cylinders of 1855 * 512 = 949760 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 480697 445845504 8e Linux LVM
/dev/sdd2 480697 904432 393015112 8e Linux LVM
Disk /dev/sde: 1288.4 GB, 1288490188800 bytes
255 heads, 63 sectors/track, 156650 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sde1 1 104434 838860799+ 8e Linux LVM
/dev/sde2 104434 156650 419430325 83 Linux
Disk /dev/sdf: 212.6 GB, 212600881152 bytes
255 heads, 63 sectors/track, 25847 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdf1 1 25847 207615996 8e Linux LVM
STAGE>
Create the new partition as a Physical Volume in LVM terms:
Code:
STAGE> pvcreate /dev/sdf1
Writing physical volume data to disk "/dev/sdf1"
Physical volume "/dev/sdf1" successfully created
Display your Volume Groups so you can see the "before" and "after" states:
Code:
STAGE> vgdisplay
--- Volume group ---
VG Name volumex
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 21
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 4
Act PV 4
VG Size 1.95 TB
PE Size 4.00 MB
Total PE 511996
Alloc PE / Size 511996 / 1.95 TB
Free PE / Size 0 / 0
VG UUID AEkJMc-pJke-512C-2GPh-uynH-Jd3r-7P8ohM
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 70.00 GB
PE Size 4.00 MB
Total PE 17920
Alloc PE / Size 17920 / 70.00 GB
Free PE / Size 0 / 0
VG UUID QiUgoN-KfHS-kLN4-ms5P-Xnzh-uCIt-tCtSFq
Extend the Volume Group to include the Physical Volume you just created:
Code:
STAGE> vgextend volumex /dev/sdf1
Volume group "volumex" successfully extended
Do a pvscan and an lvdisplay to enumerate the free space withing /dev/sdf and to see the name of the Logical Volume:
Code:
STAGE> pvscan
PV /dev/sdd1 VG volumex lvm2 [425.19 GB / 0 free]
PV /dev/sdd2 VG volumex lvm2 [374.80 GB / 0 free]
PV /dev/sde1 VG volumex lvm2 [800.00 GB / 0 free]
PV /dev/sde2 VG volumex lvm2 [400.00 GB / 0 free]
PV /dev/sdf1 VG volumex lvm2 [198.00 GB / 198.00 GB free]
PV /dev/sdc1 VG VolGroup00 lvm2 [70.00 GB / 0 free]
Total: 6 [2.21 TB] / in use: 6 [2.21 TB] / in no VG: 0 [0 ]
STAGE> lvdisplay
--- Logical volume ---
LV Name /dev/volumex/data-drive
VG Name volumex
LV UUID qfKl0W-5JAm-wjuG-XA7J-uO1c-5Y2g-ThWfdQ
LV Write Access read/write
LV Status available
# open 1
LV Size 1.95 TB
Current LE 511996
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID o4ZQdf-DK3z-mN0B-nwBG-2T8X-p4M3-YnIBL1
LV Write Access read/write
LV Status available
# open 1
LV Size 70.00 GB
Current LE 17920
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
Extend the LV by using "lvextend", then the name of the LV, then the device you want to add to the LV:
Code:
STAGE> lvextend /dev/volumex/data-drive /dev/sdf1
Extending logical volume data-drive to 2.15 TB
Logical volume data-drive successfully resized
Observe that the VG has been enlarged:
Code:
STAGE> vgdisplay
--- Volume group ---
VG Name volumex
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 23
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 5
Act PV 5
VG Size 2.15 TB
PE Size 4.00 MB
Total PE 562683
Alloc PE / Size 562683 / 2.15 TB
Free PE / Size 0 / 0
VG UUID AEkJMc-pJke-512C-2GPh-uynH-Jd3r-7P8ohM
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 70.00 GB
PE Size 4.00 MB
Total PE 17920
Alloc PE / Size 17920 / 70.00 GB
Free PE / Size 0 / 0
VG UUID QiUgoN-KfHS-kLN4-ms5P-Xnzh-uCIt-tCtSFq
STAGE>
In this case, I had to unmount the volume and resize it. I got an error telling me that I needed to fsck it, so I did that and used resize2fs again to resize the LV. The following three commands take care of it.
Code:
STAGE> umount /dev/volumex/data-drive
STAGE> resize2fs /dev/volumex/data-drive
STAGE> e2fsck -f /dev/volumex/data-drive
Finally, mount the filesystem and check it:
Code:
mount -a
ls -l /dataroot
df -h