[Solved] Resizing LVM

If none of the more specific forums is the right place to ask

[Solved] Resizing LVM

Postby vitaliok78 » 2018-08-31 18:40

I do want to reduce the /home from 100 GB to 25 GB and I do want the remaining free space to assign to /var.

What exact commands should I perform in order to have those LVM partitions be resized as I do want to have it in right place?
Last edited by vitaliok78 on 2018-09-05 16:25, edited 1 time in total.
vitaliok78
 
Posts: 18
Joined: 2018-08-19 16:26

Re: Resizing LVM

Postby GarryRicketson » 2018-08-31 19:30

How to resize a lvm partition on Debian
===============
https://wiki.debian.org/LVM
List of LV commands

lvchange — Change attributes of a Logical Volume.
lvconvert — Convert a Logical Volume from linear to mirror or snapshot.
lvcreate — Create a Logical Volume in an existing Volume Group.
lvdisplay — Display the attributes of a Logical Volume.
lvextend — Extend the size of a Logical Volume.
lvreduce — Reduce the size of a Logical Volume.
lvremove — Remove a Logical Volume.
lvrename — Rename a Logical Volume.
lvresize — Resize a Logical Volume.
lvs — Report information about Logical Volumes.
lvscan — Scan (all disks) for Logical Volumes.

Or you can use the
'fdisk' command, use the 'man fdisk' command to get details,
or can use the command 'gparted', if you have "gparted" installed.
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Resizing LVM

Postby milomak » 2018-08-31 21:30

this is not for the fainthearted

i suggest you read a number of the links that garry posted to make sure that in your mind you understand what you are doing with each step
iMac - MacOS and Windows 10 (Bootcamp)/ Debian Sid (External SSD)
Laptop (64-bit) - Debian Sid, Win10,
Kodi Box - Debian Sid
milomak
 
Posts: 1798
Joined: 2009-06-09 22:20

Re: Resizing LVM

Postby GarryRicketson » 2018-08-31 22:14

If the OP at least showed us the existing partitions, structure, someone might be able to
give some better details, the 'df' command is good for that :
Example:
Code: Select all
man df
and show us what
Code: Select all
df -h
shows.
Please use code boxes.
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Resizing LVM

Postby milomak » 2018-08-31 22:19

would be helpful also to know what filesystem is being used
iMac - MacOS and Windows 10 (Bootcamp)/ Debian Sid (External SSD)
Laptop (64-bit) - Debian Sid, Win10,
Kodi Box - Debian Sid
milomak
 
Posts: 1798
Joined: 2009-06-09 22:20

Re: Resizing LVM

Postby p.H » 2018-09-01 08:44

Please post the output of
Code: Select all
lsblk
df -hT

so we know more about your installation and can provide adequate advice.
Some filesystems types such as XFS cannot be reduced.

General steps :
Login directly as root, or preferably boot in rescue/maintenance/emergency/single user mode.
Unmount /home unless its filesystem type allows online shrinking (such as BTRFS or NILFS2).
Reduce the home filesystem with the appropriate tool (resize2fs for the ext* family).
Reduce the home logical volume to the same (or bigger, NOT smaller) size with lvreduce.
If a logical volume for /var does not already exist :
- Create a new logical volume for /var with lvcreate.
- Create a filesystem in the logical volume with the appropriate tool (mkfs.ext* for ext*).
- Mount the logical volume on a temporary mount point.
- Copy the contents of /var into the mount point.
- Reboot the system.
- Edit /etc/fstab to automatically mount the logical volume on /var at boot.
- If everything works as expected, bind mount / on a temporary directory to access the old contents hidden under /var and delete it.
If a logical volume for /var already exists :
- Extend the logical volume with lvextend.
- Resize the filesystem in the logical volume with the appropriate command (resize2fs for ext*)
- Remount /home if you had to unmount it.

Or you can do all this in a live system.

GarryRicketson wrote:Or you can use the
'fdisk' command, use the 'man fdisk' command to get details,
or can use the command 'gparted', if you have "gparted" installed.

