Synology Nas: Run Fsck To Check and Repair a Linux File System

I own a Linux powered Synology dedicated Network Attached Storage (NAS) server for my home office use. How do I run fsck on Synology DiskStation that offers RAID storage using Linux command line options over an ssh session?

This server is powered by Linux operating system and comes with the e2fsck program that can be used to check the ext3/ext4 family of file systems.
First, you need to login using ssh interface. The syntax is as follows:

ssh [email protected]
ssh [email protected]

Once logged in you need to stop running services such as smb/nfs/pgsql and so. To see current volumes or mount point type the following command:
df
Sample outputs:

Filesystem           1K-blocks      Used Available Use% Mounted on
rootfs                 2451064    437412   1911252  19% /
/dev/root              2451064    437412   1911252  19% /
/tmp                    255700       272    255428   1% /tmp
/dev/vg1/volume_1    2879621632 176443652 2703075580   7% /volume1
/dev/vg1/volume_1    2879621632 176443652 2703075580   7% /opt

To see current services accessing the /volume1/ and /opt/, run:
lsof /opt/
lsof /volume1/

Sample outputs:

COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF    NODE NAME
postgres 5052 admin  cwd    DIR  253,0     4096      18 /volume1/@database/pgsql
postgres 5057 admin  cwd    DIR  253,0     4096      18 /volume1/@database/pgsql
postgres 5057 admin   17u   REG  253,0 16777216 3539006 /volume1/@database/pgsql/pg_xlog/000000010000000000000006
postgres 5058 admin  cwd    DIR  253,0     4096      18 /volume1/@database/pgsql
lsof     8284  root  txt    REG  253,0   125544 4068473 /opt/sbin/lsof
lsof     8285  root  txt    REG  253,0   125544 4068473 /opt/sbin/lsof

You need to stop pgsql service, enter:
/usr/syno/etc/rc.d/S20pgsql.sh stop
Sample outputs:
Stopping PostgreSQL...
In short, you need to stop services that are running and accessing data shares such as SMB,NFS,pgsql,mysql and so on. You can use web interface to stop these services too. cd to /usr/syno/etc/rc.d/ and stop all file sharing services. Finally, unmount volumes as follows:
umount /volume1/
umount /opt

Verify that /opt and /volume1/ are unmounted:
df
Sample outputs:

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/md0               2451064    437408   1911256  19% /
/tmp                    255700       264    255436   0% /tmp

Run fsck on ext4 file system:
fsck.ext4 -v /dev/vg1/volume_1
OR
e2fsck -p -y -f -v /dev/vg1/volume_1
Sample outputs:

e2fsck 1.41.12 (17-May-2010)
1.41.12-2198: is cleanly umounted, 474816/182845440 files, 55587266/731381760 blocks
 (check after next mount)

Reboot the server:
reboot

Check out related media

This tutorial is also available in a quick video format:

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.