# How to give free space in /usr



## HL1234 (Jan 24, 2015)

Hello
after trying to update the FreeBSD 10.0-RELEASE-p12 System my 10GB space of /usr is full

```
/dev/ad0s1e  2,1G  324M  1,6G  17%  /tmp
/dev/ad0s1f  10G  9,8G  -241M  103%  /usr
/dev/ad0s1g  4,7G  770M  3,5G  18%  /home
```

I do not understand what this negative disk space -241M means?

My Server Software is not so big. Just Apache Webserver + MySQL + PHP (Websites and databse files are in /home) and eMail-Server (sendmail) some Services like bind, ftp, sshd.

I find out with `du -sh *`:
that the most data are in:

```
2,9G  /usr/local
3,9G  /usr/ports
1,6G  /usr/src
```

I have try these to give free space:
`portsclean -C`
`portsclean -DP`
`portmaster -y --clean-distfiles`
in /usr/ports `make clean`
in /usr/src `make cleandir && make cleandir` and `make clean`

But nothing helps...

How can I delete some space without deleting needed system files?


----------



## gkontos (Jan 24, 2015)

You can safely nuke /usr/ports/* and /usr/src/*. That will free you around ~5GB of space. Then you can use `portsnap fetch extract` to restore a clean ports tree.


----------



## gkontos (Jan 24, 2015)

Apologies! Nuke /usr/src  after you upgrade...


----------



## getopt (Jan 24, 2015)

HL1234 said:


> Hello
> after trying to update the FreeBSD 10.0-RELEASE-p12 System my 10GB space of /usr is full


Did you succed in upgrading the system? Did it fail because of the diskspace?
In either case you should clean /usr/obj like this:

```
# cd /usr/obj
# chflags -R noschg *
# rm -rf *
```
For building from sources you need about roughly 2,5-3GB free disk space.
While upgrading /usr/ports can be removed for freeing up about 1GB space.

You might want to know where the disk space has been consumed. Try `du -hd1 /usr` for a first look, and then explore the directories which look big `du -hd1 /usr/bigsize | grep M`.
You also might want to review if some of the installed ports can be deleted. `pkg info -sa | grep MiB` shows the big ones.
Searching for removable files might be considered too, i.e `find /usr -name "*\.core"`


----------



## wblock@ (Jan 24, 2015)

Please do not ever do unqualified -rf with rm(1).  Always, always, always give a path: `rm -rf /usr/obj`.


----------



## getopt (Jan 24, 2015)

wblock@ said:


> Please do not ever do unqualified -rf with rm(1).  Always, always, always give a path: `rm -rf /usr/obj`.



Hi wblock@,
good idea, I agree. 

Unfortunately the handbook still does it the old insane way in chapter *Procedure 24.2. Overview of Build World Process*. So always, always, always take care about the handbook


----------



## gkontos (Jan 24, 2015)

Before you type `rm -rf *` make sure you know where you are by using `pwd`. You need to nuke your /  first before you get into that habit. 
Anyway, 3.9G in /usr/ports means that they have never been cleaned. Don't waste utilities, CPU and Disk IO for this since there is no benefit. Just remove them.


----------



## getopt (Jan 24, 2015)

Well, and there is still `rm -Irf *`


			
				 man rm said:
			
		

> -I      Request confirmation once if more than three files are being removed or if a directory is being recursively removed.  This is a far less intrusive option than -i yet provides almost the same level of protection against mistakes.





```
# cd /usr/ports
 # rm -Irf *
recursively remove 55 dirs and 11 files?
```

And for those who cannot remember there is a little help from my friend `alias`:

```
# alias rm  'rm -I'

# cd /usr/ports
 # rm -rf *
recursively remove 55 dirs and 11 files?
```
This alias may be worth being put in the shell configuration file.


----------



## wblock@ (Jan 24, 2015)

getopt said:


> Unfortunately the handbook still does it the old insane way


Not any more.


----------



## gkontos (Jan 25, 2015)

getopt said:


> Well, and there is still `rm -Irf *`
> 
> This alias may be worth being put in the shell configuration file.



Still, it does not tell you _what_ it is going to remove. So, if you are determined to perform this action and you think that you are in the correct place, you will answer _yes_! However, getting the habit you use `pwd` will save you one day.


----------



## HL1234 (Jan 25, 2015)

Thanks a lot for all who has give me advice.

First:


getopt said:


> Did you succed in upgrading the system? Did it fail because of the diskspace?
> In either case you should clean /usr/obj like this:
> 
> ```
> ...


Good idea, but my /usr/obj ist empty. All are under /usr/src.
Yes updating the system was successful and I don't forget to reboot. But updating the "software" with `portupgrade -ar` run in trouble because of the Perl version (another problem) and because of not enough disk space. I have then cleaned the ports, which has given free space at this time and then I do `portupgrade -PP` to use packages when ever possible. I need the ports for Apache and Sendmail and some bit more to give my own installation settings. But for the rest of the hundreds of software piaces I could use packages when ever possible.

The question is: if I would delete all under /usr/src, would I further be able to make updates again with  `freebsd-update` or build a new system? I have no own kernel.

Second: what is this with this minus diskspace   -241M  103%  /usr. I have some link to /tmp in /usr. But how can a partition get 103% full?

And why don't the commands above clean anything more?


----------



## getopt (Jan 25, 2015)

HL1234 said:


> The question is: if I would delete all under /usr/src, would I further be able to make updates again with  `freebsd-update` or build a new system? I have no own kernel.


If you have a GENERIC kernel you can delete /usr/src and use `freebsd-update` for getting binary files. /usr/src is needed only if you want to build the system yourself from source or for  building a custom kernel.


HL1234 said:


> Second: what is this with this minus diskspace   -241M  103%  /usr. I have some link to /tmp in /usr. But how can a partition get 103% full?



FAQ Chapter 8. Disks, File Systems, and Boot Loaders]


> 8.22. How is it possible for a partition to be more than 100% full?
> 
> A portion of each UFS partition (8%, by default) is reserved for use by the operating system and the root user. df(1) does not count that space when calculating the Capacity column, so it can exceed 100%. Notice that the Blocks column is always greater than the sum of the Used and Avail columns, usually by a factor of 8%.
> 
> For more details, look up -m in tunefs(8).





HL1234 said:


> And why don't the commands above clean anything more?


 Good question. You have to search your disk


----------



## HL1234 (Jan 29, 2015)

gkontos said:


> You can safely nuke /usr/ports/* and /usr/src/*. That will free you around ~5GB of space. Then you can use `portsnap fetch extract` to restore a clean ports tree.


I like to give the whole sequence, for those who read this thread:
Portsnap Ports new siting
Config file: /etc/portsnap.conf
`rm /var/db/portsnap/tag
rm -rf /var/db/portsnap/files
rm -rf /usr/ports/*
cd /usr/ports
portsnap fetch
portsnap extract`
To update an already installed Ports Collection, use portsnap update
`portsnap update`
Sure, you can combine fetch and extract for portsnap - I prefer to do it step by step.
Later on, when the ports tree has been built, you can make updates:
`portsnap fetch update`
Update or create the ports database file INDEX.db and fetch the ports index file called INDEX from the official
`portsdb -Fu`


----------



## wblock@ (Jan 30, 2015)

portsdb is not needed.  It is only used by ports-mgmt/portupgrade.  The preferred ports-mgmt/portmaster does not need a separate database.


----------

