Adding a drive to an existing LV. The initial install was done using the LVM2
options in Debian Lenny using the LVM2 auto partition options on a 80GB
drive, detailed:
# cfdisk
Disk Drive: /dev/hda
Size: 80026361856 bytes, 80.0 GB
Heads: 255 Sectors per Track: 63 Cylinders: 9729
Name Flags Part Type FS Type [Label] Size (MB)
-------------------------------------------------------------------------------------------------
hda1 Boot Primary Linux ext2 254.99
hda2 Primary Linux LVM 79768.77
# df -h /dev/mapper/LVM120-root
shows size of existing LV:
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/LVM120-root 71G 2.4G 65G 4% /
LVM120:~# pvscan
shows existing drives in current VG/LV:
PV /dev/hda2 VG LVM120 lvm2 [74.29 GB / 0 free]
# vgscan
shows existing VG info
Reading all physical volumes. This may take a while...
Found volume group "LVM120" using metadata type lvm2
# lvscan
shows LV details - in this case created at install so holds the / system dir,
and is called root :
ACTIVE '/dev/LVM120/root' [71.75 GB] inherit
ACTIVE '/dev/LVM120/swap_1' [2.54 GB] inherit
Check system drives info:
# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd1f9d1f9
Device Boot Start End Blocks Id System
/dev/hda1 * 1 31 248976 83 Linux
/dev/hda2 32 9729 77899185 8e Linux LVM
Disk /dev/hdb: 82.3 GB, 82348277760 bytes
255 heads, 63 sectors/track, 10011 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xafe2afe2
Device Boot Start End Blocks Id System
/dev/hdb1 1 10012 80416768 83 Linux
Disk /dev/dm-0: 77.0 GB, 77045170176 bytes
255 heads, 63 sectors/track, 9366 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-0 doesn't contain a valid partition table
Disk /dev/dm-1: 2722 MB, 2722103296 bytes
255 heads, 63 sectors/track, 330 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1 doesn't contain a valid partition table
There are 2 partitions associated with the current LV - hda1+2, which are
formatted as ext3 (83) and LVM2 (8e), as hda1 is a boot partition of 228MB.
Around 2GB has been used for the new install with KDE and apps, so the
remainder of the drive is available:
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/LVM120-root
71G 2.4G 65G 4% /
tmpfs 491M 0 491M 0% /lib/init/rw
udev 10M 696K 9.4M 7% /dev
tmpfs 491M 140K 490M 1% /dev/shm
/dev/hda1 228M 17M 199M 8% /boot
To add hdb to the LV, it is prepared from an unpartitioned drive's free space
with cfdisk by creating a new partition of type ext3 (or you can just add the
whole drive as /dev/hdb with
# pvcreate /dev/hdb
without partitioning it first):
:
#cfdisk /dev/hdb.
Disk Drive: /dev/hdb
Size: 81964302336 bytes, 81.9 GB
Heads: 255 Sectors per Track: 63 Cylinders: 9964
Name Flags Part Type FS Type [Label] Size (MB)
------------------------------------------------------------------------------
Pri/Log Free Space 81956.69
[ Help ] [ New ] [ Print ] [ Quit ] [ Units ]
[ Write ]
Create new partition from free space
[Primary] [Logical] [Cancel ]
Size (in MB): 81956.69
Are you sure you want to write the partition table to disk? (yes or no):
Warning!! This may destroy data on your disk!
hdd1 Primary Linux 81956.69
[ Quit ]
It is not necessary to format it after cfdisk, as the root partition which is
ext3 will be resized into this available space later on the fly, but not all
other FS types can do this.
After that, it is prepared for an LV, in order of Physical Volume, Volume
Group, Logical Volume :
# pvcreate /dev/hdb1
Physical volume "/dev/hdb1" successfully created
It is now detailed with :
# pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name LVM120
PV Size 74.29 GB / not usable 1.42 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 19018
Free PE 0
Allocated PE 19018
PV UUID qoetx0-FgRU-F8Bj-ITdx-M3UZ-xpSi-AZe3M5
--- Physical volume ---
PV Name /dev/hdb1
VG Name LVM120
PV Size 76.69 GB / not usable 4.00 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 19632
Free PE 19632
Allocated PE 0
PV UUID zaFBkJ-YARB-Nlj2-So1Z-PiMA-kVgW-GeoisR
Now hdb has a different TYPE="lvm2pv" label from the default ext3 one at
partition creation, as shown with
# blkid
/dev/hda1: UUID="cb10eff9-bbb6-48d6-a86e-fb5e80324046" TYPE="ext2"
/dev/hda2: UUID="qoetx0-FgRU-F8Bj-ITdx-M3UZ-xpSi-AZe3M5" TYPE="lvm2pv"
/dev/hdb1: UUID="zaFBkJ-YARB-Nlj2-So1Z-PiMA-kVgW-GeoisR" TYPE="lvm2pv"
/dev/dm-0: UUID="880e140a-3ea9-41f2-aba9-424268434d1c" TYPE="ext3"
/dev/dm-1: TYPE="swap"
and in cfdisk it now shows as unpartitioned free space again:
# cfdisk /dev/hdb1
Disk Drive: /dev/hdb1
Size: 82346770432 bytes, 82.3 GB
Heads: 255 Sectors per Track: 63 Cylinders: 10011
Name Flags Part Type FS Type [Label] Size (MB)
-------------------------------------------------------------------------------------------------
Pri/Log Free Space 82343.28
The current LV drives allocated are shown using:
# lvmdiskscan
/dev/ram0 [ 8.00 MB]
/dev/root [ 71.75 GB]
/dev/ram1 [ 8.00 MB]
/dev/hda1 [ 243.14 MB]
/dev/dm-1 [ 2.54 GB]
/dev/ram2 [ 8.00 MB]
/dev/hda2 [ 74.29 GB] LVM physical volume
/dev/ram3 [ 8.00 MB]
/dev/ram4 [ 8.00 MB]
/dev/ram5 [ 8.00 MB]
/dev/ram6 [ 8.00 MB]
/dev/ram7 [ 8.00 MB]
/dev/ram8 [ 8.00 MB]
/dev/ram9 [ 8.00 MB]
/dev/ram10 [ 8.00 MB]
/dev/ram11 [ 8.00 MB]
/dev/ram12 [ 8.00 MB]
/dev/ram13 [ 8.00 MB]
/dev/ram14 [ 8.00 MB]
/dev/ram15 [ 8.00 MB]
/dev/hdb1 [ 76.69 GB]
1 disk
19 partitions
0 LVM physical volume whole disks
1 LVM physical volume
which is made up of PVs :
LVM120:~# pvscan
PV /dev/hda2 VG LVM120 lvm2 [74.29 GB / 0 free]
Total: 1 [74.29 GB] / in use: 1 [74.29 GB] / in no VG: 0 [0 ]
with more detail in:
# vgdisplay -v
Finding all volume groups
Finding volume group "LVM120"
--- Volume group ---
VG Name LVM120
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 74.29 GB
PE Size 4.00 MB
Total PE 19018
Alloc PE / Size 19018 / 74.29 GB
Free PE / Size 0 / 0
VG UUID buiuWa-IN2B-eQ3z-ynnv-SsYF-ww3p-O1jwct
--- Logical volume ---
LV Name /dev/LVM120/root
VG Name LVM120
LV UUID ICF2Ju-qAbk-sXuV-yUFM-DzQU-DM9b-uZQz8r
LV Write Access read/write
LV Status available
# open 1
LV Size 71.75 GB
Current LE 18369
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Name /dev/LVM120/swap_1
VG Name LVM120
LV UUID 6VVPRv-u80U-Mjpp-cJ2E-57yQ-TPpr-0QlpnA
LV Write Access read/write
LV Status available
# open 2
LV Size 2.54 GB
Current LE 649
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
--- Physical volumes ---
PV Name /dev/hda2
PV UUID qoetx0-FgRU-F8Bj-ITdx-M3UZ-xpSi-AZe3M5
PV Status allocatable
Total PE / Free PE 19018 / 0
To add drive/partition hdb1 to the Volume Group named LVM120:
# vgextend LVM120 /dev/hdb1
Volume group "LVM120" successfully extended
Now to add the extra volume to the LV group:
# lvextend /dev/mapper/LVM120-root /dev/hdb1
Extending logical volume root to 148.44 GB
Logical volume root successfully resized
The new VG and LV changes have to be made known to the kernel:
# vgchange -ay
2 logical volume(s) in volume group "LVM120" now active
# lvchange -ay /dev/mapper/LVM120-root
Now to summarise to this point:
# pvdisplay
--- Physical volume ---
PV Name /dev/hda2
VG Name LVM120
PV Size 74.29 GB / not usable 1.42 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 19018
Free PE 0
Allocated PE 19018
PV UUID qoetx0-FgRU-F8Bj-ITdx-M3UZ-xpSi-AZe3M5
--- Physical volume ---
PV Name /dev/hdb1
VG Name LVM120
PV Size 76.69 GB / not usable 4.00 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 19632
Free PE 19632
Allocated PE 0
PV UUID zaFBkJ-YARB-Nlj2-So1Z-PiMA-kVgW-GeoisR
# vgdisplay
--- Volume group ---
VG Name LVM120
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 150.98 GB
PE Size 4.00 MB
Total PE 38650
Alloc PE / Size 19018 / 74.29 GB
Free PE / Size 19632 / 76.69 GB
VG UUID buiuWa-IN2B-eQ3z-ynnv-SsYF-ww3p-O1jwct
# lvdisplay
--- Logical volume ---
LV Name /dev/LVM120/root
VG Name LVM120
LV UUID ICF2Ju-qAbk-sXuV-yUFM-DzQU-DM9b-uZQz8r
LV Write Access read/write
LV Status available
# open 1
LV Size 148.44 GB
Current LE 38001
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Name /dev/LVM120/swap_1
VG Name LVM120
LV UUID 6VVPRv-u80U-Mjpp-cJ2E-57yQ-TPpr-0QlpnA
LV Write Access read/write
LV Status available
# open 2
LV Size 2.54 GB
Current LE 649
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
We see the LV size has increased from 71.75 GB to 148.44 GB but this is not
reflected in the root dev size:
# df -h /dev/mapper/LVM120-root
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/LVM120-root 71G 2.4G 65G 4% /
As the root partition was formatted in ext3, it can be re-sized on the fly
without being unmounted, or a rescue disk used to boot the system for this
operation which would be very inconvenient and Microsoft:
# resize2fs /dev/mapper/LVM120-root
resize2fs 1.41.3 (12-Oct-2008)
Filesystem at /dev/mapper/LVM120-root is mounted on /; on-line resizing
required
old desc_blocks = 5, new_desc_blocks = 10
Performing an on-line resize of /dev/mapper/LVM120-root to 38913024 (4k)
blocks.
The filesystem on /dev/mapper/LVM120-root is now 38913024 blocks long.
Now df shows the full allocation size:
LVM150:~# df -h /dev/mapper/LVM120-root
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/LVM120-root
147G 19G 121G 14% /
Note that the FS will be checked next reboot due to different superblock
sizes, and rebooted again after.
Finished!
Steve 2008-2022