Professional Documents
Culture Documents
Mint and the other had contained a NTFS partition to share with Windows. Now I removed the
NTFS partition and want to extend my logical volume group to use the released disk space.
How do I extend the volume group, my logical volume containing /home and the filesystem (ext4)
on /home? Is this possible to do online?
/dev/sdb/ (240GB)
linuxvg (160GB) should use 100% of the disk space
swap
root
home (ext4, 128GB) should be extended to use the remaining space
Well, the easy way would've been to just pvcreate the NTFS partition and use vgextend, instead of
removing the partition entirely. If you grow the existing PV partition instead you probably have to
reboot, as Linux refuses to re-read the partition table while the disk is in use. Working around this
online is awkward.
The question was solved, after reading this blog post. I will write the solution in short form:
1) boot from a live cd with
2) use gdisk (if you use GPT) otherwise you could go with good old fdisk
3) note your partition settings, in my case gdisk -l /dev/sdb
4) delete your partition with
5) create a new partition with the exact same alignment as the previous one (in my example
starting at block 2048)
6) write your new partition table
7) run partprobe -s to refresh the partition table without a reboot
8) resize your PV with pvresize /dev/sdb1 or wherever your pv is (use pvs to determine if you
don't know)
9) now resize your logical volume with lvextend -l +100%FREE /dev/file/of/your/lv, in my case
sudo lvextend -l +100%FREE /dev/linuxvg/home
10) resize the filesystem sudo resize2fs /dev/linuxvg/home
11) first check the consistency sudo e2fsck -f /dev/linuxvg/home
You can do this entire process while running on the filesystem you want to resize (yes, it's safe and
fully supported). There is no need for rescue CDs or alternate operating systems.
1). Resize the partition (again, you can do this with the system running). GParted is easy to use
and supports resizing.
You can also use a lower level tool such as fdisk. But you'll have to delete the partition and recre
ate it. Just make sure when doing so that the new partition starts at the exact same location.
2). Reboot. Since the partition table was modified on the running system, it won't take effect until
a reboot.
3). Run pvresize /dev/sdXY to have LVM pick up the new space.
4). Resize the logical volume with lvextend. If you want to use the whole thing:
lvextend -r -l +100%FREE /dev/VGNAME/LVNAME. The -r will resize the filesystem as well.
Though I always recommend against using the entire volume group. You never know what you'll
need in the future. You can always expand later, you can't shrink.
LVM allows great level of indirection. A logical volume is inside a volume group, which could be
using several disks.
home --> linuxvg --> (sdb1, sdb2, sdc1)
http://tldp.org/HOWTO/LVM-HOWTO/createvgs.html
If you're using xfs, then you use the command : xfs_growfs –d /mountpoint
rather than resize2fs. You can do that while that FS mount is active, such as if you've grown the
root partition, and you don't need to reboot after.
*** This is a step by step procedure to discover the LUNS in Linux which are allocated from stora
ge end and then create a Volume group with those LUNS using Linux LVM2 ***
* * After executing the 2nd step, you will receive message from HDLM stating that, there is a
change in configuration, which indicates that LUN’s are identified in server.
* * Then take the device files of those new LUN’s. Ex: /dev/sddlmaX
* * Here the LUN’s i’ve got are as follows. Total 5 LUN’s, each 100 GB.
/dev/sddlmag
/dev/sddlmah
/dev/sddlmai
/dev/sddlmaj
/dev/sddlmak
# lvm vgcreate data2vg /dev/sddlmag – Created VG with name “data2vg” adding disk
/dev/sddlmag to it and then add remaining four Lun’s into VG “data2vg” with following cmd.
# vgextend data2vg /dev/sddlmai
# vgextend data2vg /dev/sddlmaj
# vgextend data2vg /dev/sddlmak
# pvs – Shows Physical Volume info.
PV VG Fmt Attr PSize PFree
/dev/sddlmaa datavg lvm2 a- 100.00G 0
/dev/sddlmab datavg lvm2 a- 100.00G 0
/dev/sddlmac datavg lvm2 a- 100.00G 0
/dev/sddlmad datavg lvm2 a- 100.00G 0
/dev/sddlmae datavg lvm2 a- 100.00G 0
/dev/sddlmaf prodvg lvm2 a- 50.00G 0
/dev/sddlmag data2vg lvm2 a- 100.00G 100.00G
/dev/sddlmah data2vg lvm2 a- 100.00G 100.00G
/dev/sddlmai data2vg lvm2 a- 100.00G 100.00G
/dev/sddlmaj data2vg lvm2 a- 100.00G 100.00G
/dev/sddlmak data2vg lvm2 a- 100.00G 100.00G
* * “data2vg” has 5 PV’s each 100GB as said earlier. #lvs is not complete unless we create logical
volume for this VG. Hence it looks as follows.
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
datalv datavg -wi-ao 499.98G
prodlv prodvg -wi-ao 50.00G
* * #vgs is complete as volume group is created and looks fine from below output.
# vgs
VG #PV #LV #SN Attr VSize VFree
data2vg 5 0 0 wz–n- 499.98G 499.98G
datavg 5 1 0 wz–n- 499.98G 0
prodvg 1 1 0 wz–n- 50.00G 0
* * To create LV, we need to know the No.of PE’s (Physical Extent) for that particular Volume
Group created.We can get that Number by #vgdisplay data2vg
# vgdisplay data2vg
— Volume group —
VG Name data2vg
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 5
Act PV 5
VG Size 499.98 GB
PE Size 4.00 MB
Total PE 127995
Alloc PE / Size 0/0
Free PE / Size 127995 / 499.98 GB
VG UUID 9tBXcp-rLL0-ZWLD-8eMi-70N0-RTuU-Z75XgD
* * Now create the directory and give it appropriate permissions required and mount the VG / File
system that is created.
# mkdir /oradata
# chown oracle:dba /oradata
# chmod 777 /oradata
# mount /dev/data2vg/data2lv /oradata
# df -Th /oradata
/dev/mapper/data2vg-data2lv ext3 493G 198M 467G 1% /oradata
Below is another example of the same file where it's using a different storage vendor.
# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: HP 36.4G Model: MAN3367MC Rev: HP05
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 00 Lun: 00
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
Type: Unknown ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 00 Lun: 02
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 00 Lun: 03
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 00
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
Type: Unknown ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 02
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi2 Channel: 00 Id: 01 Lun: 03
Vendor: COMPAQ Model: HSV110 (C)COMPAQ Rev: 2003
You can use iscsiadm (only used when storage using iscsi target) command to get information
about attached lun.
# iscsiadm -m session -P 3
iSCSI Transport Class version 2.0-870
version 6.2.0.873-35
Target: iqn.2017-06.com.linoxide:target1 (non-flash)
Current Portal: 172.16.20.139:3260,1
Persistent Portal: 172.16.20.139:3260,1
**********
Interface:
**********
............
............
************************
Attached SCSI devices:
************************
Host Number: 3 State: running
scsi3 Channel 00 Id 0 Lun: 0
Attached scsi disk sdd State: running
scsi3 Channel 00 Id 0 Lun: 1
Attached scsi disk sde State: running
scsi3 Channel 00 Id 0 Lun: 2
Attached scsi disk sdf State: running