Creating a SWAP partition in a LVM
Assuming that you have already created a physical volume ==> volume group.
If not then click here.....
Now firstly create a logical volume.
Check the free space in your volume group by firing a command in terminal as vgdisplay VOLUMEGROUP NAME.
[root@sunny ~]# vgdisplay vg_sunny
--- Volume group ---
VG Name vg_sunny
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 14.51 GiB
PE Size 4.00 MiB
Total PE 3714
Alloc PE / Size 3204 / 12.52 GiB
Free PE / Size 510 / 1.99 GiB
VG UUID XdBCWB-sQw5-JQvn-v0an-VOWi-fIs9-Q7uEmm
Don't forget to add entry of new swap space in /etc/fstab file.
If not then click here.....
Now firstly create a logical volume.
Check the free space in your volume group by firing a command in terminal as vgdisplay VOLUMEGROUP NAME.
[root@sunny ~]# vgdisplay vg_sunny
--- Volume group ---
VG Name vg_sunny
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 14.51 GiB
PE Size 4.00 MiB
Total PE 3714
Alloc PE / Size 3204 / 12.52 GiB
Free PE / Size 510 / 1.99 GiB
VG UUID XdBCWB-sQw5-JQvn-v0an-VOWi-fIs9-Q7uEmm
This command shows that in this volume group we still have a free space of 1.99GB.
Now we need to create a logical volume by the help of lvcreate command.
[root@sunny ~]# lvcreate -L 100M -n lv-swap-new vg_sunny
Logical volume "lv-swap-new" created
Now just format the newly created logical volume to swap.
[root@sunny ~]# mkswap /dev/vg_sunny/lv-swap-new
mkswap: /dev/vg_sunny/lv-swap-new: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=0bac54cc-eff5-4f6d-af00-f82b83132a20
Now you have successfully created your swap partition now for using this what you need to do is just enable that swap partition.
Firstly check the amount of swap space which is presently allocated to your machine's OS.
[root@sunny ~]# free -m
total used free shared buffers cached
Mem: 1506 575 930 0 24 275
-/+ buffers/cache: 275 1230
Swap: 999 0 999
You can do this either via free -m or via swapon -s commands.
[root@sunny ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 1023992 0 -1
Just switch the new swap device on:
[root@sunny ~]# swapon /dev/vg_sunny/lv-swap-new
Now just to verify that your new partition has been activated or not just fire the same command swapon -s (-s is for summary of all your swap partitions).
[root@sunny ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 1023992 0 -1
/dev/dm-2 partition 102392 0 -2
Summary: Previously your swap partition which was allocated to your machine was 999MB but now you have a swap space which is allocated to your machine is 1099MB which can be switched on or switched off as per your requirements.
Now suppose that you need to switch off your swap space which you just created, so for doing that what you need to so is just fire swapoff.
[root@sunny ~]# swapoff /dev/vg_sunny/lv-swap-new
[root@sunny ~]# swap -s
-bash: swap: command not found
[root@sunny ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-1 partition 1023992 0 -1
[root@sunny ~]#
Don't forget to add entry of new swap space in /etc/fstab file.
Thank you!
ReplyDelete