User Tools

Site Tools


linux:create_swap

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
linux:create_swap [2024/05/16 09:22]
manu
linux:create_swap [2024/05/16 09:37] (current)
manu
Line 6: Line 6:
  
 Create the LVM2 logical volume of size 256 MB: Create the LVM2 logical volume of size 256 MB:
-  ​# lvcreate -L 1G -n LogVol02 VolGroup00 ​+<cli prompt='#'>​ 
 +# lvcreate -L 1G -n LogVol02 VolGroup00 ​ 
 +</​cli>​
  
 Format the new swap space: Format the new swap space:
-  ​# mkswap /​dev/​VolGroup00/​LogVol02+<cli prompt='#'>​ 
 +# mkswap /​dev/​VolGroup00/​LogVol02 
 +</​cli>​
  
 Add the following entry to the /etc/fstab file: Add the following entry to the /etc/fstab file:
Line 15: Line 19:
  
 Enable the extended logical volume: Enable the extended logical volume:
-  ​# swapon -va+<cli prompt='#'>​ 
 +# swapon -va 
 +</​cli>​
  
 Test that the logical volume has been extended properly: Test that the logical volume has been extended properly:
-  ​# cat /proc/swaps # free+<cli prompt='#'>​ 
 +# cat /proc/swaps # free 
 +</​cli>​
  
 +<cli prompt='#'>​
 swapoff /dev/hda3 swapoff /dev/hda3
 mkswap /dev/hda4 mkswap /dev/hda4
 swapon /dev/hda4 swapon /dev/hda4
 +</​cli>​
  
 and edit swap entry in /etc/fstab and edit swap entry in /etc/fstab
  
-How to Increase Swap Space in Linux?+==== How to Increase Swap Space in Linux? ​====
  
 Check the current swap space Check the current swap space
-<​cli>​ +<​cli ​prompt='#'​
-[root@lnxb080 ​~]# free+[root@lnxb080 ​etc]# free -h
               total        used        free      shared ​ buff/​cache ​  ​available               total        used        free      shared ​ buff/​cache ​  ​available
-Mem:        ​7793408 ​    ​1477056 ​     787968 ​     393280 ​    ​5528384 ​    ​5224384 +Mem:          ​7.4Gi ​      ​1.4Gi ​      ​784Mi ​      ​384Mi ​      ​5.3Gi ​      5.0Gi 
-Swap:       2097088 ​     216448 ​    ​1880640+Swap:         2.0Gi       ​211Mi       ​1.8Gi 
 [root@lnxb080 ~]# swapon --show [root@lnxb080 ~]# swapon --show
 NAME      TYPE      SIZE   USED PRIO NAME      TYPE      SIZE   USED PRIO
 /dev/dm-6 partition ​  2G 211.4M ​  -2 /dev/dm-6 partition ​  2G 211.4M ​  -2
 +
 [root@lnxb080 ~]# ll /dev/dm-6 [root@lnxb080 ~]# ll /dev/dm-6
 brw-rw---- 1 root disk 253, 6 Jan  8 21:00 /dev/dm-6 brw-rw---- 1 root disk 253, 6 Jan  8 21:00 /dev/dm-6
-[root@lnxb080 ~]# ll /dev/+
 [root@lnxb080 ~]# lsblk [root@lnxb080 ~]# lsblk
 NAME                     ​MAJ:​MIN RM  SIZE RO TYPE  MOUNTPOINT NAME                     ​MAJ:​MIN RM  SIZE RO TYPE  MOUNTPOINT
Line 54: Line 66:
     ├─rootvg-usr ​        ​253:​7 ​   0    3G  0 lvm   /usr     ├─rootvg-usr ​        ​253:​7 ​   0    3G  0 lvm   /usr
 </​cli>​ </​cli>​
 +
 +Disable the swap
 +<cli prompt='#'>​
 +# swapoff -v /​dev/​{swap_partition}
 +</​cli>​
 +
 +Resize the partition
 +
 +Format the ne swap space
 +<cli prompt='#'>​
 +# mkswap /​dev/​{swap_partition}
 +</​cli>​
 +
 +Enable the swap
 +<cli prompt='#'>​
 +# swapon /​dev/​{swap_partition}
 +</​cli>​
 +
 +Check fstab
 +<cli prompt='#'>​
 +[root@lnxb080 etc]# cat fstab
 +...
 +/​dev/​mapper/​rootvg-swap none                    swap    defaults ​       0 0
 +</​cli>​
 +
 +==== Creating a Swap File (instead of partition) ====
 +
 +Create the swap file with 4GB
 +<cli prompt='#'>​
 +# fallocate -l 4G /​swap/​swapfile01
 +or
 +# mkswap -U clear --size 4G --file /​swap/​swapfile01
 +</​cli>​
 +
 +Change the permissions
 +<cli prompt='#'>​
 +# chmod 600 /​swap/​swapfile01
 +</​cli>​
 +
 +Format the swap
 +<cli prompt='#'>​
 +# mkswap /​swap/​swapfile01
 +</​cli>​
 +
 +Add to /etc/fstab
 +  /swapfile none swap defaults 0 0
 +
  
linux/create_swap.1715844171.txt.gz · Last modified: 2024/05/16 09:22 by manu