Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 16 Jan 2018 09:52:12 +0100 (CET)
From:      =?ISO-8859-1?Q?Trond_Endrest=F8l?= <Trond.Endrestol@fagskolen.gjovik.no>
To:        FreeBSD questions <freebsd-questions@freebsd.org>
Subject:   Re: Dualboot and ZFS
Message-ID:  <alpine.BSF.2.21.1801160934560.69908@mail.fig.ol.no>
In-Reply-To: <20180116034929.GB89443@admin.sibptus.transneft.ru>
References:  <20180115051308.GA45168@admin.sibptus.transneft.ru> <VI1PR02MB12007D071EA5398373D2189CF6EB0@VI1PR02MB1200.eurprd02.prod.outlook.com> <20180115125241.GB60956@admin.sibptus.transneft.ru> <VI1PR02MB1200C7F0066F361E60A6CBEDF6EB0@VI1PR02MB1200.eurprd02.prod.outlook.com> <20180115144747.GA65526@admin.sibptus.transneft.ru> <VI1PR02MB120018D174817F8FFB2981D5F6EB0@VI1PR02MB1200.eurprd02.prod.outlook.com> <20180115151526.GA66342@admin.sibptus.transneft.ru> <a7920f859b666cff48f4f73ee1b2f954@dweimer.net> <20180116034929.GB89443@admin.sibptus.transneft.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 16 Jan 2018 10:49+0700, Victor Sudakov wrote:

> Dean E. Weimer wrote:
> 
> [dd]
> 
> > > For me, however, running "make installworld DESTDIR=xxx" is also
> > > installing. Can DESTDIR be a zpool on a MBR/BSD slice?
> > 
> > You can do an install from source to a zfs dataset no matter where it 
> > exists as that just shows up as any other mount point, but if you want 
> > to be able to boot from it I would suggest making it on a GPT disk. 
> 
> The whole point of my question was to install FreeBSD/ZFS as a second
> system to a box where Windows/NTFS already occupies one MBR partition and
> there is another MBR partition for FreeBSD. Do you think there is no
> such luck?  I 
> 
> > checked and there is a section on the wiki
> > <https://wiki.freebsd.org/RootOnZFS/ZFSBootSlice>; about installing
> > to MBR, but its flagged as will not boot.
> 
> "Will not boot"? That is odd because:
> 
> 1. That's basically the setup Manish suggested (using ada0s3a for
> zpool), and I think it works for him if he gave this advice.
> 
> 2. zfsboot(8) is designed for MBR so why would it fail to boot?
> 
> > By the way the setup I sent was installed by using the live CD, creating 
> 
> But your setup is not dualboot which I was asking about.

I couldn't resist attempting a proof of concept, so here it is.

The main motivation for using a BSD disklabel within a MBR slice is to 
have a ZFS partition and a swap partition while only consuming one of 
the four available MBR slices. You also avoid using a zvol for 
swap/dump.

See https://wiki.freebsd.org/RootOnZFS/ZFSBootPartition for more 
details.

Script started on Tue Jan 16 08:40:32 2018
# PS1='[script]# '

!!! These are the two MBR slices created by Windows 10, half of ada0 is available for FreeBSD !!!

[script]# gpart show ada0
=>       63  134217665  ada0  MBR  (64G)
         63       1985        - free -  (993K)
       2048    1024000     1  ntfs  [active]  (500M)
    1026048   66082816     2  ntfs  (32G)
   67108864   67108864        - free -  (32G)

!!! Now, add our FreeBSD slice !!!

[script]# gpart add -t freebsd ada0
ada0s3 added

!!! Here it is !!!

[script]# gpart show ada0
=>       63  134217665  ada0  MBR  (64G)
         63       1985        - free -  (993K)
       2048    1024000     1  ntfs  [active]  (500M)
    1026048   66082816     2  ntfs  (32G)
   67108864   67108864     3  freebsd  (32G)

!!! Create a BSD disklabel within the FreeBSD slice !!!

[script]# gpart create -s BSD ada0s3
ada0s3 created
[script]# gpart show ada0
=>       63  134217665  ada0  MBR  (64G)
         63       1985        - free -  (993K)
       2048    1024000     1  ntfs  [active]  (500M)
    1026048   66082816     2  ntfs  (32G)
   67108864   67108864     3  freebsd  (32G)

!!! Yes, the disklabel is in place !!!

[script]# gpart show ada0s3
=>       0  67108864  ada0s3  BSD  (32G)
         0  67108864          - free -  (32G)

