# How do I delete the /usr/ports when it says device busy



## mrusli (Nov 16, 2020)

Hi

Currently I am using FreeBSD 12.2. 
I wanted to delete the /usr/ports and download the svnweb subversion. 
How do I go about doing that??? 
Please help.
Thank you.


----------



## vermaden (Nov 16, 2020)

What is the output of *df -h* and *mount -p* commands?


----------



## rootbert (Nov 16, 2020)

`fstat | grep "/usr/ports"`


----------



## SirDice (Nov 16, 2020)

Maybe you have some other session logging in that's in that directory?

Also note, with a ZFS install, /usr/ports is a separate filesystem, which means you can't `rm -rf /usr/ports` itself, only its contents. You would need to use `zfs destroy` to actually remove the /usr/ports/ directory itself. Not needed if you just want to checkout a new ports tree. Just remove its contents, not the directory itself.


----------



## mrusli (Nov 17, 2020)

vermaden said:


> What is the output of *df -h* and *mount -p* commands?




```
$ sudo df -h
Filesystem            Size    Used   Avail Capacity  Mounted on                                     
zroot/ROOT/default    113G    3.6G    109G     3%    /                                              
devfs                 1.0K    1.0K      0B   100%    /dev                                           
procfs                4.0K    4.0K      0B   100%    /proc                                          
zroot/var/tmp         109G    104K    109G     0%    /var/tmp                                       
zroot/usr/home        109G     41M    109G     0%    /usr/home                                      
zroot/var/log         109G    464K    109G     0%    /var/log                                       
zroot/tmp             109G    112K    109G     0%    /tmp                                           
zroot/var/crash       109G     96K    109G     0%    /var/crash                                     
zroot                 109G     96K    109G     0%    /zroot                                         
zroot/usr/src         110G    727M    109G     1%    /usr/src                                       
zroot/var/audit       109G     96K    109G     0%    /var/audit                                     
zroot/var/mail        109G    120K    109G     0%    /var/mail                                      
zroot/usr/ports       110G    716M    109G     1%    /usr/ports   

$ sudo mount -p
zroot/ROOT/default      /                       zfs     rw,noatime,nfsv4acls    0 0
devfs                   /dev                    devfs   rw              0 0
procfs                  /proc                   procfs  rw              0 0
zroot/var/tmp           /var/tmp                zfs     rw,nosuid,noatime,nfsv4acls     0 0
zroot/usr/home          /usr/home               zfs     rw,noatime,nfsv4acls    0 0
zroot/var/log           /var/log                zfs     rw,noexec,nosuid,noatime,nfsv4acls      0 0
zroot/tmp               /tmp                    zfs     rw,nosuid,noatime,nfsv4acls     0 0
zroot/var/crash         /var/crash              zfs     rw,noexec,nosuid,noatime,nfsv4acls      0 0
zroot                   /zroot                  zfs     rw,noatime,nfsv4acls    0 0
zroot/usr/src           /usr/src                zfs     rw,noatime,nfsv4acls    0 0
zroot/var/audit         /var/audit              zfs     rw,noexec,nosuid,noatime,nfsv4acls      0 0
zroot/var/mail          /var/mail               zfs     rw,nfsv4acls    0 0
zroot/usr/ports         /usr/ports              zfs     rw,nosuid,noatime,nfsv4acls     0 0
```


----------



## mrusli (Nov 17, 2020)

rootbert said:


> `fstat | grep "/usr/ports"`


$ sudo fstat | grep "/usr/ports"
rusli    sh           886   wd /usr/ports     34 drwxr-xr-x      85  r


----------



## mrusli (Nov 17, 2020)

SirDice said:


> Maybe you have some other session logging in that's in that directory?
> 
> Also note, with a ZFS install, /usr/ports is a separate filesystem, which means you can't `rm -rf /usr/ports` itself, only its contents. You would need to use `zfs destroy` to actually remove the /usr/ports/ directory itself. Not needed if you just want to checkout a new ports tree. Just remove its contents, not the directory itself.


Oh no wonder I cannot use the rm -rf /usr/ports command on my zfs.

So how do i zfs destroy, /usr/ports???


----------



## T-Daemon (Nov 17, 2020)

mrusli said:


> So how do i zfs destroy, /usr/ports???


There is no need to destroy the dataset, just run `rm -rf /usr/ports/* /usr/ports/.svn` as *SirDice* suggested:


SirDice said:


> ... use `zfs destroy` to actually remove the /usr/ports/ directory itself. *Not needed if you just want to checkout a new ports tree. Just remove its contents, not the directory itself.*


----------



## vermaden (Nov 17, 2020)

mrusli said:


> Hi
> 
> Currently I am using FreeBSD 12.2.
> I wanted to delete the /usr/ports and download the svnweb subversion.
> ...


The /usr/ports is a ZFS dataset.

After you do `rm -rf /usr/ports` command you HAVE a clean /usr/ports directory, but you can not delete that directory because its ZFS dataset. Do delete ZFS dataset you will have to use zfs destroy zroot/usr/ports command, but as you are saying that you want to fetch a fresh copy of Ports then you only need this:


```
# rm -rf /usr/ports
# portsnap auto
```

Regards.


----------



## rootbert (Nov 17, 2020)

mrusli said:


> $ sudo fstat | grep "/usr/ports"
> rusli    sh           886   wd /usr/ports     34 drwxr-xr-x      85  r


`kill -9 886` to kill that process which accesses /usr/ports, then destroy that zfs dataset as recommended above


----------



## SirDice (Nov 17, 2020)

That's just a different shell that happens to be in /usr/ports. Even if he exits that shell, he still won't be able to remove /usr/ports itself because it's a separate ZFS filesystem. ZFS isn't going to allow you to remove its mountpoint if the filesystem is mounted. 

Just to reiterate, you don't need to remove the directory itself, only its contents. The directory only has to be empty for a subversion checkout to work.


----------