Fdisk and gparted cannot handle LVM logical volumes. Gparted can only be used to resize a partition containing an LVM physical volume.
Last edited by p.H on 2018-09-05 06:59, edited 1 time in total.
p.H
 
Posts: 631
Joined: 2017-09-17 07:12

Re: Resizing LVM

Postby GarryRicketson » 2018-09-01 15:55

Thanks, some of the search results, mentioned fdisk and gparted, but just goes to show,... Apology on my part for the mis-information.

Looking at the Debian wiki: https://wiki.debian.org/LVM
Installation

All tools to manage an LVM volume are available in lvm2 package

Code: Select all
sudo apt-get install lvm2


If the OP does not have that installed, they will need it to be able to use the 'LVM' commands.
I am not posting all of what the wiki says, the OP needs to really look at that,
to get the details, but there seems to be a GUI available, :
If needed, you can install system-config-lvm, it's a utility for graphically configuring Logical Volumes.


!!!MOST IMPORTANT!!!!
Make a good backup first, before doing anything to change your partitions, and make sure the backup will work. There is no 100% safe way to do this, there is all ways the possibility something can go wrong.
Probably if the OP has good instructions, and follows the steps closely, nothing will go wrong, but there is no way anybody can guarantee nothing will go wrong. Make a good back up first. IF the OP does not know how to do that, then they need to concentrate on learning how to do that first.
==== edited, NOTE: ====
I have been looking at the various search results, on How to resize a LVM partition, and still am not finding any really good, clear tutorial, step by step:
(some that look good, but are not for Debian, and clearly state that on others distro , it might be different)
Which seems to be what the OP wants/needs
What exact commands should I perform in order to have those LVM partitions be resized as I do want to have it in right place?

One main reason none of the tutorials are easy to follow is there are many, variations, like what filesystem, etc,...so any way, with more details, some one might be able to walk the OP through this. Thanks
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Resizing LVM

Postby belligerent_poodle » 2018-09-01 18:58

I've found this of a little help in my situation. It's because I have a ext4 partition type:
https://www.systutorials.com/5621/extending-a-mounted-ext4-file-system-on-lvm-in-linux/
belligerent_poodle
 
Posts: 1
Joined: 2018-05-28 01:13

Re: Resizing LVM

Postby vitaliok78 » 2018-09-04 18:58

GarryRicketson wrote:If the OP at least showed us the existing partitions, structure, someone might be able to
give some better details, the 'df' command is good for that :
Example:
Code: Select all
man df
and show us what
Code: Select all
df -h
shows.
Please use code boxes.



Filesystem Size Used Avail Use% Mounted on
/dev/dm-0 8.2G 3.8G 3.9G 50% /
udev 10M 0 10M 0% /dev
tmpfs 778M 8.9M 769M 2% /run
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 236M 33M 191M 15% /boot
/dev/mapper/zeus--vg-var 2.7G 2.7G 0 100% /var
/dev/mapper/zeus--vg-tmp 360M 2.1M 335M 1% /tmp
/dev/mapper/zeus--vg-home 128G 40G 82G 33% /home
tmpfs 389M 0 389M 0% /run/user/0
vitaliok78
 
Posts: 18
Joined: 2018-08-19 16:26

Re: Resizing LVM

Postby vitaliok78 » 2018-09-04 19:01

p.H wrote:Please post the output of
Code: Select all
lsblk
df -hT

so we know more about your installation and can provide adequate advice.
Some filesystems types such as XFS cannot be reduced.

General steps :
Login directly as root, or preferably boot in rescue/maintenance/emergency/single user mode.
Unmount /home unless its filesystem type allows online shrinking (such as BTRFS or NILFS2).
Reduce the home filesystem with the appropriate tool (resize2fs for the ext* family).
Reduce the home logical volume to the same (or bigger, NOT smaller) size with lvreduce.
Create a new logical volume for /var with lvcreate.
Create a filesystem in the logical volume with the appropriate tool (mkfs.ext* for ext*).
Mount the logical volume on a temporary mount point.
Copy the contents of /var into the mount point.
Edit /etc/fstab to automatically mount the logical volume on /var at boot.
Reboot the system.
If everything works as expected, bind mount / on a temporary directory to access the old contents hidden under /var and delete it.

