# Install FreeBSD from running OS onto a USB Flash Drive?



## coredumb (Jul 22, 2016)

Hi,
there must be a trick for this case: How can I install FreeBSD from a running (remote) FreeBSD system *onto* a new and fresh USB Thumb Drive? Not to be confused with a different scenario where to dd a FreeBSD installer image onto a flash drive to boot from and interactively install FreeBSD from.

There is a running FreeBSD machine (the first one) at a friend's house who needs a new FreeBSD on a stick for a second machine to boot that from. I want to remotely perform this (all text-based) installation based on the specs I have about the second machine (like NIC vendor to specify in network config in rc.conf etc.). The only two tasks my friend should have to do is to plug the empty stick into machine 1 and, after install&config, to move the stick to machine 2 and let it boot from that. 

Any ideas?


----------



## coredumb (Jul 22, 2016)

Oh! Silly me!

The solution is here: /usr/sbin/bsdinstall

Just fired it up, selected the desired settings including the correct target disk and there you go.
I haven't been consulting the Handbook before starting this thread which btw. is always a very good reference. Thanks to all the authors!


----------



## SirDice (Jul 22, 2016)

Another way is to use installworld/installkernel and setting DESTDIR. See build(7).


----------



## kpa (Jul 22, 2016)

SirDice said:


> Another way is to use installworld/installkernel and setting DESTDIR. See build(7).



That's not enough, you have to do `make distrib-dirs distribution` to get the /etc (and few others) configuration files in place. The poudriere documentation quotes this sequence for creating an absolutely pristine environment for a jail and it can used for installing a new system as well.


```
/usr/src# make installworld DESTDIR=PATH DB_FROM_SRC=1
/usr/src# make distrib-dirs DESTDIR=PATH DB_FROM_SRC=1
/usr/src# make distribution DESTDIR=PATH DB_FROM_SRC=1
```

Edit: Of course you need `make installworld installkernel DESTDIR=....`


----------



## wblock@ (Jul 22, 2016)

But building from source does not copy the system.

If both machines are on a shared network, I would boot the second with mfsBSD (http://mfsbsd.vx.sk/), then set up the same disk formatting (http://www.wonkity.com/~wblock/docs/html/disksetup.html) and copy the original system over the network with dump(8)/restore(8) through SSH (http://www.wonkity.com/~wblock/docs/html/backup.html).

We really need a standalone utility for this, a way to build an installer disk/image that writes an existing system onto a new one.  People ask for it fairly often, and USB media is large enough that the old 700M or 4G space limit on optical media is not a problem any more.


----------



## SirDice (Jul 22, 2016)

kpa said:


> That's not enough, you have to do `make distrib-dirs distribution` to get the /etc (and few others) configuration files in place. The poudriere documentation quotes this sequence for creating an absolutely pristine environment for a jail and it can used for installing a new system as well.
> 
> 
> ```
> ...


The jail(8) man page does it slightly different but it should also work for USB sticks. Also, don't forget `gpart bootcode` to make the stick bootable.


```
D=/here/is/the/jail
     cd /usr/src
     mkdir -p $D
     make world DESTDIR=$D
     make distribution DESTDIR=$D
```


----------

