fsck root filesystem on a remote machine

Solution 1:

shutdown -rF now

Should force a fsck of all disks in /etc/fstab on reboot. link: man shutdown

Alternatively, if you want a fsck on every reboot:

cd /
touch forcefsck
reboot

Solution 2:

it's also a good idea on debian and debian-derivatives like ubuntu to edit /etc/default/rcS on remote servers and set "FSCKFIX=yes"

that adds "-y" to the boot time fsck, so it doesn't risk the remote server being stuck waiting for someone to login at the console and run fsck.

also, just in case something like happens again, it's worthwhile having a rescue partition that you can boot (e.g. temporarily set grub's default), ssh into, and run fsck on your real rootfs. if you don't currently have a spare partition free for this, you can shrink a swap partition to give yourself enough space to make a rescue partition (which you can populate with debootstrap).

and if you can't use a swap partition, you can set up a grub entry to boot into a live cd image (using the kernel and initrd from the iso)...but you'll have to modify the initrd filesystem to have your correct IP address etc and make sure that sshd is running. clonezilla, gparted or systemrescuecd would make good live systems to use as a base for this. your /boot partition/directory needs to be big enough to hold these files.