Or you can do all this in a live system.

GarryRicketson wrote:Or you can use the
'fdisk' command, use the 'man fdisk' command to get details,
or can use the command 'gparted', if you have "gparted" installed.

Fdisk and gparted cannot handle LVM logical volumes. Gparted can only be used to resize a partition containing an LVM physical volume.


lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 149.1G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 148.8G 0 part
├─zeus--vg-root 254:0 0 8.4G 0 lvm /
├─zeus--vg-swap_1 254:1 0 7.9G 0 lvm [SWAP]
├─zeus--vg-var 254:2 0 2.8G 0 lvm /var
├─zeus--vg-tmp 254:3 0 380M 0 lvm /tmp
└─zeus--vg-home 254:4 0 129.4G 0 lvm /home
sr0 11:0 1 1024M 0 rom

df -hT

Filesystem Type Size Used Avail Use% Mounted on
/dev/dm-0 ext4 8.2G 3.8G 3.9G 50% /
udev devtmpfs 10M 0 10M 0% /dev
tmpfs tmpfs 778M 8.9M 769M 2% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 ext2 236M 33M 191M 15% /boot
/dev/mapper/zeus--vg-var ext4 2.7G 2.7G 0 100% /var
/dev/mapper/zeus--vg-tmp ext4 360M 2.1M 335M 1% /tmp
/dev/mapper/zeus--vg-home ext4 128G 40G 82G 33% /home
tmpfs tmpfs 389M 0 389M 0% /run/user/0
vitaliok78
 
Posts: 18
Joined: 2018-08-19 16:26

Re: Resizing LVM

Postby milomak » 2018-09-04 19:14

right so you have home and var as seperate VGs.

can you provide please provide vgdisplay, pvdisplay and lvdisplay
iMac - MacOS and Windows 10 (Bootcamp)/ Debian Sid (External SSD)
Laptop (64-bit) - Debian Sid, Win10,
Kodi Box - Debian Sid
milomak
 
Posts: 1798
Joined: 2009-06-09 22:20

Re: Resizing LVM

Postby vitaliok78 » 2018-09-04 19:28

milomak wrote:right so you have home and var as seperate VGs.

can you provide please provide vgdisplay, pvdisplay and lvdisplay


vgdisplay

--- Volume group ---
VG Name zeus-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 148.81 GiB
PE Size 4.00 MiB
Total PE 38095
Alloc PE / Size 38095 / 148.81 GiB
Free PE / Size 0 / 0
VG UUID gp90hz-jwIV-V58L-UG7o-JILY-z883-7MsRGn

pvdisplay

--- Physical volume ---
PV Name /dev/sda5
VG Name zeus-vg
PV Size 148.81 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 38095
Free PE 0
Allocated PE 38095
PV UUID ucoGPe-d4T9-Nl9F-rGIj-Mp1L-qJV4-p3M7Qk

lvdisplay

--- Logical volume ---
LV Path /dev/zeus-vg/root
LV Name root
VG Name zeus-vg
LV UUID mGe4TC-fbzf-K3xq-lO1r-bfrY-ftv1-2fRbNt
LV Write Access read/write
LV Creation host, time (none), 2018-07-06 22:25:52 +0300
LV Status available
# open 1
LV Size 8.38 GiB
Current LE 2145
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0

--- Logical volume ---
LV Path /dev/zeus-vg/var
LV Name var
VG Name zeus-vg
LV UUID wY75kH-fWZO-0l1D-kEdX-zQQe-qWDW-S7wEox
LV Write Access read/write
LV Creation host, time (none), 2018-07-06 22:25:52 +0300
LV Status available
# open 1
LV Size 2.79 GiB
Current LE 715
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:2

--- Logical volume ---
LV Path /dev/zeus-vg/swap_1
LV Name swap_1
VG Name zeus-vg
LV UUID ggvQdS-TOXj-8aGA-Bk9Q-6pxW-fi4R-YYbFMV
LV Write Access read/write
LV Creation host, time (none), 2018-07-06 22:25:52 +0300
LV Status available
# open 2
LV Size 7.85 GiB
Current LE 2010
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1

