Difference between revisions of "LVM"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 2: Line 2:
  
 
# Ubuntu LVM
 
# Ubuntu LVM
https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/
+
https://www.cyberciti.biz/faq/howto-add-disk-to-lvm-volume-on-linux-to-increase-size-of-pool/
 +
 
 +
Add new disk in vmware or whatever on host
 +
 
 +
```
 +
sudo pvdisplay
 +
sudo lvdisplay
 +
sudo apt-get install scsitools
 +
sudo rescan-scsi-bus
 +
sudo pvcreate /dev/sdd
 +
sudo lvmdiskscan -l
 +
sudo vgextend {VG Docker Name} /dev/sdd
 +
sudo lvm lvextend l +100%FREE /dev/mapper/vg-docker
 +
sudo resize2fs p /dev/mapper/vg-docker
 +
```
 +
 
 +
 
  
 
# VMWare
 
# VMWare

Revision as of 16:44, 26 February 2021

Extend VM Guest disk drive

Ubuntu LVM

Add new disk in vmware or whatever on host

sudo pvdisplay
sudo lvdisplay
sudo apt-get install scsitools
sudo rescan-scsi-bus
sudo pvcreate /dev/sdd
sudo lvmdiskscan -l
sudo vgextend {VG Docker Name} /dev/sdd
sudo lvm lvextend l +100%FREE /dev/mapper/vg-docker
sudo resize2fs p /dev/mapper/vg-docker

VMWare

https://ahelpme.com/linux/online-resize-of-a-root-ext4-file-system-increase-the-space/

Here you can see how to online resize your root ext4 file system. The free space of your partition will be increased after the operation. The size of the root file system will grow not to shrink. Of course, this could have been any other partition, not exactly the root one, but in most cases, such operations on the root are the more complex and dangerous – SO ALWAYS do backups before such operations!

All services work properly and no shut down of services, no reboot or umount is required during the resize operation.

Still, we rebooted the server once to force check the file system as a precaution, because it was possible and this server was not in production. The reboot of the server after this kind of resizing is not mandatory.
The following methind is tested on a CentOS 7, Ubuntu 16 LTS and Gentoo with kernel 4.15 kernel. So we can assume you may have no problems if your system is newer than our.

Summary
Partition resize – Use resizepart in parted command. All Linux distributions have this package with the same name as the needed command “parted”
File system resize – Use resize2fs from the E2fsprogs package. All Linux distributions include this package mostly with the same name of the package.
STEP 1) Expand the partition, which holds the root partition.
Let’s assume you have changed your disk and now there is more unallocated space to be used or somehow the space of the disk is increased. Look below for a real-world example with one of our virtual servers.

root@srv1 ~ # parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p                                                                
Model: Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  2097kB  1049kB                        bios_grub
 2      2097kB  4096MB  4094MB  linux-swap(v1)
 3      4096MB  24.0GB  19.9GB  ext4
(parted) resizepart 3 -1                                                  
Warning: Partition /dev/sda3 is being used. Are you sure you want to continue?
parted: invalid token: -1                                                 
Yes/No? Yes                                                               
End?  [24.0GB]? -1                                                        
(parted) p                                                                
Model: Model: ATA Samsung SSD 850 (scsi)
Disk /dev/sda: 215GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system     Name  Flags
 1      1049kB  2097kB  1049kB                        bios_grub
 2      2097kB  4096MB  4094MB  linux-swap(v1)
 3      4096MB  215GB   211GB   ext4

(parted) q                                                                
Information: You may need to update /etc/fstab.
As you can see from the first print command the partition number 3 is 19.9GB and after the resize command with “-1” is 211GB. There is a warning about the partition is used, but it is normal and not critical.

STEP 2) Resize the file system, on which we expanded the partition.
You need to install E2fsprogs. All Linux distributions have this package, here are some of them:

CentOS 7 – e2fsprogs
Ubuntu – e2fsprogs
Gentoo – sys-fs/e2fsprogs
After installing the e2fsprogs package you will have the online ext4 resizing tool – resize2fs.

root@srv ~ # resize2fs /dev/sda3
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sda3 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 13
The filesystem on /dev/sda3 is now 51428620 (4k) blocks long.
Check if everything is OK with


root@srv ~ # dmesg|grep EXT4
[  449.330140] EXT4-fs (vda3): resizing filesystem from 4859392 to 51428620 blocks
[  449.936044] EXT4-fs (vda3): resized filesystem to 51428620
root@srv ~ # df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           798M  3.5M  795M   1% /run
/dev/sda3       193G  3.4G  182G   2% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
tmpfs           798M     0  798M   0% /run/user/0
Bonus – you can force check the file system on next reboot
Probably it is a good idea to force check the file system integrity on the next boot. This step is not mandatory and you may skip it.
For Ubuntu you can do:


root@srv ~ # touch /forcefsck
root@srv ~ # reboot

With LVM

https://access.redhat.com/solutions/24770

The following are sample steps to extend a Volume Group (VG), a Logical Volume (LV), and a filesystem using a device named /dev/sdN as its Physical Volume (PV).

Create a PV from a free disk or partition (e.g. /dev/sdN1 as a partition):

Raw
# pvcreate /dev/sdN1
Extend the VG (/dev/sdN1 is an existing PV path):

Raw
# vgextend vgdata /dev/sdN1
Extend the LV and resize the underlying filesystem together (/dev/vgdata/lvdata is the existing LV path), which will be extended by 125 GB:

Raw
# lvextend -r -L +125G /dev/vgdata/lvdata
If the filesystem you are extending is a GFS filesystem, refer to How do I grow a GFS2 file-system on RHEL?.

If unpartitioned disk space is being added to an existing VG to extend a LV and the corresponding file system, refer to How to Increase the Size of an LVM2 Logical Volume.