Dualboot and ZFS

Manish Jain bourne.identity at hotmail.com
Mon Jan 15 09:50:35 UTC 2018



On 01/15/18 10:43, Victor Sudakov wrote:
> Dear Colleagues,
> 
> I have a box with dual boot: Windows and FreeBSD/UFS:
> 
> $ gpart show ada0
> =>       63  976773105  ada0  MBR  (466G)
>           63       1985        - free -  (993K)
>         2048  293029888     1  ntfs  [active]  (140G)
>    293031936  598958080     2  ntfs  (286G)
>    891990016   83886080     3  freebsd  (40G)
>    975876096     897072        - free -  (438M)
> 
> $ gpart show ada0s3
> =>       0  83886080  ada0s3  BSD  (40G)
>           0  75497472       1  freebsd-ufs  (36G)
>    75497472   8388607       2  freebsd-swap  (4.0G)
>    83886079         1          - free -  (512B)
> 
> $
> 
> boot0 handles the OS selection, everything works just fine.
> 
> Can I install FreeBSD with root-on-zfs into ada0s3 somehow?
> 

Hi Victor,

Yes, you can. But you will need a spare slice somewhere - another disk 
(SATA / USB). If the used potion of your ada0s3a is small, you can even 
use a USB pen drive.

You can rsync your current installation to the spare slice, and then 
mirror the sync back to a newly created ada0s3-zfs.

Let's say your spare disk is da0 with 40G spare (or at least the used 
size of ada0s3a).

gpart destroy -F da0		# only if needed
gpart create -s MBR da0		# only if needed

If da0 already has a spare slice, the 2 steps above are not needed, but 
then you will need to replace the slice number instead of da0s1 in the 
steps below.

gpart add -t freebsd da0	# adds da0s1; note the slice number here
gpart create -s BSD da0s1
gpart set -a active -i 1 da0
gpart add -t freebsd-zfs da0s1
zpool create zroot /dev/da0s1a
zpool set bootfs=zroot zroot
gpart bootcode -b /boot/boot0 da0
zpool export zroot
dd if=/boot/zfsboot of=/tmp/zfsboot1 count=1
gpart bootcode -b /tmp/zfsboot1 /dev/da0s1
dd if=/boot/zfsboot of=/dev/da0s1a skip=1 seek=1024
zpool import zroot
zfs set checksum=fletcher4 zroot


{
cat <<- EOF

/dev/*
/proc/*
/sys/*
/tmp/*
/mnt/*
/media/*
/lost+found
/usr/ports
/usr/src/*
/zroot
} > /root/excl

rsync -aAHXv --delete --exclude-from /root/excl / /zroot/


echo 'zfs_load=YES' > /zroot/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /zroot/boot/loader.conf
echo 'kern.geom.label.disk_ident.enable=0' >> /zroot/boot/loader.conf

Boot into da0, delete ada0s3 ('gpart delete -i 3 ada0; gpart destroy -F 
ada0s3'), and carry out the reverse transaction from da0s1 to ada0s3, 
using a new pool name zmirror in place of zroot.

Hope this helps.

Regards,
Manish Jain


More information about the freebsd-questions mailing list