--- Logical volume ---
LV Path /dev/zeus-vg/tmp
LV Name tmp
VG Name zeus-vg
LV UUID acrPFB-z5dt-N7TX-r4FJ-Hzbs-IMMG-2my08S
LV Write Access read/write
LV Creation host, time (none), 2018-07-06 22:25:52 +0300
LV Status available
# open 1
LV Size 380.00 MiB
Current LE 95
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:3

--- Logical volume ---
LV Path /dev/zeus-vg/home
LV Name home
VG Name zeus-vg
LV UUID lQGL8s-1lyF-qCd0-eKMN-8602-Wdif-LOE0kC
LV Write Access read/write
LV Creation host, time (none), 2018-07-06 22:25:52 +0300
LV Status available
# open 1
LV Size 129.41 GiB
Current LE 33130
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:4
vitaliok78
 
Posts: 18
Joined: 2018-08-19 16:26

Re: Resizing LVM

Postby GarryRicketson » 2018-09-05 01:38

Thank you for posting the needed details.
Postby vitaliok78 » 2018-08-31 12:40

I do want to reduce the /home from 100 GB to 25 GB and I do want the remaining free space to assign to /var.


I am not any expert, but it does not look like it will be possible to use
25 gb in the home partition , (to me, any way, it is really hard to sort the info when people do not use code boxes)
But any way here it shows:
Code: Select all
Filesystem                             Type  Size Used Avail Use% Mounted on
/dev/mapper/zeus--vg-home ext4 128G 40G 82G 33% /home

If the home partition is currently using 40G , shrinking it to 25G , will cause quite a few problems. You could still resize it , but make sure you don't go
to small, it would need to be over 40g.
User avatar
GarryRicketson
 
Posts: 5161
Joined: 2015-01-20 22:16
Location: Durango, Mexico

Re: Resizing LVM

Postby vitaliok78 » 2018-09-05 03:42

GarryRicketson wrote:Thank you for posting the needed details.
Postby vitaliok78 » 2018-08-31 12:40

I do want to reduce the /home from 100 GB to 25 GB and I do want the remaining free space to assign to /var.


I am not any expert, but it does not look like it will be possible to use
25 gb in the home partition , (to me, any way, it is really hard to sort the info when people do not use code boxes)
But any way here it shows:
Code: Select all
Filesystem                             Type  Size Used Avail Use% Mounted on
/dev/mapper/zeus--vg-home ext4 128G 40G 82G 33% /home

If the home partition is currently using 40G , shrinking it to 25G , will cause quite a few problems. You could still resize it , but make sure you don't go
to small, it would need to be over 40g.


I do want to extend /var directory.
vitaliok78
 
Posts: 18
Joined: 2018-08-19 16:26

Re: Resizing LVM

Postby p.H » 2018-09-05 07:18

Log in directly as root.
Code: Select all
# unmount /home because an ext4 filesystem cannot be reduced while mounted
umount /home

# resize the ext4 filesystem in logical volume zeus-vg/home to 50G
fsck -f /dev/mapper/zeus--vg-home
resize2fs /dev/mapper/zeus--vg-home 50G

# reduce the logical volume zeus-vg/home to 50G
lvreduce -L50G /dev/mapper/zeus--vg-home

# remount /home
mount /home

# extend the logical volume zeus-vg/var by 20G
lvextend -L+20G /dev/mapper/zeus--vg-var

# resize the ext4 filesystem in logical volume zeus-vg/var to the new volume size
resize2fs /dev/mapper/zeus--vg-var

You can of course adjust the indicated sizes. I advise to not allocate all the available space to /var at once and keep some free space for future growth of any logical volume when needed. Extending a logical volume (and its filesystem) is easy : just repeat the above last two commands.
p.H
 
Posts: 631
Joined: 2017-09-17 07:12

Next

Return to General Questions

Who is online

Users browsing this forum: No registered users and 5 guests

fashionable