# Cleanly removing /usr/src



## ralphbsz (Jul 21, 2019)

For some reason that I can't remember, I have /usr/src fully populated on my FreeBSD 11.3 machine at home. Never noticed it, until I ran the upgrade from 11.2 to 11.3 a few days ago. That's 140,000 files that I don't need, and which clog backup and waste time during upgrades. What's the clean way to remove them? Can I just do "rm -Rf /usr/src/* /usr/obj/*"? Without causing problems for future upgrades?


----------



## obsigna (Jul 21, 2019)

Yes!

In addition, in /etc/freebsd-update.conf you might want to remove src from the components of the base system which should be kept updated. (± line 15).


----------



## malavon (Jul 21, 2019)

I don't know if this is still the case, but in the past the nvidia driver needed /usr/src to build. This is of course only applicable if you ever build it from the port.


----------



## ralphbsz (Jul 21, 2019)

Thank you, done. Worked well. The upgrade on the 2nd machine ran 3x faster, when it didn't have to upgrade the source.

And no need to worry about the Nvidia driver; I only do servers (no graphics), and I hardly ever build anything from ports.


----------



## PMc (Jul 21, 2019)

malavon said:


> I don't know if this is still the case, but in the past the nvidia driver needed /usr/src to build. This is of course only applicable if you ever build it from the port.



Not only that one, there is a couple of them. Working with /usr/ports needs /usr/src as a prereq. But nobody (afaik) needs /usr/obj; that one can be dropped immediately after OS-build&installation.


----------



## VladiBG (Jul 21, 2019)

I'm using only ports and i never had need of /usr/src for them.


----------



## PMc (Jul 21, 2019)

VladiBG said:


> I'm using only ports and i never had need of /usr/src for them.



Example from /usr/ports/sysutils/lsof/Makefile:

```
.if !exists(${SRC_BASE}/sys/kern/kern_lockf.c)
IGNORE=         requires kernel sources
.endif
```


----------



## SirDice (Jul 22, 2019)

Ports that require access to kernel structures typically need access  to the source tree. This includes for example various kernel modules and tools like the aforementioned sysutils/lsof.


----------



## Phishfry (Jul 22, 2019)

PMc said:


> But nobody (afaik) needs /usr/obj; that one can be dropped immediately after OS-build&installation.


Now this directory should be 'make clean' from the building directory (usually /usr/src) before deleted.

I have been down that rabbit hole before by deleting without cleaning first. You need to undo some flags.
This is usually the result of a broken build that bombs out and leaves some build files in a state of flux. `make clean` fixes that.
`chflags -R noschg *`








						Solved - Can't delete jail directory.
					

Hello,  I was trying Jails but I end up with a directory I can't delete: /usr/jail/www.  I did it using:  setenv D /usr/jail/www mkdir -p $D cd /usr/src make installworld DESTDIR=$D make distribution DESTDIR=$D  Any ideia?  Thanks!  EDIT:   rm: /usr/jail/www/bin/rcp: Operation not permitted rm...




					forums.freebsd.org


----------

