0%

Linux: Create a swap

There are two ways to create a swap in Linux.

Use disk partition

Make a partition first

1
fdisk /dev/sda1
1
mkswap /dev/sda1
1
swapon /dev/sda1
1
2
blkid
UUID="40a10328-63e5-4450-8bed-1739bc472d2d"
1
2
vi /etc/fstab
UUID="40a10328-63e5-4450-8bed-1739bc472d2d" swap swap defaults 0 0
1
mount -a

Use a file

1
2
3
dd if=/dev/zero of=/tmp/swap bs=1M count=128
mkswap /tmp/swap
swapon /tmp/swap
1
2
vi /etc/fstab
/tmp/swap swap swap defaults 0 0