# Free space issue on UFS (corrupted file system?)



## Serg (Dec 26, 2017)

My configuration:


```
FreeBSD dlna 10.3-RELEASE FreeBSD 10.3-RELEASE #0 r297264: Fri Mar 25 03:51:29 UTC 2016    [email]root@releng1.nyi.freebsd.org[/email]:/usr/obj/usr/src/sys/GENERIC  i386
```


```
df -h
Filesystem    Size    Used   Avail Capacity  Mounted on
/dev/ada1p2    17G     16G     18M  100%    /
devfs          1.0K    1.0K      0B  100%    /dev
/dev/ada0p1    7.0T    2.4T    4.1T    37%    /divan
mount
/dev/ada1p2 on / (ufs, local, soft-updates)
devfs on /dev (devfs, local, multilabel)
/dev/ada0p1 on /divan (ufs, local, soft-updates)
```
I have issue with free space on /dev/ada1p2. FreeBSD was freezes, I rebooted it by power reset. After restart I noticed no free space left – df reported -1.2 GB free space. I deleted some files but got only 18 MB free space. But I know there was at least 4 GB before power reset and  in total all data in files/folders on /dev/ada1p2 takes no more 10 GB. I thought issue in corrupted file system. fsck(8) in multi user mode shows errors:

```
fsck -y /dev/ada1p2
** /dev/ada1p2 (NO WRITE)

** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=2247234  OWNER=root MODE=140777 
SIZE=0 MTIME=Dec 26 10:11 2017
CLEAR? no
UNREF FILE I=2247244  OWNER=root MODE=140777
SIZE=0 MTIME=Dec 26 10:11 2017
CLEAR? no
UNREF FILE I=2247247  OWNER=root MODE=140777
SIZE=0 MTIME=Dec 26 10:11 2017
CLEAR? no
UNREF FILE I=2247248  OWNER=root MODE=140777
SIZE=0 MTIME=Dec 26 10:11 2017
CLEAR? no
UNREF FILE I=2247251  OWNER=root MODE=140777
SIZE=0 MTIME=Dec 26 10:11 2017
CLEAR? no
** Phase 5 - Check Cyl groups
323253 files, 4197427 used, 370052 free (55356 frags, 39337 blocks, 1.2% fragmentation)
```

But in single user mode fsck reports all clean and fixing nothing. I tried a few times with the same result. I have no idea how to return occupied space which obviously not in use but I think marked as in use.


----------



## Maelstorm (Dec 26, 2017)

Boot to single user mode and run `fsck -f`.  Say no when it asks to use the journal.


----------



## Serg (Dec 26, 2017)

Hi Maelstorm,
thanks for quick reply. Unfortunately  fsck -f gives the same result like  fsck -y. Nothing repaired reported because no issues detected and nothing was asked regarding journal. But when fsck tried to check /dev/ada0p1 (7 TB disk but I have no issue with it) fsck can't finish with error "out of swap space". I attached screen shot. May be it is related. May be I have corrupted swap partition?

Thanks.


----------



## ShelLuser (Dec 26, 2017)

'out of swap space' usually means just that: you don't have enough. You might want to check with `swapctl -lh`.

Also; this is usually when I grab a rescue cd, boot with that and then perform recovery using that environment. It will ensure that you won't disrupt too much on your original OS.


----------



## Jov (Dec 27, 2017)

try this:

```
newfs -N /dev/ada1p2
```

to get a super_block, note do not use the first several numbers.

then:

```
fsck_ffs -f -b <super_block> /dev/ada1p2
```

and your data may be placed in the lost+found dir on the top dir of the partiton.


----------



## Maelstorm (Dec 27, 2017)

Serg said:


> Hi Maelstorm,
> thanks for quick reply. Unfortunately  fsck -f gives the same result like  fsck -y. Nothing repaired reported because no issues detected and nothing was asked regarding journal. But when fsck tried to check /dev/ada0p1 (7 TB disk but I have no issue with it) fsck can't finish with error "out of swap space". I attached screen shot. May be it is related. May be I have corrupted swap partition?
> 
> Thanks.





ShelLuser said:


> 'out of swap space' usually means just that: you don't have enough. You might want to check with `swapctl -lh`.
> 
> Also; this is usually when I grab a rescue cd, boot with that and then perform recovery using that environment. It will ensure that you won't disrupt too much on your original OS.



I have to agree with ShelLuser with this.  If the error is that you have ran out of swap space, then chances are, that is what the problem is.  Is the 7TB all in one partition?  If so, you may need to break it up because the data structures used by fsck may be getting way too large for the system to handle.  I put a swap partition on each physical HD that I have so on my system there is 4gb swap across two disks.  Additionally, I make the swap at least the same size as the amount of memory in the machine.  So if you have 16GB Ram, make your swap 16GB or more...20GB would be better.  The reason behind this is that if the kernel panics, it has room to dump the full memory core of the machine...all 16GB of it.  Something else to consider as well.  It is a performance enhancement to have the swap space on all the drives be of the same size.  I read somewhere that it does something with page mapping so it doesn't need more than one table.  If the swap spaces are of different sizes, then it needs a table for each swap, which takes time and memory.

One other thing, for the longest time, I had a communications problem between the mainboard and one of the hard disks.  When the problem manifested itself, there were a bunch of weird errors.  However, fsck saw those and fixed them when I corrected the problem.  So I am not sure why fsck isn't seeing the problem here.

Try using `du -d 1`.  You could have a file or a bunch of files taking up all of your space, which would explain why fsck isn't finding anything because there isn't a problem with the file system metadata.  Find out which directory is taking up the space, cd in it, and run the du command again.  Keep doing it until you find where the problem is at.

Hope this helps.


----------

