linux_wiki:add_new_partitions_and_logical_volumes_and_swap_to_a_system_non-destructively

Add New Partitions And Logical Volumes And Swap To A System Non-destructively

General Information

Different methods of adding swap.


Create new partition with the Logical Volume type

fdisk /dev/sdb
n
Partition type: primary
Partition number: 1
First sector: default
Last sector: +1G
t
Hex code: 8e
w


Setup LVM physical volume, volume group, logical volume

pvcreate /dev/sdb1
vgcreate vglocal /dev/sdb1
lvcreate -n lvswap -L 1G vglocal


Format logical volume with swap, enable, and add to fstab

mkswap /dev/mapper/vglocal-lvswap
swapon /dev/mapper/vglocal-lvswap
 
vim /etc/fstab
 
/dev/mapper/vglocal-lvswap  swap  swap  sw  0 0

Create physical disk partition for swap

fdisk /dev/sdb
n
Partition type: primary
Partition number: 2
First sector: default
Last sector: +1G
t
Hex code: 82
w
  • Hex code 82 is Linux Swap


Create the swap filesystem

mkswap /dev/sdb2
swapon /dev/sdb2
  • edit /etc/fstab if you want persistent changes


View swap space

swapon -s


Activate all swap on /etc/fstab

swapon -a
  • Turn off swap with: swapoff /dev/<devname> or swapoff -a

  • linux_wiki/add_new_partitions_and_logical_volumes_and_swap_to_a_system_non-destructively.txt
  • Last modified: 2019/05/25 23:50
  • (external edit)