# Configure ports to install and run on external media



## DCH3416 (Dec 4, 2017)

I've purchased a Asus EeePC 701 4G, which has 4 gigabytes of built in storage. I've installed the base FreeBSD system as well as some small command line ports (sudo, nano, tmux). 

What I'm looking to do is configure ports to install on an external storage media, like a flash drive or an SD card. Also include the external media as a path to execute binaries from command line. Like installing xorg and a desktop environment onto just the external media and being able to start a desktop environment with it attached. 

I'm also looking for a degree of flexibility as far as being able to start up the machine without the external media. Like if I wanted to add a port to the built in storage.

Essentially, having two ports directories, one local and one external, external may not always be available. 

Where would be a good place to get started?


----------



## mrclksr (Dec 5, 2017)

You could do it as follows:

Create a mount point for the media you want to store your installed ports, and mount it:

```
# mkdir /software
# mount /dev/daXsY /software
```
Then create directories for the port files and the package and ports database:

```
# mkdir -p /software/db/pkg
# mkdir /software/db/ports
# mkdir -p /software/usr/local
```
Now you can build and install your ports:

```
# cd /usr/ports/<category>/<portname>
# sh -c 'PORT_DBDIR=/software/db/ports PKG_DBDIR=/software/db/pkg LOCALBASE=/software/usr/local make install'
```
Finally, add the paths /software/usr/local/sbin and /software/usr/local/bin to the environment variable [FONT=Courier New]PATH[/FONT], or add them to the path-variable of your login class in /etc/login.conf, followed by executing

```
# cap_mkdb /etc/login.conf
```


----------



## DCH3416 (Dec 6, 2017)

Thanks, configured very nicely. 

Would it be possible to configure the installation of binary packages onto external media using "pkg install?" The example there works well for small ports, but for something like xorg I'm exhausting my machine's local storage capacity attempting to compile.


----------



## SirDice (Dec 6, 2017)

See pkg(8):

```
-r	<root directory>, --rootdir <root directory>
	     pkg will install all packages within the specified	<root
	     directory>.
```


----------



## DCH3416 (Dec 6, 2017)

SirDice said:


> See pkg(8):
> 
> ```
> -r	<root directory>, --rootdir <root directory>
> ...



Ah, I see.

Have to say, BSD is pretty fantastic compared to other unix like operating systems, particularly coming from a popular commercial operating system. BSD offers a degree of structure I'm comfortable with, and without too much hand holding so I can take the time to learn. 

Thanks.


----------

