Really good article about SD cards; problems, solutions, what to look for etc.
https://picockpit.com/raspberry-pi/moni ... pberry-pi/
I had problems with my Unifi RPi, so I checked the SD card using:
Code: Select all
sudo fsck -fvn /dev/mmcblk0p2 | tee ~/fsck_p2
Also did the same for p1. P2 showed a bunch of errors, like a lot. You can't run fsck on a mounted filesystem, e.g. the system partition, and that can't be unmounted, so fsck has to be set to run after a reboot.
This is done by adding a command to the bootloader command line which when seen will cause fsck to repair the disk prior to it being mounted:
...and add the string "fsck.mode=force" into the SINGLE LINE command line. Do not include a line break and make very sure you get this right! Note that "fsck.repair=yes" is there by default and basically answers "yes" to any question during the process.
The old method of adding a file called /forcefsck at the root is deprecated and should not be used.
Code: Select all
Sep 4 11:49:06 UniFiController systemd-fsck[136]: Please pass 'fsck.mode=force' on the kernel command line rather than creating /forcefsck on the root file system.
After a reboot, a read-only fsck shows no errors! Phew.
However, the Unifi DB may still have issues, so I repaired the MongoDB by:
Code: Select all
sudo service unifi stop
sudo mongod --dbpath /usr/lib/unifi/data/db --smallfiles --logpath /usr/lib/unifi/logs/server.log --repair
sudo chown -R unifi:unifi /usr/lib/unifi/logs/server.log
sudo chown -R unifi:unifi /usr/lib/unifi/data/db
sudo service unifi start
Note that just doing a reboot without first orderly shutting down stuff writing to the SD card, e.g. Unifi (as it uses MongoDB), can damage the filesystem.
You can check when fsck was last used on a filesystem by using tune2fs, e.g.
Code: Select all
sudo tune2fs -l /dev/mmcblk0p2 | grep checked
and you can check the systemd log to confirm it ran during boot by using:
Code: Select all
sudo cat /var/log/syslog | grep fsck
...
Sep 4 15:05:07 UniFiController kernel: [ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1 bcm2708_fb.fbwidth=1920 bcm2708_fb.fbheight=1080 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000 console=ttyS0,115200 console=tty1 root=PARTUUID=74bf6075-02 rootfstype=ext4 elevator=deadline fsck.repair=yes fsck.mode=force rootwait quiet splash plymouth.ignore-serial-consoles
Sep 4 15:05:07 UniFiController systemd-fsck[125]: e2fsck 1.44.5 (15-Dec-2018)
Sep 4 15:05:07 UniFiController systemd-fsck[125]: Pass 1: Checking inodes, blocks, and sizes
Sep 4 15:05:07 UniFiController systemd-fsck[125]: Pass 2: Checking directory structure
Sep 4 15:05:07 UniFiController systemd-fsck[125]: Pass 3: Checking directory connectivity
Sep 4 15:05:07 UniFiController systemd-fsck[125]: Pass 4: Checking reference counts
Sep 4 15:05:07 UniFiController systemd-fsck[125]: Pass 5: Checking group summary information
Sep 4 15:05:07 UniFiController systemd-fsck[125]: rootfs: 121152/943488 files (0.2% non-contiguous), 3089183/3822976 blocks
Sep 4 15:05:07 UniFiController systemd-fsck[254]: fsck.fat 4.1 (2017-01-24)
Sep 4 15:05:07 UniFiController systemd-fsck[254]: /dev/mmcblk0p1: 282 files, 98419/516190 clusters
Sep 4 15:05:36 UniFiController systemd[1]: systemd-fsckd.service: Succeeded.
...