- Настройка и управление LVM разделами в Linux
- Установка утилиты lvm2
- How to Delete Volume Group(LVM) in Linux Using 5 Easy Steps
- Delete Volume Group(LVM) in Linux
- 1. Check mounted Logical Volume using df command
- 2. Unmount the Volume using umount command
- 3. Disable Logical Volume using lvchange command
- 4. Delete Logical Volume using lvremove command
- 5. Delete Volume Group using vgremove command
- Удаление LVM
- Удаление физического тома
Настройка и управление LVM разделами в Linux
LVM (Logical Volume Manager) – подсистема операционных систем Linux, позволяющая использовать разные области физического жесткого диска или разных жестких дисков как один логический том. LVM встроена в ядро Linux и реализуется на базе device mapper.
Главные преимущества LVM – высокий уровень абстракции от физических дисков, гибкость и масштабируемость. Вы можете на лету изменять размер логического тома, добавлять (и удалять) новые диски. Для LVM томов поддерживается зекалирование, снапшоты (persistent snapshot) и striping (расслоение данных между несколькими дисками с целью увеличения производительности).
В данной статье мы рассмотрим использование LVM разделов на примере Linux CentOS 8, покажем процесс объединения двух дисков в одну группу LVM, посмотрим как создавать группы, тома, монтировать, расширять и уменьшать размер LVM разделов.
Прежде всего нужно разобраться с уровнями дисковых абстракций LVM.
- Physical Volume (PV) – физический уровень. Физические диски инициализируются для использования в LVM.
- Volume Group (VG) – уровень группы томов. Инициализированные диски объединяются в логические группы с именем.
- Logical Volume (LV) — создается логический том на группе томов, на котором размещается файловая система и данные.
Установка утилиты lvm2
Чтобы начать работу с LVM, нужно установить утилиту lvm2. Выполним следующие команды:
How to Delete Volume Group(LVM) in Linux Using 5 Easy Steps
In this article, I will take you through the steps to delete Volume Group in Linux. Volume group is a logical aggregation of physical volumes in LVM(Logical Volume Manager) Technology. This acts as a storage reservoir in LVM where the storage can be added by adding multiple physical volumes and it can be assigned as well by creating multiple logical volumes. Volume Group provides an abstraction Layer in LVM which allows us to manage the free spaces of multiple storage disks in an effective manner.
Delete Volume Group(LVM) in Linux
1. Check mounted Logical Volume using df command
First you need to check the mounted volume and the mount point name using df -h command. Here you can see that log_grp1 is currently mounted on /u01 mount point. To know more about LVM configuration you can check on How to configure LVM (pvcreate, vgcreate and lvcreate ) in Linux Using 6 Easy Steps.
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 484M 0 484M 0% /dev tmpfs 496M 0 496M 0% /dev/shm tmpfs 496M 6.8M 489M 2% /run tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 1.5G 36G 4% / /dev/sda1 1014M 193M 822M 19% /boot tmpfs 100M 0 100M 0% /run/user/0 /dev/mapper/vol_grp-log_grp1 384M 2.3M 358M 1% /u01
Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to User.
2. Unmount the Volume using umount command
Once you identified the mount point, you need to remove it by using umount /u01 command as shown below.
[root@localhost ~]# umount /u01
After unmounting the logical volume you can further check if there are any other active logical volumes of volume group vol_grp1 is currently mounted.
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 484M 0 484M 0% /dev tmpfs 496M 0 496M 0% /dev/shm tmpfs 496M 6.8M 489M 2% /run tmpfs 496M 0 496M 0% /sys/fs/cgroup /dev/mapper/centos-root 37G 1.5G 36G 4% / /dev/sda1 1014M 193M 822M 19% /boot tmpfs 100M 0 100M 0% /run/user/0
Once everything is verified, you can safely remove any entry from /etc/fstab if available. This will make sure that System will not try to mount something which is unavailable.
[root@localhost ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Thu Apr 23 12:36:31 2020 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=1e70f026-ce6f-4938-a74c-ec9c5f6ce74a /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 #/dev/sdb1 swap swap defaults 0 0 #/root/testswap swap swap defaults 0 0 #/dev/vol_grp/log_vol swap swap defaults 0 0
3. Disable Logical Volume using lvchange command
Now to we need to disable all the associated logical volume before moving ahead and delete volume group from the System. You can disable the logical volume log_grp1 by using lvchange -an /dev/vol_grp/log_grp1 command as shown below.
[root@localhost ~]# lvchange -an /dev/vol_grp/log_grp1
Check Logical Volume status using lvscan command. You can check from below output log_grp1 is now showing in inactive state. Similarly you need to disable all the logical volume associated with Volume Group vol_grp using lvchange command as shown above.
[root@localhost ~]# lvscan ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit inactive '/dev/vol_grp/log_grp1' [400.00 MiB] inherit ACTIVE '/dev/centos/swap' [2.00 GiB] inherit ACTIVE '/dev/centos/root' [36.99 GiB] inherit
4. Delete Logical Volume using lvremove command
Now delete the logical volume log_grp1 using lvremove /dev/vol_grp/log_grp1 command as shown below. Similarly delete all the logical volume that is associated with Volume group vol_grp using lvremove command.
[root@localhost ~]# lvremove /dev/vol_grp/log_grp1 Logical volume "log_grp1" successfully removed
Check Logical Volume Status again by running lvscan command. You can see from below output log_grp1 does not exists now and hence it is removed.
[root@localhost ~]# lvscan ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit ACTIVE '/dev/centos/swap' [2.00 GiB] inherit ACTIVE '/dev/centos/root' [36.99 GiB] inherit
5. Delete Volume Group using vgremove command
Once all the Logical Volume are deleted you can now delete volume Group vol_grp using vgremove vol_grp command as shown below.
[root@localhost ~]# vgremove vol_grp Volume group "vol_grp" successfully removed
To verify you can run vgscan and get confirmed if vol_grp is removed or not. As you can see from below output vol_grp does not exists now.
[root@localhost ~]# vgscan Reading volume groups from cache. Found volume group "centos" using metadata type lvm2
Popular Recommendations:-
Удаление LVM
Сначала надо убедиться, что раздел не смонтирован.
mount -l — посмотреть список смонтированных разделов.
[root@server2 dev]# mount -l sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=1923948k,nr_inodes=480987,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,pids) cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,blkio) cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,net_prio,net_cls) cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,memory) cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,hugetlb) cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,perf_event) cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,freezer) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuacct,cpu) cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,cpuset) cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,seclabel,devices) configfs on /sys/kernel/config type configfs (rw,relatime) /dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota) selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime) systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=31,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13195) mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel) debugfs on /sys/kernel/debug type debugfs (rw,relatime) /dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota) /dev/mapper/vgdata-lvdata on /mnt/lvdata type xfs (rw,relatime,seclabel,attr2,inode64,noquota) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=387136k,mode=700)
[root@server2 dev]# umount /mnt/lvdata
Если настроено автомонтирование, удаляем его в /etc/fstab.
Отображаем список групп томов:
[root@server2 dev]# vgdisplay --- Volume group --- VG Name vgdata System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 96.00 MiB PE Size 4.00 MiB Total PE 24 Alloc PE / Size 12 / 48.00 MiB Free PE / Size 12 / 48.00 MiB VG UUID hi6t25-6pAc-j5O9-F9Am-ChC3-PH42-mpg8jt --- Volume group --- VG Name centos 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
[root@server2 dev]# vgremove vgdata Do you really want to remove volume group "vgdata" containing 1 logical volumes? [y/n]: y Do you really want to remove active logical volume vgdata/lvdata? [y/n]: y Logical volume "lvdata" successfully removed Volume group "vgdata" successfully removed
Удаление физического тома
[root@server2 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- /dev/sdc1 lvm2 --- 100.00m 100.00m
[root@server2 ~]# pvremove /dev/sdc1 Labels on physical volume "/dev/sdc1" successfully wiped.