Host and fstab file messed up after try to change swap size

I was trying to increase the swap size of my Ubuntu. I, naïve, followed the steps of this answer:

Check the swap that is in use:

sudo swapon -s

If swap partition(s) are found:

sudo swapoff -a
sudo nano -Bw /etc/fstab

Add # before the UUID of the swap partition(s):

# UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX   none   swap    sw     0       0

Add a line for the swapfile, if one does not exist:

swapfile   none    swap     sw      0       0

Create the swapfile:

sudo fallocate -l XG /swapfile*

where X is swapfile's size in GB:

sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile

Reboot:

sudo reboot

After that, my computer only starts in recovery mode.

I tried to follow this anwser. But the error unable to resolve host my-laptop-name: Temporary failure in name resolution appears and make the process to fail.

I tried to fix it following another answer that says that the name of the host in /etc/hostname and /etc/hosts must be the same. It was wrong in /etc/hosts. But the file is read-only and I can’t write on it, even with sudo.

I checked /etc/fstab and notice that I, dumb, put # to the UUID to the the boot disk, not only to the swap thing. I tried to erase the #. But that file is read-only too. I want to kill myself right now :).

If it’s not clear after all this, I don’t know much about Linux.

Edit 1:

My version of Ubuntu is Desktop 22.04.3 LTS

When I do sudo sudo nano /etc/fstab to erase # from boot line, [ File '/etc/fstab' is unwritable. The same happens with /etc/hosts.

Edit 2:

I edited the boot option in the GRUB and it worked to edit both /etc/fstab and /hosts.

Now I am struggling because when I try to boot normally the system raises an error about swap. This the error:

[0.219748] ACPI BIOS Error (bug): Could not resolve symbol [_SB.PC00.DGPV],
AE_NOT_FOUND (20230331/psargs-330)
[0.219765 ACPI Error: Aborting method SB.PC00.PEG0.PCRP._OFF due to previous error (AE_NOT_FOUND) (20230331/psparse-596)

/dev/nvme0n1p2: clean, 848739/15597568 files, 29875721/62383360 blocks

[2.251365] systemd[1]: Failed to activate swap /swapfile.
[FAILED] Failed to activate swap /swapfile.
[DEPEND] Dependency failed for Swaps.

[3.057060] iwlwifi <ipv6> BIOS contains WGDS but no WRDS

I tried to recreate swap file like in this answer. These are the commands I run to do so:

swapoff -a
rm /swapfile 
dd if=/dev/zero of=/swapfile bs=1M count=4096
chmod 600 /swapfile

mkswap /swapfile
#anwer to this line is:
# setting up swapspace version 1, size 4 GiB
# no label, UUID=<long UUID>

swapon /swapfile

Then I review /etc/fstab. At the end there’s the line /swapfile none swap sw 0 0. There’s the line with UUID with the boot partion too. But there’s no line with the UUID that mkswap /swapfile returned. And the error when trying to boot still happens.

Asked By: Simón

||

The default Linux command line mounts root as read-only on boot (more precisely, just after initramfs).

The safest way is to do the following:

  • Reboot to GRUB; if you are greeted with a blank screen, hit Esc.
  • Select Ubuntu’s boot entry. Don’t hit Enter; instead, edit the boot entry. The bottom of the GRUB menu tells you what you can do.
  • There is a line starting with linux. Remove all ro parameters from that line. Go to the end of that line and add the parameter rw.
  • Boot. Refer to the bottom of the screen for instructions.
Answered By: mcendu

You can fix this! When I was starting with Ubuntu I broke my systems with fstab so many times I wrote down a procedure for how to fix them. Here ya go:

  1. Boot the computer to an Ubuntu live USB and select "try Ubuntu"
  2. Open a terminal and issue a sudo blkid , this will list the drives and partitions with UUIDs and labels. Identify the system partition.
  3. In the terminal issue a sudo mount /dev/sd__ /mnt where sd__ is
    the system partition you determined in step 2, probably sda1. Notice the space before /mnt
  4. Edit fstab and fix the problem with a sudo nano /mnt/etc/fstab Be sure to save your work.
  5. Reboot into your fixed system! Remember to remove the live USB.
Answered By: Organic Marble