Lubuntu - Slow boot - Maybe swapfile or partition

I have noticed that my Lubuntu 20.04 boots slowly. So far, I have read some posts, and I can share you all this info I have collected:

# systemd-analyze blame
19.296s dev-sda5.device                                      
18.412s snapd.service                                        
17.480s networkd-dispatcher.service                          
16.627s accounts-daemon.service                              
15.142s udisks2.service                                      
12.115s dev-loop13.device                                    
11.692s NetworkManager-wait-online.service                   
11.054s dev-loop9.device                                     
11.010s bluetooth.service                                    
11.008s avahi-daemon.service                                 
10.916s dev-loop14.device                                    
10.872s dev-loop17.device                                    
10.831s dev-loop8.device                                     
10.798s dev-loop12.device                                    
10.755s dev-loop19.device                                    
10.734s NetworkManager.service                               
10.716s dundee.service                                       
10.665s dev-loop16.device                                    
10.638s dev-loop18.device                                    
10.604s dev-loop15.device                                    
10.604s dev-loop11.device                                    
 9.929s polkit.service                                       
 9.833s ofono.service                                                                                                                 
 9.176s switcheroo-control.service                                                                                                    
 9.158s thermald.service                                                                                                              
 9.155s systemd-logind.service                                                                                                        
 9.051s wpa_supplicant.service                                                                                                        
 8.573s dev-loop10.device                                                                                                             
 7.504s dev-loop6.device                                                                                                              
 7.450s dev-loop7.device                                                                                                              
 7.439s dev-loop2.device
...

Critical chain is:

# systemd-analyze critical-chain
graphical.target @50.502s
└─multi-user.target @50.502s
  └─kerneloops.service @50.294s +207ms
    └─network-online.target @50.270s
      └─NetworkManager-wait-online.service @38.577s +11.692s
        └─NetworkManager.service @27.837s +10.734s
          └─dbus.service @27.833s
            └─basic.target @27.480s
              └─sockets.target @27.478s
                └─snapd.socket @27.474s +3ms
                  └─sysinit.target @27.408s
                    └─snapd.apparmor.service @26.409s +998ms
                      └─apparmor.service @23.930s +2.464s
                        └─local-fs.target @23.929s
                          └─boot-efi.mount @23.880s +48ms
                            └─systemd-fsck@dev-disk-by\x2duuid-B86C\x2d1FC8.service @23.705s +155ms
                              └─dev-disk-by\x2duuid-B86C\x2d1FC8.device @23.704s

fstab:

    # sudo cat /etc/fstab
    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to name devices
    # that works even if disks are added and removed. See fstab(5).
    #
    # <file system> <mount point>   <type>  <options>       <dump>  <pass>
    # / was on /dev/sda5 during installation
    UUID=5376f975-326e-467b-b615-3c05494fc9c9 /               ext4    errors=remount-ro 0       1
    # /boot/efi was on /dev/sda1 during installation
    /swapfile                                 none            swap    sw              0       0
    UUID=B86C-1FC8 /boot/efi vfat umask=0077 0 1

And blkid shows:

sudo blkid
/dev/sda5: UUID="5376f975-326e-467b-b615-3c05494fc9c9" TYPE="ext4" PARTUUID="e2f7acbc-05"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/loop5: TYPE="squashfs"
/dev/loop6: TYPE="squashfs"
/dev/loop7: TYPE="squashfs"
/dev/sda1: UUID="B86C-1FC8" TYPE="vfat" PARTUUID="e2f7acbc-01"
/dev/loop8: TYPE="squashfs"
/dev/loop9: TYPE="squashfs"
/dev/loop10: TYPE="squashfs"
/dev/loop11: TYPE="squashfs"
/dev/loop12: TYPE="squashfs"
/dev/loop13: TYPE="squashfs"
/dev/loop14: TYPE="squashfs"
/dev/loop15: TYPE="squashfs"
/dev/loop16: TYPE="squashfs"
/dev/loop17: TYPE="squashfs"
/dev/loop18: TYPE="squashfs"
/dev/loop19: TYPE="squashfs"

Also lsbkl outputs this:

#sudo lsbkl -f
# There is more info here, but I think it is not relevant at this point.
#...
sda                                                                       
├─sda1 vfat           B86C-1FC8                               511M     0% /boot/efi
├─sda2                                                                    
└─sda5 ext4           5376f975-326e-467b-b615-3c05494fc9c9  806,9G     7% /
sr0  

gnome-disks smart-data-1:

smart-data-1

gnome-disks smart-data-2:

smart-data-2

free command:

~$ free -h
total        used        free      shared  buff/cache   available
Mem:          5,7Gi       853Mi       409Mi       119Mi       4,4Gi       4,4Gi
Swap:         2,0Gi       1,0Mi       2,0Gi

Do you know what may be happening? I'm guessing that sda1 partition or swapfile may be responsible for this. If it is so, how may a fix it? Thanks in advance!


Your HDD has read/write errors and excessive load/unload errors. The drive may just be old, and pre-failing.

HDD's are much slower than SSD's, and tend to boot much slower. Expect boot times of approximately 30-90 seconds.

CABLES

Re-seat the data and power cables on the rear of the HDD, and the motherboard.

PARTITION TABLE

Your disk should probably be in GPT format... although with a 2014 computer that may be BIOS, not UEFI... that may not be possible.

SWAP

A 2G /swapfile is a little smallish, and we'll increase it to 4G...

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

In the terminal...

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 6G RAM and 4G swap

Edit /etc/fstab, using sudo -H gedit /etc/fstab or sudo pico /etc/fstab.

Confirm this /swapfile line in /etc/fstab... and confirm no other “swap” lines... use SPACES in this line... confirm NO TABS...

/swapfile  none  swap  sw  0  0

reboot                    # reboot and verify operation

BAD BLOCKS

Let's check your disk for any bad blocks...

Note: do NOT abort a bad block scan!

Note: do NOT bad block a SSD

Note: backup your important files FIRST!

Note: this will take many hours

Note: you may have a pending HDD failure

Boot to a Ubuntu Live DVD/USB in “Try Ubuntu” mode.

In terminal...

sudo fdisk -l # identify all "Linux Filesystem" partitions

sudo e2fsck -fcky /dev/sdXX # read-only test

or

sudo e2fsck -fccky /dev/sda5 # non-destructive read/write test (recommended)

The -k is important, because it saves the previous bad block table, and adds any new bad blocks to that table. Without -k, you loose all of the prior bad block information.

The -fccky parameter...

   -f    Force checking even if the file system seems clean.

   -c    This option causes e2fsck to use badblocks(8) program to do
         a read-only scan of the device in order to find any bad blocks.
         If any bad blocks are found, they are added to the bad block
         inode to prevent them from being allocated to a file or direc‐
         tory.  If this option is specified twice, then the bad block scan
         will be done using a non-destructive read-write test.

   -k    When combined with the -c option, any existing bad blocks in the
         bad blocks list are preserved, and any new bad blocks found by
         running badblocks(8) will be added to the existing bad blocks
         list.

   -y    Assume an answer of `yes' to all questions; allows e2fsck to be
         used non-interactively. This option may not be specified at the
         same time as the -n or -p options.