Challenges to creating and using SWAP files in Ubuntu 18.04

Hello! My brother invited me to join his Civ 6 game recently. An initial diagnosis of my Dell XPS 13 (Ubuntu 18.04) showed I had only 2 gigs however for Steam to use for a swap file. Whenever I activated the game in Steam, it hung on the loading data page… forever!
Having never messed with swap files before I used the excellent Its Foss tutorial on creating Swap Files to get started. I swapoff the file, and mkswap something larger. But oh wait, wasn’t I supposed to fallocate a new swap file. Oops! I just deleted the old swap file (mkswap does that) without adding a new file first! Suddenly my browser and the toolbar disappear. In a panic I power down and attempt to reboot - wrong move apparently. Now I’m stuck at Grub. Every time I try rebooting the Dell leaves me weeping at the Ubuntu splash screen.
Clearly I need a new swap file simply to reboot, much less run Civ 6. Additional homework, including -
https://linuxconfig.org/how-to-reset-lost-root-password-on-ubuntu-18-04-bionic-beaver-linux, https://www.2daygeek.com/shell-script-create-add-extend-swap-space-linux/
-helped me patch together something close to a script for accessing BASH through GRUB. My first run through the Foss process gives notice upon swapon that I just created a four gig file, to whit-
4194300k swap on /swapfile. Priority: -2 extents:29 across : 17580028k SSFS
-looks good huh? To make sure I’m on the same page I run the Its Foss pipe instructions, thinking this will save the swapfile, and activate it for use. I reboot, only to find myself once more left crying on the Ubuntu splash page. I walk back through my process to regain BASH, and free -h returns a swap file, however swapon --show returns nothing.
So what have I done? Did I actually create a swap file I can use? If so how have a failed to inform the system to use it? If not, what pitfalls should I avoid creating a swapfile the second time around? Help! I can already hear the settlers and sails of other Civilizations claiming the globe as their own…

You probably didn’t turn on the created swapfile, which is the reason why you see a file but no actual swap.

However, at this point I strongly recommend to start over, from scratch and follow each step carefully. Then you will have your swapfile, without question.

are you getting a grub> or grub rescue> prompt? if so, have you tried booting in from it: https://www.linux.com/training-tutorials/how-rescue-non-booting-grub-2-linux/

2 Likes

The reboot launched immediately into a series of protocols checking system services and the like. I recall logging service, login and network service all read FAILURE in read, while others read PASS in green. Either this was a system check or the actual reboot. But in any event it didn’t pass muster, cycling endlessly back on itself. I presumed for that reason I was simply seeing the background to the Ubuntu startup screen.

I can boot into the recovery screen, and visit GRUB from there. Then I rw init/bin/bash to rewrite startup and reach BASH.

Thanks Akito. I have walked through this twice, with the same result. That said I’m hardly a master at this. I would rather have this spelled out for you, but I cannot screen capture from the machine in any event.
I will try again in the next forty eight hours, and spell out each step as I go for your review. Again much appreciated!

1 Like

That’s practically impossible. If every step is carried out successfully, you have successfully created and activated a SWAP file.

that sounds like what a normal startup looks like without the ubuntu splash screen, but a more involved issue than just missing swap. can you boot into a live system (usb or dvd) and run fsck on your ubuntu partition(s)?

if you have a chance to grab a copy of your .bash_history when you are in a live boot, i think we will find one of those commands issued to create swap might have done otherwise. a system can run without swap as you saw when you switched it off with swapoff. something happened after that (i believe - possibly mkswap / instead of /swapfile?) that made your browser and toolbar act up and system unable to boot.

2 Likes

I don’t know how to run history through bash as you suggest; I’ll have to investigate. I just ran fsck booting through a USB -
ubuntu@ubuntu:~$ sudo fsck -A /dev/sdb

fsck from util-linux 2.31.1

ubuntu@ubuntu:~$ fsck -A /dev/sdb

fsck from util-linux 2.31.1

ubuntu@ubuntu:~$ fsck -A /dev/sda

fsck from util-linux 2.31.1

ubuntu@ubuntu:~$ fsck -A /dev/hd*

fsck from util-linux 2.31.1

ubuntu@ubuntu:~$ man fsck

ubuntu@ubuntu:~$ fsck -f /dev/sda2

fsck from util-linux 2.31.1

e2fsck 1.44.1 (24-Mar-2018)

fsck.ext2: Permission denied while trying to open /dev/sda2

You must have r/w access to the filesystem or be root

ubuntu@ubuntu:~$ sudo fsck -f /dev/sda2

fsck from util-linux 2.31.1

e2fsck 1.44.1 (24-Mar-2018)

Pass 1: Checking inodes, blocks, and sizes

Pass 2: Checking directory structure

Pass 3: Checking directory connectivity

Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/sda2: 405981/7782400 files (1.1% non-contiguous), 14845673/31127296 blocks

ubuntu@ubuntu:~$ sudo fsck -A

fsck from util-linux 2.31.1

ubuntu@ubuntu:~$ sudo fsck -f /dev/sda1

fsck from util-linux 2.31.1

fsck.fat 4.1 (2017-01-24)

0x41: Dirty bit is set. Fs was not properly unmounted and some data may be corrupt.

  1. Remove dirty bit

  2. No action

? 1

Perform changes ? (y/n) y

/dev/sda1: 18 files, 4193/130812 clusters

Having run this I tried rebooting without success; continues to hang on splash screen. I will look into BASH history next.

Clearly Akito I missed something the first two times around, so I looked to retrace my steps today.

  1. I edit the GRUB menu, rewriting the linux entry from ro quiet splash $vt_handoff to rw init=/bin/bash -I then hit CTRL-X as recommended here. https://linuxconfig.org/how-to-reset-lost-root-password-on-ubuntu-18-04-bionic-beaver-linux note this brings me back to GRUB so I hit c for the command line.

  2. Having achieved root@(none))/# I type free -h. It lists no swap memory

  3. root@(none))/# swapon –show returns nothing.

  4. fallocate -l 4G /swapfile as per https://itsfoss.com/create-swap-file-linux/ it returns root@(none)/#

5. chmod 600 /swapfile which returns same as per ibid

  1. mkswap /swapfile returns “ Setting up swapspace version 1, size = 4 GiB(4294963200 bytes) no label, UUID= 5317-8850-41b6-b075-d6de972fbb17 and root@(none)/# as per Ibd

  2. swapon /swapfile returns { 1014.650463}Adding 4194300k swap on /swapfile. Priority -2 extents: 29 across : 17500028k SSFS

  3. swapon –show returns 1 FILE, SIZE 4G USED 0B PRIO -2 as per Ibd.

  4. I back up the file sudo cp /etc/fstab /etc/fstab.back which returns root@(none)/# as per Ibd.

  5. I enter the following command echo ‘/swapfile none swap sw 0 0’ | tee -a /etc/fstab (Identical to Ibd save that, as I cannot sudo on this command line, I omitted it.) This returns /swapfile none swap sw 0 0 and root@(none)/#

  6. I press the power button, then press it again to start the boot process. Besides mentioning its booting into insecure mode all I get is the splash screen, little orange dots blinking away…

I presume by now you can tell I’m not master of the command line. This said I’m guessing I failed to actually reach my root, as no sudo was used. What did I miss?

bash history is a hidden file in your home directory so its path would be something like /home/user/.bash_history where user is (most often) the username you use to log in with.

if this turns out to be about something other than swap, there are logs in /var/log that may have some info about why you can’t boot properly. Xorg.0.log, kern.log and syslog would probably have the most pertinent data, but it can be a slog to try and find the needle in the haystack if it doesn’t immediately present itself.

i don’t remember anyone asking, but is it possible that you have a system backup that you can revert to?

i missed this when replying about bash history.

did fsck finish the other three steps like it did on the first partition? if not, did you try it again?

apologies for the multi-post. just had a thought about:

you can usually press the esc key to remove the splash screen when it begins to show. you mentioned seeing

that is what i am referring to. if your system will allow you to do that, you may well see the part in the boot process where your system is getting stuck. taking a photo with a phone (or whatever you have. it just needs to be clear enough to read obviously) and posting that could also be helpful.

network failure could be dealt with after boot. login is a different problem entirely and logging failure points to a certain level of brokenness that would make me think about reinstalling.

I found bash by finally working the GRUB command line. As you can see from the attached it looks like I used fallocate to create not one but two swapfiles. One of them appears when I use swapon --show.

both links are giving me 404: not found errors.

Actually we both appear to have missed the obvious: that I wasn’t running fsck on anything other than the ISO disk I had booted. When you look at this photo you’ll see the actual root name appear. Here’s the challenge: I cannot run fsck on /dev/sda2 from Recovery Mode GRUB: e2fsck: Cannot continue, aborting.
However when I run fsck -nf /dev/sda2 it gives me the wrong count on free blocks. Could this bee the issue? If so how do I fix it?

The screen goes black when I press esc when the splash screen shows. I hit esc again and the splash screen reappears…

while the new info is possibly helpful, my assumption was that you were running fsck on the partitions that were problematic. /dev/sda doesn’t tell me anything obvious about your system.

your most recent (this photo) link is also returning a 404 error for me.

Akito, it looks like I have in fact created the swapfile. The challenge now appears to be with block mounts.