ZFS root, error 2 when mounting root

bw bw.mail.lists at gmail.com
Mon Feb 25 15:14:39 UTC 2013


On 02/25/2013 03:13 PM, Paul Kraus wrote:
> On Feb 24, 2013, at 4:42 AM, bw.mail.lists <bw.mail.lists at gmail.com> wrote:
>
>> Basically, I tried to follow https://wiki.freebsd.org/RootOnZFS/GPTZFSBoot/9.0-RELEASE, but ended up with a system that didn't know how to mount /.
>>
>> There are two scripts attached.
>
> I did not see any attachments.
>

Mail list got rid of them, I didn't know it will do that. Appended 
inline at the end of this mail. Stuff will probably get wrapped, but at 
least it's there.

>
>> The main difference I see between those two scripts is that one doesn't use a cache file and the other one does, hence the name of the scripts. But it should work without cachefile too, shouldn't it? The other difference is how mountpoints are set, but I can't figure out what could be wrong there.
>
> 	I am guessing without seeing the scripts, but I assume the cache you refer to is the /boot/zfs/zpool.cahce file. This file instructs the kernel which zpools to import at boot time. If this file is missing or damaged the kernel cannot import any zpools. So you MUST have a valid zpool.cache file in order to import the zpool containing the "/" zfs dataset

That was my understanding, too, but the instructions on the wiki say 
there's no need to copy the cache file. In fact, there is no cache file 
to copy, since the pool is created with

zpool create -o altroot=/mnt -O canmount=off zroot mirror /dev/gpt/g0zfs 
/dev/gpt/g1zfs

No cache file. The wiki article was changed recently to eliminate that 
part, the message on the wiki is: "Fix so that the default instructions 
does not install data directly to the zroot pool. Simplify instructions 
regarding cache files, they are no longer needed. Fixes and cleanups."

Either the instructions are wrong, or something in my script is. I 
assume it's my script.

>
> --
> Paul Kraus
> Deputy Technical Director, LoneStarCon 3
> Sound Coordinator, Schenectady Light Opera Company
>
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
>

ZFSNOCACHE:
=========================================================
DISK0="da0"
DISK1="da1"
echo "will use pool zroot, made up of disks $DISK0 and DISK1"

echo "Creating partitions..."
echo "  $DISK0"
gpart create -s gpt $DISK0
gpart add -s 122 -t freebsd-boot -l g0boot $DISK0
gpart add -s 4G -t freebsd-swap -l g0swap $DISK0
gpart add -t freebsd-zfs -l g0zfs $DISK0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK0
echo "  $DISK1"
gpart create -s gpt $DISK1
gpart add -s 122 -t freebsd-boot -l g1boot $DISK1
gpart add -s 4G -t freebsd-swap -l g1swap $DISK1
gpart add -t freebsd-zfs -l g1zfs $DISK1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK1
echo"done"

echo "Loading kernel modules..."
kldload opensolaris
kldload zfs
kldload geom_mirror
echo "done"

echo 'Setting swap as mirror...'
gmirror label gswap /dev/gpt/g0swap /dev/gpt/g1swap
echo 'done'

echo "Creating zroot..."
zpool create -o altroot=/mnt -O canmount=off zroot mirror /dev/gpt/g0zfs 
/dev/gpt/g1zfs
echo "done"

echo "Creating filesystems..."
echo "  checksum"
zfs set checksum=fletcher4 zroot
echo '  /'
zfs create -o mountpoint=/ 
zroot/ROOT
echo '  /tmp'
zfs create -o compression=off        -o exec=on      -o setuid=off 
zroot/tmp
chmod 1777 /mnt/tmp
echo '  /usr'
zfs create 
zroot/usr
zfs create 
zroot/usr/local
zfs create -o compression=off                        -o setuid=off 
zroot/usr/ports
zfs create -o compression=off        -o exec=off     -o setuid=off 
zroot/usr/ports/distfiles
zfs create -o compression=off        -o exec=off     -o setuid=off 
zroot/usr/ports/packages
zfs create -o compression=lzjb       -o exec=off     -o setuid=off 
zroot/usr/src
zfs create 
zroot/usr/obj
echo '  /var'
zfs create 
zroot/var
zfs create -o compression=lzjb       -o exec=off     -o setuid=off 
zroot/var/crash
zfs create                           -o exec=off     -o setuid=off 
zroot/var/db
zfs create -o compression=lzjb       -o exec=on      -o setuid=off 
zroot/var/db/pkg
zfs create                           -o exec=off     -o setuid=off 
zroot/var/empty
zfs create -o compression=lzjb       -o exec=off     -o setuid=off 
zroot/var/log
zfs create -o compression=gzip       -o exec=off     -o setuid=off 
zroot/var/mail
zfs create                           -o exec=off     -o setuid=off 
zroot/var/run
zfs create -o compression=off        -o exec=on      -o setuid=off 
zroot/var/tmp
chmod 1777 /mnt/var/tmp
echo '  /home'
zfs create                                           -o setuid=off 
zroot/home
echo 'done'

echo 'Installing FreeBSD'
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done
echo 'done'

echo 'Setting up the new system'
echo '  loader.conf'
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'geom_mirror_load="YES"' >> /mnt/boot/loader.conf

echo '  rc.conf'
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo 'hostanme="hostname.domain.org"' >> /mnt/etc/rc.conf
echo 'ifconfig_bce0="inet 10.1.1.2 netmask 255.255.255.0"' >> 
/mnt/etc/rc.conf
echo 'defaultrouter="10.1.1.1"' >> /mnt/etc/rc.conf
echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf

echo '  periodic.conf'
echo 'daily_status_gmirror="YES"' >> /mnt/etc/periodic.conf

echo '  fstab'
echo '# Device          Mountpoint      FStype  Opts    Dump    Pass#' 
 >> /mnt/etc/fstab
echo '/dev/mirror/gswap none            swap    sw      0       0' >> 
/mnt/etc/fstab

echo 'done'

echo 'Setting mountpoints on zroot'
zfs unmount -a
zpool set bootfs=zroot/ROOT zroot
zfs set mountpoint=/ zroot/ROOT
zfs set mountpoint=/zroot zroot
zfs set mountpoint=/tmp zroot/tmp
zfs set mountpoint=/usr zroot/usr
zfs set mountpoint=/var zroot/var
zfs set mountpoint=/home zroot/home
zfs set readonly=on zroot/var/empty
echo 'done'

echo 'exporting the pool'
zpool export zroot
echo 'all done, can reboot.'
=========================================================

ZFSWITHCACHE:
=========================================================
DISK0="da0"
DISK1="da1"
echo "will use pool zroot, made up of disks $DISK0 and DISK1"

echo "Creating partitions..."
echo "  $DISK0"
gpart create -s gpt $DISK0
gpart add -b 34 -s 64k -t freebsd-boot -l g0boot $DISK0
gpart add -s 4G -a 4k -t freebsd-swap -l g0swap $DISK0
gpart add -a 4k -t freebsd-zfs -l g0zfs $DISK0
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK0
echo "  $DISK1"
gpart create -s gpt $DISK1
gpart add -b 34 -s 64k -t freebsd-boot -l g1boot $DISK1
gpart add -s 4G -a 4k -t freebsd-swap -l g1swap $DISK1
gpart add -a 4k -t freebsd-zfs -l g1zfs $DISK1
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $DISK1
echo"done"

echo "Loadin kernel modules..."
kldload opensolaris
kldload zfs
kldload geom_mirror
echo "done"

echo 'Setting swap as mirror...'
gmirror label gswap /dev/gpt/g0swap /dev/gpt/g1swap
echo 'done'

echo "Creating $POOL..."
zpool create -o altroot=/mnt -o cachefile=/var/tmp/zpool.cache zroot 
mirror /dev/gpt/g0zfs /dev/gpt/g1zfs
echo "done"

echo "Creating fielsystems"
zfs create -o setuid=off zroot/tmp
chmod 1777 /mnt/tmp
zfs create zroot/usr
zfs create zroot/usr/home
cd /mnt
ln -s usr/home home
cd -
zfs create zroot/usr/local
sleep 5
zfs create -o compression=on -o exec=off -o setuid=off zroot/usr/src
zfs create zroot/var
zfs create -o exec=off -o setuid=off zroot/var/backups
zfs create -o compression=on -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/db
zfs create -o compression=on -o exec=on -o setuid=off zroot/var/db/pkg
zfs create -o exec=off -o setuid=off zroot/var/empty
zfs create -o compression=on -o exec=off -o setuid=off zroot/var/log
zfs create -o compression=on -o exec=off -o setuid=off zroot/var/mail
zfs create -o exec=off -o setuid=off zroot/var/run
zfs create -o setuid=off zroot/var/tmp
chmod 1777 /mnt/var/tmp
zfs create -o setuid=off zroot/usr/ports
zfs create -o exec=off -o setuid=off zroot/usr/ports/distfiles
zfs create -o exec=off -o setuid=off zroot/usr/ports/packages
echo "done"

echo "Making zfs bootable, hopefully"
zpool set bootfs=zroot zroot
mkdir -p /mnt/boot/zfs
cp -p /var/tmp/zpool.cache /mnt/boot/zfs/zpool.cache
echo "done?"

echo 'Installing FreeBSD'
cd /usr/freebsd-dist
export DESTDIR=/mnt
for file in base.txz lib32.txz kernel.txz doc.txz ports.txz src.txz;
do (cat $file | tar --unlink -xpJf - -C ${DESTDIR:-/}); done
echo 'done'

echo 'Setting up the new system'
echo '  loader.conf'
echo 'zfs_load="YES"' >> /mnt/boot/loader.conf
echo 'geom_mirror_load="YES"' >> /mnt/boot/loader.conf
echo 'vfs.root.mountfrom="zfs:zroot"' >> /mnt/boot/loader.conf

echo '  rc.conf'
echo 'zfs_enable="YES"' >> /mnt/etc/rc.conf
echo 'hostanme="hostname.domain.org"' >> /mnt/etc/rc.conf
echo 'ifconfig_bce0="inet 10.1.1.2 netmask 255.255.255.0"' >> 
/mnt/etc/rc.conf
echo 'defaultrouter="10.1.1.1"' >> /mnt/etc/rc.conf
echo 'sshd_enable="YES"' >> /mnt/etc/rc.conf

echo '  periodic.conf'
echo 'daily_status_gmirror="YES"' >> /mnt/etc/periodic.conf

echo '  fstab'
echo '# Device          Mountpoint      FStype  Opts    Dump    Pass#' 
 >> /mnt/etc/fstab
echo '/dev/mirror/gswap none            swap    sw      0       0' >> 
/mnt/etc/fstab

echo 'done'

echo 'Make sure empty stays empty'
zfs set readonly=on zroot/var/empty
echo 'done'

echo 'all done, can reboot: shutdown -r now'
=========================================================




More information about the freebsd-questions mailing list