!!! Add our ZFS partition !!!

[script]# gpart add -s 28G -t freebsd-zfs ada0s3
ada0s3a added

!!! Add our swap partition !!!

[script]# gpart add -t swap ada0s3
ada0s3b added

!!! Show the resulting disklabel !!!

[script]# gpart show ada0s3
=>       0  67108864  ada0s3  BSD  (32G)
         0  58720256       1  freebsd-zfs  (28G)
  58720256   8388608       2  freebsd-swap  (4.0G)

!!! Load the ZFS module, and optionally set the ashift property to 12 !!!

[script]# kldload zfs
[script]# sysctl vfs.zfs.min_auto_ashift=12
vfs.zfs.min_auto_ashift: 9 -> 12

!!! Create our zpool, YMMV !!!

[script]# zpool create -O mountpoint=legacy zroot /dev/ada0s3a

!!! Create our initial BE, YMMV !!!

[script]# uname -a
FreeBSD  11.1-STABLE FreeBSD 11.1-STABLE #0 r327786: Wed Jan 10 22:26:38 UTC 2018     root@releng2.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
[script]# zfs create zroot/ROOT
[script]# zfs create zroot/ROOT/20180110-r327786
[script]# zfs set mountpoint=/tmp/zroot zroot/ROOT/20180110-r327786

!!! The BE is temporary mounted at /tmp/zroot !!!

[script]# df -ah
Filesystem                           Size    Used   Avail Capacity  Mounted on
/dev/iso9660/11_1_STABLE_AMD64_CD    701M    701M      0B   100%    /
devfs                                1.0K    1.0K      0B   100%    /dev
tmpfs                                 32M    124K     32M     0%    /var
tmpfs                                 20M     68K     20M     0%    /tmp
zroot/ROOT/20180110-r327786           27G     88K     27G     0%    /tmp/zroot

!!! Extract a minimum installation !!!

[script]# cd /tmp/zroot
[script]# tar xf /usr/freebsd-dist/base.txz
[script]# tar xf /usr/freebsd-dist/kernel.txz
[script]# tar xf /usr/freebsd-dist/lib32.txz

!!! Ensure the ZFS module will be loaded by the loader !!!

[script]# echo 'zfs_load="YES"' >> boot/loader.conf

!!! Make a note of our swap partition !!!

[script]# echo '/dev/ada0s3b none swap sw 0 0' >> etc/fstab

!! Prepare our pool for export !!!

[script]# zfs unmount -a
[script]# zfs inherit mountpoint zroot/ROOT/20180110-r327786
[script]# zpool set bootfs=zroot/ROOT/20180110-r327786 zroot
[script]# df -ah
Filesystem                           Size    Used   Avail Capacity  Mounted on
/dev/iso9660/11_1_STABLE_AMD64_CD    701M    701M      0B   100%    /
devfs                                1.0K    1.0K      0B   100%    /dev
tmpfs                                 32M    128K     32M     0%    /var
tmpfs                                 20M     68K     20M     0%    /tmp
[script]# zpool export zroot

!!! Write the boot manager to the boot block in the MBR !!!

[script]# gpart bootcode -b /boot/boot0 /dev/ada0
bootcode written to ada0

!!! Write /boot/zfsboot as two separate pieces to /dev/ada0s3{,a} !!!

[script]# dd if=/boot/zfsboot of=/tmp/zfsboot1 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000383 secs (1337758 bytes/sec)
[script]# gpart bootcode -b /tmp/zfsboot1 /dev/ada0s3
bootcode written to ada0s3

[script]# dd if=/boot/zfsboot of=/dev/ada0s3a skip=1 seek=1024
128+0 records in
128+0 records out
65536 bytes transferred in 0.043591 secs (1503439 bytes/sec)

!!! Import our pool !!!

[script]# zpool import zroot
[script]# zfs list -rt all
NAME                          USED  AVAIL  REFER  MOUNTPOINT
zroot                         742M  26.2G    88K  legacy
zroot/ROOT                    742M  26.2G    88K  legacy
zroot/ROOT/20180110-r327786   742M  26.2G   742M  legacy

!!! Everything checks out, it's time for a reboot to assess the damage !!!

[script]# exit

Script done on Tue Jan 16 08:53:07 2018

Both Windows 10 and FreeBSD boots, so I would call this a success.

-- 
Trond.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.2.21.1801160934560.69908>