Software >> OS >> Unix >> Linux >> RHEL >> LVM >> How to add new logical volume and add swap space

 

 


## starting with

[root@rhel7sat1 ~]# lsblk
NAME           MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda              8:0    0  200G  0 disk
├─sda1           8:1    0    1G  0 part /boot
└─sda2           8:2    0  199G  0 part
  ├─rhel-root  253:0    0  150G  0 lvm  /
  ├─rhel-swap  253:1    0  7.9G  0 lvm  [SWAP]
  └─rhel-home  253:2    0    9G  0 lvm  /home
sr0             11:0    1 57.7M  0 rom 


## create the new logical volume

[root@rhel7sat1 ~]# lvcreate -L 2G -n swap2 rhel


## format as swap

[root@rhel7sat1 ~]# mkswap /dev/rhel/swap2


## add to swap space

[root@rhel7sat1 ~]# swapon /dev/rhel/swap2


## edit /etc/fstab to make it permanent

[root@rhel7sat1 ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jul 21 21:49:23 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/rhel-root   /                       xfs     defaults        0 0
UUID=1f9b7fed-b01a-4d1e-afec-6b81c9820846 /boot xfs     defaults        0 0
/dev/mapper/rhel-home   /home                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
/dev/mapper/rhel-swap2  swap                    swap    defaults        0 0