I am 100% new to Linux as of yesterday and I seem to have done something wrong. I had the system up and running last night with no obvious issues but today when I try to boot up I get an error and the whole thing fails.

Some background: My computer has a 500 GB SSD which is what Ubuntu (version 20.04.1) was installed onto and a 2TB HDD which I formatted for use last night. I suspect that my issue is related to that fact, because I was able to restart the system multiple times without issue before I formatted it. Unfortunately I do not know enough about Ubuntu to even know where to start, and I could not seem to find any help for my specific situation online.

On startup I'm presented with 3 options

  • Ubuntu
  • Advanced options for ubuntu
  • UEFI Firmware Settings

Here's the specific output I'm getting after selecting Ubuntu:

    [Failed] Failed to activate swap /swapfile
    [Depend] Dependency failed for Swap

Let me know if there's any other information that's relevant to the issue or if there's anything I should try. All advice is appreciated.

Here is the output from running the recommended commands in the root access:

    grep -i swap /etc/fstab
    /swapfile          none          swap    sw          0     0

    ls -al /swapfile
    -rw------- 1 root root 2147483648 Sep 24 03:41 /swapfile
  • It appears there may be a problem with your /etc/fstab file which is a simple text file but contains crucial information about the partitions on your system. Some information about your disk setup would be useful. If you can boot a live USB and look at the partition layout using gparted, that would be great info to edit into your question, along with the contents of fstab. Sep 24 '20 at 23:53
  • From the GRUB menu, choose Advanced Options, then Recovery Mode, then Root Access. Then type grep -i swap /etc/fstab and ls -al /swapfile. Edit your question with that output. Report back. Start comments to me with @heynnema or I'll miss them.
    – heynnema
    Sep 25 '20 at 0:16
  • @heynnema Thanks for the reply. I ran the commands and attached the output. Sep 25 '20 at 0:25
  • Please see my answer, and let's see if we can get you going without too much effort. Report back.
    – heynnema
    Sep 25 '20 at 0:28

That all looks normal, but let's recreate the /swapfile.

Boot to Recovery Mode like you just did, and do this...

Note: Incorrect use of the dd command can cause data loss. Suggest copy/paste.

In the terminal (or root # prompt)...

sudo swapoff -a           # turn off swap
sudo rm -i /swapfile      # remove old /swapfile

sudo dd if=/dev/zero of=/swapfile bs=1M count=4096

sudo chmod 600 /swapfile  # set proper file protections
sudo mkswap /swapfile     # init /swapfile
sudo swapon /swapfile     # turn on swap
free -h                   # confirm nnG RAM and 4G swap

Confirm this /swapfile line at the end of /etc/fstab... and confirm no other “swap” lines...

To edit, use sudo -H gedit /etc/fstab or sudo pico /etc/fstab

/swapfile    none    swap    sw      0   0

reboot                    # reboot and verify operation

Update #1:

/etc/fstab was messed up and causing the file system to be read-only. Only had 1 hour on freshly installed Ubuntu, so I recommended to reinstall Ubuntu again.

UUID="fae3ba3a-abaf-4eca-8139-40d5328d017c" /srv ext4 errors=remount-ro 0
  • Thanks for getting back to me. The first two commands ran fine, but the dd command returned the error "dd: failed to open '/swapfile': Read-only file system" Sep 25 '20 at 0:33
  • Yes, manually. I don't have an easy way to copy them Sep 25 '20 at 0:41
  • sudo dd if=/dev/zero if=/swapfile bs=1M count=4096 Sep 25 '20 at 0:44
  • Wait I had a typo. I fixed it and now it's going crazy Sep 25 '20 at 0:45
  • Yeah, that was a typo. I did have if on the first one and of on the second Sep 25 '20 at 0:47

I've actually had a similar issue. The downside is that I completed a copy from a failed hard drive then Ubuntu decided to complete a small change to my swap. Since my config was not setup properly, everything just broke with the exact same problem.

I solved it in a different way.

So, I followed the same steps as https://askubuntu.com/a/1277621/1168565 from Heynnema and worked wonders but, in my issue, that wasn't the root problem.

In fstab, I had an issue that my root drive wasn't setup (as per normal Ubuntu installation, can be explained later). So, when I added my main hard drive to fstab as /, I was able to boot with no issue.

Here's an example of my fstab:

$ cat /etc/fstab
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=fa1b78f3-9d98-42e3-9a72-a9716000d8f9 /               ext4 defaults 0 0
/swapfile       none     swap   sw   0   0
UUID=b31e2ef4-6240-47d6-8ef9-2b98622603a8 /1tb       ext4 defaults 0 0
UUID=e37a2ae4-74c8-4bd1-b3ad-36ba5904a680 /500gb     ext4 defaults 0 0

So, my line 3 didn't exist before and caused issues since the swap couldn't find / when it was initializing after the update.

But, when I loaded into the recovery system, I was unable to edit fstab since it was in readonly. Simply use the command mount -o remount / and the system will automatically remove the readonly for you to update the /etc/fstab using your preferred text editor.

If your system is having issues or locked you out due to the readonly issue, I would suggest a livecd system to modify your /etc/fstab, then boot normally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.