# Install FreeBSD in external USB HDD disk with Auto-ZFS



## nunotex (Jun 11, 2022)

Hello,

I'm using a laptop with a single M2 ssd disk with FreeBSD installed (auto-zfs).
Soon I will send my laptop to warranty and I'm thinking do a installation on a external USB HDD drive and import my home so I can connect to other laptop without toutching its internal disk.
Today I've boot FreeBSD in a USB pen and choosed "Auto-ZFS" but it points to my internal SSD.
Is there a way to work around this or clone internal disk to external one?

Other think, in the future I will use external disk as archive and backup using regular snapshots.

Thanks,

Nuno Teixeira


----------



## Deleted member 70435 (Jun 11, 2022)

Yes, there is a way, it's as if you were going to make a backup of the partition. but don't rely on the external disk, to have your system fully functional. problems can appear









						Chapter 21. The Z File System (ZFS)
					

ZFS is an advanced file system designed to solve major problems found in previous storage subsystem software




					docs.freebsd.org


----------



## T-Daemon (Jun 11, 2022)

nunotex said:


> clone internal disk to external one


One method to clone the laptop disk on the USB disk is to send and receive a ZFS data stream.

For the procedure, from the laptop system, on the USB drive

gpart(8) create partition table, add partitions efi and/or freebsd-boot, freebsd-swap, freebsd-zfs
for BIOS gpart(8) bootcode
for UEFI newfs_msdos(8) efi partition, mount_msdosfs(8) efi partition, create directories for the efi loader, copy efi loader
zpool-create(8) new-pool and altroot to a temporary mount point the USB freebsd-zfs partition
zfs-snapshot(8) -r laptop-pool, zfs-send(8) -R laptop-pool-snapshot | zfs-receive(8) -F new-pool
zpool-set(8) bootfs to new-pool/dataset
boot USB disk system
zpool set cachefile=/boot/zfs/zpool.cache new-pool
In case the USB disk is booted from the laptop and zfs-list(8) shows both pools datasets overlayed (mounted) on the same mount points, drop to single user mode, execute zpool-export(8) -f laptop-pool.
If you have difficulties at some of the steps, please ask.

If the laptop disk and the USB disk are the same size try Argentum's mirror method.

To make the partitioning of the USB disk simple, clone it: `gpart backup laptop-disk | gpart restore -F usb-disk`


----------



## grahamperrin@ (Jun 12, 2022)

T-Daemon said:


> zpool set cachefile=/boot/zfs/zpool.cache new-pool



Please, is that _required_ for anything?


For import to be automated at boot time, a value need not be set.


```
% lsblk da1
DEVICE         MAJ:MIN SIZE TYPE                                          LABEL MOUNT
da1              0:177 466G GPT                                               - -
  <FREE>         -:-   1.0M -                                                 - -
  da1p1          0:178 466G freebsd-zfs                           gpt/Transcend <ZFS>
% zpool get cachefile Transcend august
NAME       PROPERTY   VALUE      SOURCE
Transcend  cachefile  -          default
august     cachefile  -          default
%
```


----------



## grahamperrin@ (Jun 12, 2022)

nunotex said:


> … external USB HDD drive … boot FreeBSD in a USB pen and choosed "Auto-ZFS" but it points to my internal SSD. …



When you choose to stripe: the installer should offer a *choice of devices* that *includes the external USB HDD*.

For example, with multiple _virtual_ devices:


 

(It's misleading; the result of choosing to stripe is *not* a stripe.)


----------



## T-Daemon (Jun 12, 2022)

grahamperrin@ said:


> Please, is that _required_ for anything?


It's not a requirement but to tidy up the system.

The system on the USB disk may complain about failed cache file import of the original pool because the new pool is a exact clone and in the zpool.cache is still the pool configuration information of the original pool stored. It's not harmful but the system tries to import the original pool, recreating the zpool.cache file will silence the dmesg(8) notice:

```
cannot import 'zroot': no such pool or dataset
        Destroy and re-create the pool from
        a backup source.
cachefile import failed, retrying
```


----------



## nunotex (Jun 13, 2022)

grahamperrin@ said:


> When you choose to stripe: the installer should offer a *choice of devices* that *includes the external USB HDD*.
> 
> For example, with multiple _virtual_ devices:
> 
> ...


Ok, nice. I will try and see if USB HDD shows up listed and try instalation.
I will show results soon.
Thanks all for helping


----------



## nunotex (Jun 14, 2022)

grahamperrin@ said:


> When you choose to stripe: the installer should offer a *choice of devices* that *includes the external USB HDD*.
> 
> For example, with multiple _virtual_ devices:
> 
> ...


Ok, i did it and external disk showed up as da0 and I checked it up.
After a while a warning shows up:
---
There are multiple "FreeBSD" EFI boot entries, would you like to remove them all and add a new one? (I've started smoking hard/very nervous)
<YES> <NO>
---

This is very dangerous step for me since I'm testing in my only laptop I have, but do you know what happens when choosing yes or no ?


----------



## grahamperrin@ (Jun 15, 2022)

nunotex said:


> … do you know what happens when choosing yes or no ? …



I don't know, sorry, but here's the relevant commit:









						bsdinstall: bootconfig: Try to clean old efi boot entries · freebsd/freebsd-src@477fbe6
					

If one install FreeBSD on the same machine multiple times in a row or on different harddrive they have a lot of 'FreeBSD' efi boot entries added. With this patch we now do : - If there is n...




					github.com
				




At a glance: there is, at least, use of efibootmgr(8). 

Without installing, you can run `efibootmgr -v` to begin getting an idea of how things are. 

If, during installation, you opt to _not_ remove entries, then you can use efibootmgr later to tidy things.


Side note: are you installing STABLE or CURRENT? Just curious.


----------



## nunotex (Jun 15, 2022)

grahamperrin@ said:


> I don't know, sorry, but here's the relevant commit:
> 
> 
> 
> ...


CURRENT as I use at my laptop


----------

