1

I was doing a memory-heavy project in python and kept getting an error (137 SIGKILL 9, something like that), so I looked up a solution and it said to change the swap size. I copied and pasted the commands I found into terminal, and it started copying some files:

# disable the use of swap
sudo swapoff -a

# create the SWAP file. Make sure you have enough space on the hard disk.
# here is my size, the total size is bs*count B
sudo dd if=/dev/zero of=/swapfile bs=1024 count=136314880 status=progress
# output:
# 139458259968 bytes (139 GB, 130 GiB) copied, 472 s, 295 MB/s
# 136314880+0 records in
# 136314880+0 records out
# 139586437120 bytes (140 GB, 130 GiB) copied, 472.372 s, 296 MB/s

# Mark the file as SWAP space:
sudo mkswap /swapfile
# output:
# Setting up swapspace version 1, size = 130 GiB (139586433024 bytes)
# no label, UUID=25a565d9-d19c-4913-87a5-f02750ab625d

# enable the SWAP.
sudo swapon /swapfile

# check if SWAP is created
sudo swapon --show
# output:
# NAME      TYPE SIZE USED PRIO
# /swapfile file 130G   0B   -2

# Once everything is set, you must set the SWAP file as permanent, else you will lose the SWAP after reboot. Run this command:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

After a while (it reached about 40 GB I think), my system gave me a message that it was running out of space. Then the terminal finished working, i pasted the rest of the commands to set up the swap, and rebooted my computer. Then, when I booted up again, this message showed:

/dev/nvme0n1p6: clean, 1090638/907808 files, 35521979/36801792 blocks

And it doesn't boot after this. I started it in recovery mode, tried some of the options there (like clean - try to free up some space, etc), but nothing worked. This is the system summary:

screenshot showing disk usage

screenshot showing memory usage

I believe that I should have checked if I had enough space on my disk before doing the swap change. Also, I think this upgraded my swap to 40 + GB, when I wanted it to get to 8 GB max... How do I solve this problem and save my data? This project is really important to me and I would hate to lose it... Can I reverse the changes I made in the terminal in recovery mode? Thanks in advance!!!

2
  • Please edit your question and include the commands you ran. The phrase "I copied and pasted the commands I found into terminal" is both extremely worrying (you could have done anything) and not very informative. That said, your system summary shows you have no space on your root partition, so you will need to clean some files out.
    – terdon
    Jul 12, 2021 at 11:06
  • @terdon sorry, I found the code and pasted it in. I realize that I ran out of space, and I think that the copying wasn't finished, so the files that were copied are the ones causing the problem. How can I locate them and delete them?
    – zermelo
    Jul 12, 2021 at 11:32

1 Answer 1

4

It seems you’ve asked your computer to make a 130GB swap file rather than an 8GB file. You will need to do the following:

  1. Boot into recovery (or with a Live USB stick)
  2. Confirm that you’re not using a swap file:
    sudo swapoff -a
    
  3. Delete the oversized swap file that you created:
    sudo rm -f /swappyswapswap
    
    IMPORTANT: You will need to change the name of the file in this command from swappyswapswap to the proper name of the big swap file in your / directory. The file name in this command is intentionally wrong so that you — hopefully — do not blindly copy a sudo rm command, as there is no undo.
  4. Confirm your system now has space:
    df -h
    
  5. Create an 8GB file full of zeros, which will become your swap:
    sudo dd if=/dev/zero of=/swapfile bs=1M count=8192 status=progress
    
  6. Set the new file as your swap:
    sudo mkswap /swapfile
    
  7. Add the new swap file to your /etc/fstab file:
    sudo vi /etc/fstab
    
    Note: Feel free to use any text editor of your choosing to modify this file. Just remember to open the file with sudo as it is owned by root.

    Add this line to the bottom:
    /swapfile    none    swap    sw    0    0
    
    This will ensure the swap file is mounted every time you reboot.
  8. Restart the system normally.

Be sure to read, understand, and agree with every one of these steps before copy/pasting them.

3
  • Thank you, that worked! Only problem is that this tried to create a 80 GB swap, so I changed bs=10M count=8192 to bs=1G count = 8
    – zermelo
    Jul 13, 2021 at 8:31
  • Apologies. My math was off … 🤐
    – matigo
    Jul 13, 2021 at 9:23
  • Oh this is even better, taught me to think with my own head :D
    – zermelo
    Jul 13, 2021 at 13:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .