# Strange issue with root partition



## cahimira (Jun 9, 2013)

I have a strange issue with my root partition.

Each time my box reboot I get this error:

```
...
Starting file system checks:
/dev/ada0s2a: NO WRITE ACCESS
/dev/ada0s2a: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
...
```

In that moment the partition is mounted in / in read-write mode.
Then, I go to single mode, mount the partition in read-only mode and run fsck:

```
[cmd=#]mount -r /dev/ada0s2a[/cmd]
[cmd=#]fsck /dev/ada0s2a[/cmd]
...
USE JOURNAL ? [yn] <---- "y"
...
RECOVER ? [yn] <---- "y"
...
*** FILE SYSTEM MARKED CLEAN ***
```

Then, exit from single mode and the system boots normally.


----------



## wblock@ (Jun 10, 2013)

Don't mount the partition.  Just run fsck(8) on it:
`# fsck -tufs -y /dev/ada0s2a`


----------



## cahimira (Jun 10, 2013)

wblock@ said:
			
		

> Don't mount the partition.  Just run fsck(8) on it:
> `# fsck -tufs -y /dev/ada0s2a`



Hi,

ada0s2a is my root partition, not mounting is not a option.

I find more information about this issue: FreeBSD try to check my root partition (read-write mounted) with -p (preen mode) . The man page says: In preen mode, only a restricted class of innocuous file system inconsistencies will be corrected.  If unexpected inconsistencies caused by hardware or software failures are encountered, the check program will exit with a failure.

The questions are:

Why does FreeBSD try to check my root partition in "preen mode"?
Why not just enter in "Fast mode"?
Is the message "UNEXPECTED INCONSISTENCY" just a generic message?
Thanks.


----------



## wblock@ (Jun 10, 2013)

cahimira said:
			
		

> Hi,
> 
> ada0s2a is my root partition, not mounting is not a option.



It is already mounted read-only.  Don't assume that you need to mount it again.  Just run fsck(8) on it with as little messing with it as possible.


----------



## cahimira (Jun 11, 2013)

wblock@ said:
			
		

> It is already mounted read-only.  Don't assume that you need to mount it again.  Just run fsck(8) on it with as little messing with it as possible.



Hi,

That is the point.  When FreeBSD drops me to single mode, the root partition is mounted in "read-write" mode. FreeBSD mount the root partition in "read-write" mode and then try to do a `fsck -p` on that partition.

Thanks.


----------



## wblock@ (Jun 11, 2013)

After booting in single user mode:

```
# mount
/dev/gpt/tinyfs on / (ufs, local, read-only)
devfs on /dev (devfs, local, multilabel)
```

If single user mode starts with a read/write mount, something has been changed from the defaults.  fsck(1) is used after a power loss in multiuser mode, but that can be disabled in /etc/rc.conf.


----------



## jozze (Jun 11, 2013)

Try with the GENERIC kernel. Maybe you don't have soft updating enabled (if you use a custom kernel), and so each reboot is giving you this problem. In this case, make sure you have the following options enabled (uncommented) in your kernel configuration file:

```
options FFS           # Berkeley Fast Filesystem
options SOFTUPDATES   # Enable FFS soft updates support
options UFS_GJOURNAL  # Enable gjournal-based UFS journaling
```

If you have all the defaults enabled and you are indeed running the GENERIC kernel (which means you already have soft updates enabled), you could try to use the live media, from which you installed FreeBSD, for maintenance.

Boot from LiveCD/LiveUSB.
Choose LiveCD when prompted by installer.
When prompted for a user name, log in as `root'. There is no password.
Don't mount anything.
Run `# fsck -t ufs -fy /dev/ada0s2` for your root (/) partition. Optionally you can do it for each of them (except for swap).
Reboot your computer, and start from your system (not from your live medium).
fsck -fy might break some shared libraries -- if you see errors like, vim cannot find this shared library, or musicpd cannot start because of that, simply rebuild those ports with all dependencies (for the following example I will demonstrate with editors/vim and audio/musicpd). I would suggest using ports-mgmt/portupgrade to do that, e.g.

```
# portupgrade -Rf editors/vim audio/musicpd
```
or if you prefer ports-mgmt/portmaster:

```
# portmaster -R /usr/ports/editors/vim /usr/ports/audio/musicpd
```

Step `5)' will rebuild your journal (that's what the -f flag does) even if your filesystem has been marked clean, so it may take a while (OK, not that long, I have to wait around 1-2 minutes).

I hope this will help.

Cheers!


----------



## cahimira (Jun 12, 2013)

Ok,

I run this test:

Power on my box.
I choose 'boot in single mode'.
FreeBSD boots and shows: 
	
	



```
Enter full pathname of shell...
```
 then I press ENTER and get shell as root.
I run `mount`, and get:

```
/dev/ada0s2a on / (ufs, local, noatime, read-only)
devfs on /dev (devfs, local, multilabel)
```

Then, I press ^D and enter in multiuser mode.
FreeBSD shows 
	
	



```
Fast boot: skipping disk checks. ... Starting background file system checks in 60 seconds.
```
 and get the login prompt.
Then, I log in as root and get the shell and run `reboot` and my box reboots.
(all normal here)
My box boots in the default multiuser mode.
Then I get this message:

```
Starting file system checks:
/dev/ada0s2a: NO WRITE ACCESS
...
Enter full pathname of shell...
```

I press ENTER and get the shell.
Run `mount` and get:

```
/dev/ada0s2a on / (ufs, local, noatime, journaled soft-updates)
devfs on /dev (devfs, local, multilabel)
```

I don't understand why if I boot in multiuser FreeBSD tries to check my root partition, but if I boot in single user mode first, then in multiuser the filesystem check is skipped.

Thanks.


----------



## cahimira (Jun 12, 2013)

jozze said:
			
		

> Try with the GENERIC kernel. Maybe you don't have soft updating enabled (if you use a custom kernel), and so each reboot is giving you this problem. In this case, make sure you have the following options enabled (uncommented) in your kernel configuration file:
> 
> ```
> options FFS           # Berkeley Fast Filesystem
> ...



No luck 

I boot with my FreeBSD LiveUSB, run `fsck` and I get the same. I use a GENERIC kernel.

Thanks.


----------



## wblock@ (Jun 12, 2013)

An important thing to realize is that in single user mode, the normal startup scripts do not run.  Look at /etc/rc.d/fsck.

Some people disable the background checks in rc.conf:

```
background_fsck="NO"
```

I think that the background checks fail at repairing the filesystem but manage to mark it as okay.  A full fsck(8) in single user mode actually fixes it.


----------



## cahimira (Jun 12, 2013)

wblock@ said:
			
		

> An important thing to realize is that in single user mode, the normal startup scripts do not run.  Look at /etc/rc.d/fsck.
> 
> Some people disable the background checks in rc.conf:
> 
> ...



No luck 

I disable background checks in rc.conf. I do a full fsck(8) in single user mode. But the issue persists. Each time I boot FreeBSD it tries to check my root device.

Thanks.


----------



## cahimira (Jun 12, 2013)

I have more information:

Filesystem check is executed because a variable $autoboot has a "YES" has value.
`fsck` exit status: 8


----------



## cahimira (Jun 12, 2013)

There is a resume:

If I boot FreeBSD in multiuser mode from loader (default boot option), `fsck` always will be executed in preen mode (in foreground or background based on `$background_fsck`). That is totally normal.
Ok, the problem (for me) is the "preen mode". If I execute fsck in "preen mode" (`fsck -p`), it always fails.
There is the tests:

TEST 1 - Preen mode, root device mounted as read-only


```
# mount -r /
# fsck -p
/dev/ada0s2a: FILE SYSTEM CLEAN; SKIPPING CHECKS
```

TEST 2 - Preen mode, root device mounted as read-write


```
# mount -w /
# fsck -p
/dev/ada0s2a: NO WRITE ACCESS
/dev/ada0s2a: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY
```
(Exit status = 8)

TEST 3 - Full test, root device mounted as read-only


```
# mount -r /
# fsck /
** /dev/ada0s2a

USE JOURNAL [yn] y

** SU+J Recovering /dev/ada0s2a
** Reading 33554432 byte journal from inode 4.

RECOVER [yn] y

** Building recovery table.
** Resolving unreferenced inode list.
** Processing journal entries.

***** FILE SYSTEM MARKED CLEAN *****
```

TEST 4 - Full test (again), root device mounted as read-only


```
# fsck /
** /dev/ada0s2a

USE JOURNAL [yn] y

** SU+J Recovering /dev/ada0s2a
Journal timestamp does not match fs mount time
** Skipping journal, falling through to full fsck

** Las Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
** Phase 2 - Check Cyl groups
14094 files, 131293 used, 3675042 free (762 frags, 456285 blocks, 0.0% fragmentation)

***** FILE SYSTEM IS CLEAN *****

***** FILE SYSTEM WAS MODIFIED *****
```


----------

