Skip to content

Instantly share code, notes, and snippets.

@linuxkathirvel
Last active April 13, 2018 07:46
Show Gist options
  • Save linuxkathirvel/761e99ae6c99e639eb70005575e248d7 to your computer and use it in GitHub Desktop.
Save linuxkathirvel/761e99ae6c99e639eb70005575e248d7 to your computer and use it in GitHub Desktop.

Add swap partition in CentOS7

  1. Create new partition using fdisk /dev/sda with needed swap size
  2. Change change partition type as LVM by partition code 8e using t option in fdisk
  3. Save changes using w option
  4. Reboot CentOS7
  5. Create PV using pvcreate /dev/sdaX. 'X' will be newly created partition number.
  6. Get VG name using vgdisplay
  7. Extend VG size using vgextend centos /dev/sdaX
  8. After extending VG size create Logical Volume using lvcreate centos -n swap -L 4G. Here, 'centos' in VG name and 'swap' is LV name
  9. mkswap /dev/centos/swap. Here, '/dev/centos/swap' is LV path
  10. Add swap partition details in vim /etc/fstab
/dev/centos/swap        swap                    swap    defaults        0 0
  1. Execut swapon -va
  2. Check swap size using free -h command.

Reference

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/5/html/deployment_guide/s1-swap-adding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment