Logical volume increase space or merging

Issues related to applications and software problems
Post Reply
sigolo
Posts: 4
Joined: 2014/10/27 09:54:56

Logical volume increase space or merging

Post by sigolo » 2017/05/20 11:29:23

Hi, I would like to increase the space of a logical volume if possible by merging them together.
I have this situation:

Code: Select all

df -H
File system          Dim. Usati Dispon. Uso% Montato su
/dev/mapper/cl-root   51G  1,5G     50G   3% /
devtmpfs             508M     0    508M   0% /dev
tmpfs                521M     0    521M   0% /dev/shm
tmpfs                521M  6,9M    514M   2% /run
tmpfs                521M     0    521M   0% /sys/fs/cgroup
/dev/sda1            1,1G  200M    865M  19% /boot
/dev/mapper/cl-home   25G   34M     25G   1% /home
tmpfs                105M     0    105M   0% /run/user/0

Code: Select all

fdisk -l
Disk /dev/sda: 79.0 GB, 78999715840 bytes, 154296320 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Identificativo disco: 0x000217a7

Dispositivo Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   154296319    76098560   8e  Linux LVM

Disk /dev/mapper/cl-root: 50.9 GB, 50914656256 bytes, 99442688 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/cl-home: 24.9 GB, 24855445504 bytes, 48545792 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
I would like to merge "/dev/mapper/cl-root 51G 1,5G 50G 3% /" and "/dev/mapper/cl-home 25G 34M 25G 1% /home"
I have to increase "/" to 65GB so i can also give only 15GB by "/home".
these things are possible? can someone halp me? thank you.

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Merging two logical volume

Post by TrevorH » 2017/05/20 11:39:56

You can't directly "merge" them as there is no facility to do so but looking at your space usage, you do have enough space on your current / filesystem to contain all the data that's on /home. Given that, what you need to do is umount /home and then mount it somewhere else - say on /mnt. Now you can (as root)

Code: Select all

umount /home
mount /dev/mapper/cl-home /mnt
cd /mnt
cp -ax . /home/
umount /mnt
This should have copied your data from the existing home LV to the root filesystem. You'll want to edit /etc/fstab and remove the line that mounts that LV on /home now. Now double check that all your data that you want/need is on the root filesystem and accessible under /home before you proceed further as the next steps will destroy the data in the old location. Done? Then now you need to use lvchange -an to set the home LV to inactive so that you can lvremove it. When that's gone you can use lvextend -r -L+YG to add Y GB to your existing / filesystem LV and resize the filesystem on it to use the new space.

That does the "merge" you asked for but does abolish your separate /home filesystem. If you want to keep /home on its own filesystem then you would need to amend those instructions to handle that. I am presuming that the filesystems in use on all your LVs is xfs which is the default on CentOS 7 unless you choose otherwise at install time. If it is xfs then that cannot be made smaller so you cannot directly shrink your current home filesystem but you can back up the contents, make it smaller with lvresize and then re-format it using mkfs and copy the data back.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

sigolo
Posts: 4
Joined: 2014/10/27 09:54:56

Re: Logical volume increase space or merging

Post by sigolo » 2017/05/20 17:39:18

Thank you for your precious informations.
i have thinked, in my case, better to reduce of 15GB "/home" and give that space to "/".
Yes i have filesystem is xfs, so i backuped the contents of "/home", maked it smaller with lvresize and then re-formated it using mkfs and copied the data back. All gone well.

Post Reply