# Force fsck after power loss.



## urello (Oct 30, 2014)

A few days ago my D-Link router has become fully inoperable. I decided to re-use some of my old hardware and set up a PC-based router with FreeBSD 10. The router works perfectly, however my rampaging cats occasionally unplug the power cord. In order to bring the router back up I have to shutdown my workstation moving the display, GPU and keyboard from the workstation to the router and run fsck on /dev/ada0p4. This is really boring. I added the following to  rc.conf:

```
fsck_y_enable="YES"
background_fsck="NO"
force_fsck="YES"
```
However this didn't solve my problem.  Any suggestion?

```
df -h
Filesystem  Size  Used  Avail Capacity  Mounted on
/dev/ada0p2  19G  13G  5,2G  71%  /
devfs  1,0K  1,0K  0B  100%  /dev
/dev/ada0p4  49G  2,5G  43G  5%  /data
```


----------



## wblock@ (Oct 30, 2014)

Step one: protect the cords from the cats, and vice versa.

Depending on how close the router is located to the workstation, connect a serial cable and set the router to use a serial console.  Then use cu(1) from the workstation to control the router console.

Look in, but do not modify, /etc/defaults/r.conf for the settings.  
	
	



```
fsck_y_enable="YES"
```
 might do what you want.  A UPS is highly recommended, and could probably be shared by both systems if they are close enough.


----------



## urello (Oct 30, 2014)

There are about 5 meters between workstation and router. I don*'*t have such a cable. Is there any way to tell FreeBSD to "mount partition only if filesystem is clean" or do *I* need to exclude this partition from fstab?


----------



## phoenix (Oct 30, 2014)

What does your /etc/fstab look like?  Particularly the last couple of columns for the /data line.


----------



## urello (Oct 31, 2014)

```
cat /etc/fstab
/dev/ada0p2  /  ufs  rw  1  1
/dev/ada0p4  /data  ufs  rw  0  0
```


----------



## SirDice (Oct 31, 2014)

urello said:


> ```
> cat /etc/fstab
> /dev/ada0p2  /  ufs  rw  1  1
> /dev/ada0p4  /data  ufs  rw  0  0
> ```


Change the last digit to 1 or 2. A 0 would indicate there's never an fsck(8) needed. You'd only use 0 for swap or NFS shares.

fstab(5):

```
If the sixth field is not present or is zero, a value of zero is returned
  and fsck(8) and quotacheck(8) will assume that the file system does not
  need to be checked.

  The fs_passno field can be used to implement finer control when the sys-
  tem utilities may determine that the file system resides on a different
  physical device, when it actually does not, as with a ccd(4) device.  All
  file systems with a lower fs_passno value will be completed before start-
  ing on file systems with a higher fs_passno value.  E.g. all file systems
  with a fs_passno of 2 will be completed before any file systems with a
  fs_passno of 3 or greater are started.  Gaps are allowed between the dif-
  ferent fs_passno values.  E.g. file systems listed in /etc/fstab may have
  fs_passno values such as 0, 1, 2, 15, 100, 200, 300, and may appear in
  any order within /etc/fstab.
```


----------



## phoenix (Nov 3, 2014)

I'd set it to 2 as it's not needed for booting, and you don't want multiple fsck's running in parallel on the same disk.  AIUI, fsck runs on all the "1" filesystems first, then all the "2" filesytems.  With / and /data on the same disk, you'd want to run them in series, not in parallel.  Granted, I could be misremembering things from the old days.


----------



## Chris_H (Nov 4, 2014)

phoenix,  you are not mistaken. *2* would be the optimum choice, under these circumstances. 

--Chris


----------

