Skip to content

Instantly share code, notes, and snippets.

@jwillmer
Created March 20, 2024 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwillmer/5066f7a64f4105e40d589af7cfe5595f to your computer and use it in GitHub Desktop.
Save jwillmer/5066f7a64f4105e40d589af7cfe5595f to your computer and use it in GitHub Desktop.
Resize partition and add swap to Ubuntu
# disable swap
sudo swapoff -a
# check space
df -h
# check partitions
lsblk
# recreate partition
sudo fdisk /dev/sda
p # show table
d # delete
n # new / confirm existing format
a # optional: mark as bootable
w # save
# check partitions
lsblk
# recognize newly available space
resize2fs /dev/sda1
# check space
df -h
# create new swap file
sudo fallocate -l 8G /swapfile
# set permissions
sudo chmod 600 /swapfile
# make it a swapfile
sudo mkswap /swapfile
# activate the swap
sudo swapon /swapfile
# make the swap permanent
sudo nano /etc/fstab
# add this line
/swapfile none swap sw 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment