LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   New build of LFS I'm experimenting with. (OpenRC+ZFS+B/LFS) (https://www.linuxquestions.org/questions/linux-from-scratch-13/new-build-of-lfs-im-experimenting-with-openrc-zfs-b-lfs-4175546201/)

ReaperX7 06-23-2015 09:26 AM

New build of LFS I'm experimenting with. (OpenRC+ZFS+B/LFS)
 
Going to try and put another build together, this time with OpenRC. I figure by now I've studied up on it enough and gotten some usage with it via Slackware to try and fold it into LFS as neatly as possible. One step closer to my new ideal build, though my ideal filesystem still eludes me at getting ZFS into a bootable state. Really wish I could solve how to get ZFS as root working.

I'll post notes after I get it finished.

ButterflyMelissa 06-23-2015 11:54 AM

subscribed, thanks :)

ReaperX7 06-23-2015 08:50 PM

I might also have found the secret to ZFS as well thanks to Funtoo. Only time will tell though.

Edit:

Due to acquiring a new hard drive, the ZFS+OpenRC+B/LFS project will be going forward.

ReaperX7 06-25-2015 05:06 PM

Update #1:

Created a partition layout on my /dev/sdc disk with the following layout:

/dev/sdc1 - linux type - ext2 - /boot
/dev/sdc2 - linux swap type - swap - swap
/dev/sdc3 - solaris root type - zfs - /

Created zpool with the following options:

Code:

zpool create -f -o ashift=12 -o cachefile=/tmp/zpool.cache -O normalization=formD -m none -R /mnt/lfs ztank /dev/sdc3
Set zfs mountpoint and options with dataset:

Code:

zfs create -p ztank/lfs
zfs create -o mountpoint=/ ztank/lfs/root

Beginning build of LFS. With all hope, this should work.

Note: For anyone following this, when you unmount the main LFS zpool, use:

Code:

zpool export ztank
To remount it use:

Code:

zpool import -f -R /mnt/lfs ztank
All tests conclusive that ZFS is working and able to be remounted without incident.

Halting build at libstdc++ for the day.

ReaperX7 06-26-2015 05:26 PM

Update #2:

Resumed build of OpenRC+ZFS+B/LFS today.

Re-import of ztank was successful. Status of ztank zpool was clear. No problems with partition found.

Code:

bash-4.3# zpool list
NAME    SIZE  ALLOC  FREE  EXPANDSZ  FRAG    CAP  DEDUP  HEALTH  ALTROOT
ztank  224G  3.59G  220G        -    0    1  1.00x  ONLINE  /mnt/lfs
bash-4.3# zpool status
  pool: ztank
 state: ONLINE
  scan: none requested
config:

        NAME        STATE    READ WRITE CKSUM
        ztank      ONLINE      0    0    0
          sdc3      ONLINE      0    0    0

errors: No known data errors

Proceeding onward with binutils-pass2. Will edit in next finish point for the day.

Stopped at man-pages in chapter 6. zpool exported without issue. No problems found.

Keith Hedger 06-27-2015 05:34 PM

what are the advantages of zfs over ext for lfs?

ReaperX7 06-27-2015 08:53 PM

Depends on what you need, but only I'm doing it just to prove it can be done, and document the process of getting it done correctly.

If anyone wants info on ZFS, check here:

https://en.wikipedia.org/wiki/ZFS

Update 3:

Only got glibc-2.21 built and installed today due to time constraint. Otherwise, system is still in working order without issue.

ReaperX7 06-30-2015 09:55 AM

Update 4:

Okay, yesterday I finished the entire system in LFS, minus the kernel.

I have the kernel prepped for building SPL and ZFS modules internally into the kernel to be ready at boot time. OpenRC is installed and the initial runlevels are set, with udev and udev-trigger added to sysinit runlevel.

The only thing I have left is the import Python 2.x for rebuilding Grub-2.02~beta2 which is sporting a massive patch to support ZFS, btrfs, as well as several detection methods. I'll post the patch, as well as the build instructions for all extras I added which include:

os-prober
openrc
aadityabagga-openrc-services
spl
zfs

and anything that will get added shortly later today when I get the system prepped for first boot. If all goes well, expect a video upload of the boot. If all does not go well, I might be screwed. LOL. Well, at least I can format it to JFS or Ext4 and reload the tarball backup I'll make. Heh.

Anyways, it's about done, so cross those fingers.

ReaperX7 06-30-2015 08:16 PM

Supplemental update:

Patch for Grub-2.02~beta2 ( grub-legacy_detection+zfs+btrfs.patch )

Note: This doesn't give FULL ZFS support, so you will have to edit the grub.cfg file manually to add the ZFS root partition.

Code:

diff -Naur grub-2.02~beta2.orig/Makefile.util.def.orig grub-2.02~beta2/Makefile.util.def
--- grub-2.02~beta2.orig/Makefile.util.def.orig        2014-05-20 15:13:30.969701269 +0200
+++ grub-2.02~beta2/Makefile.util.def        2014-05-20 15:19:23.271715952 +0200
@@ -384,7 +384,7 @@
  ldadd = libgrubgcry.a;
  ldadd = libgrubkern.a;
  ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
 };
 
 program = {

diff -Naur grub-2.02~beta2.orig/util/grub.d/10_linux.in grub-2.02~beta2/util/grub.d/10_linux.in
--- grub-2.00.orig/util/grub.d/10_linux.in        2012-04-18 23:24:38.000000000 +0200
+++ grub-2.00/util/grub.d/10_linux.in        2012-06-30 07:53:03.765625589 +0200
@@ -198,7 +198,8 @@
            "initramfs-genkernel-${version}" \
            "initramfs-genkernel-${alt_version}" \
            "initramfs-genkernel-${GENKERNEL_ARCH}-${version}" \
-          "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}"; do
+          "initramfs-genkernel-${GENKERNEL_ARCH}-${alt_version}" \
+          "initrd.gz"; do
    if test -e "${dirname}/${i}" ; then
      initrd="$i"
      break

diff -Naur grub-2.02~beta2.orig/util/grub.d/00_header.in grub2-2.02~beta2/util/grub/00_header.in
--- grub-2.02~beta2.orig/util/grub.d/00_header.in        2013-12-24 08:45:34.000000000 -0800
+++ grub-2.02~beta2/util/grub.d/00_header.in        2015-01-27 21:55:45.697000000 -0800
@@ -153,7 +153,7 @@
 EOF
    else
        for dir in "${pkgdatadir}" "`echo '/@bootdirname@/@grubdirname@' | sed "s,//*,/,g"`" /usr/share/grub ; do
-            for basename in unicode unifont ascii; do
+            for basename in unicode unifont dejavusansmono ascii; do
                path="${dir}/${basename}.pf2"
                if is_path_readable_by_grub "${path}" > /dev/null ; then
                    font_path="${path}"
@@ -166,7 +166,7 @@
        if [ -n "${font_path}" ] ; then
    cat << EOF
 if [ x\$feature_default_font_path = xy ] ; then
-  font=unicode
+  font=dejavusansmono
 else
 EOF
                # Make the font accessible
@@ -179,7 +179,7 @@
 EOF
            else
    cat << EOF
-if loadfont unicode ; then
+if loadfont dejavusansmono ; then
 EOF
            fi
        fi
 
diff -Naur grub-2.02~beta2.orig/util/grub-mkconfig.in grub-2.02~beta2/util/grub-mkconfig.in
--- grub-2.02~beta2.orig/util/grub-mkconfig.in        2013-12-24 08:46:40.000000000 -0800
+++ grub-2.02~beta2/util/grub-mkconfig.in        2015-01-26 23:39:24.521000000 -0800
@@ -129,8 +129,9 @@
 fi
 
 # Device containing our userland.  Typically used for root= parameter.
-GRUB_DEVICE="`${grub_probe} --target=device /`"
-GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || true
+GRUB_DEVICE="`${grub_probe} --target=device /`" || GRUB_DEVICE="`legacy_find_root_device`"
+GRUB_DEVICE_UUID="`${grub_probe} --device ${GRUB_DEVICE} --target=fs_uuid 2> /dev/null`" || \
+    GRUB_DEVICE_UUID="`legacy_convert_to_uuid ${GRUB_DEVICE}`"
 
 # Device containing our /boot partition.  Usually the same as GRUB_DEVICE.
 GRUB_DEVICE_BOOT="`${grub_probe} --target=device /boot`"
 
diff -Naur grub-2.02~beta2.orig/util/grub-mkconfig_lib.in grub-2.02~beta2/util/grub-mkconfig_lib
--- grub-2.02~beta2.orig/util/grub-mkconfig_lib.in        2013-12-17 13:45:18.000000000 -0800
+++ grub-2.02~beta2/util/grub-mkconfig_lib.in        2015-01-26 23:42:43.932000000 -0800
@@ -264,6 +264,82 @@
  echo "$version_find_latest_a"
 }
 
+legacy_find_device ()
+{
+    mount_point=$1
+
+    # Autodetect current root device
+    device=
+    if [ -f /etc/fstab ] ; then
+        device="`awk '$1!~/^#/{
+          if ($2 ~ "^/+$") { $2 = "/"; } else { sub("/*$", "", $2); }
+          if ($2 == "'"$mount_point"'"){
+                  print $1;
+              }
+          }' /etc/fstab | tail -n 1`"
+    fi
+
+    if [ -n "$device" ] ; then
+        case "$device" in
+            LABEL=* | UUID=*)
+                device="`findfs $device`"
+                device="`readlink -f "$device"`"
+            ;;
+            *)
+                device=`readlink -f "$device"`
+            ;;
+        esac
+    fi
+
+    echo $device
+}
+
+legacy_find_root_device ()
+{
+    echo "Cannot determine root device.  Trying legacy probe method" >&2
+    device="`legacy_find_device /`"
+
+    if [ -z "$device" ]; then
+        echo "Cannot determine root device.  Assuming /dev/sda1" >&2
+        echo "This error is probably caused by an invalid /etc/fstab" >&2
+        device=/dev/sda1
+    fi
+
+    echo $device
+}
+
+legacy_convert_to_uuid()
+{
+    echo "Cannot determine uuid of root device.  Trying legacy probe method" >&2
+    local dev; dev="$1"
+
+    convert=false
+    case "$dev" in
+        /dev/disk/*)
+          ;;
+        /dev/mapper/*)
+          ;;
+        /dev/evms/[hs]d[a-z][0-9]*)
+            convert=:
+          ;;
+        /dev/evms/*)
+          ;;
+        /dev/md[0-9]*)
+          ;;
+        /dev/*)
+            convert=:
+          ;;
+    esac
+    if $convert; then
+        if [ -b "$dev" ]; then
+            uuid="`blkid -o value -s UUID "$dev" || true`"
+        fi
+    fi
+
+    echo "$uuid"
+}
+
+
 # One layer of quotation is eaten by "" and the second by sed; so this turns
 # ' into \'.
 grub_quote () {
 
diff -Naur grub-2.02~beta2.orig/util/grub-install.c grub-2.02~beta2/util/grub-install.c
--- grub-2.02~beta2.orig/util/grub-install.c        2013-12-24 08:40:31.000000000 -0800
+++ grub-2.02~beta2/util/grub-install.c.new        2015-01-27 22:07:56.714000000 -0800
@@ -827,7 +827,7 @@
  grub_util_host_init (&argc, &argv);
  product_version = xstrdup (PACKAGE_VERSION);
  pkgdatadir = grub_util_get_pkgdatadir ();
-  label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2");
+  label_font = grub_util_path_concat (2, pkgdatadir, "dejavusansmono.pf2");
 
  argp_parse (&argp, argc, argv, 0, 0, 0);

Make sure you run autoreconf before you build since you patched one of the configure and makefile configurations.

ReaperX7 06-30-2015 08:27 PM

Supplement update #2:

os-prober may need needed to correctly identify the partitions if you have it in the system.

To install os-prober grab the source here:

URL: http://http.debian.net/debian/pool/m...er_1.65.tar.xz
MD5: a7e833555f54387a4798ffea8c2bf0d4

Build instructions:
Code:

make
cp -av linux-boot-prober os-prober /usr/bin
cp -av linux-boot-probes os-probes /usr/lib
( cd /usr/lib/linux-boot-probes
  for probe in common/* ; do
    ln -svf $probe .
  done
  cd mounted
  for probe in common/* x86/* ; do
    ln -svf $probe .
  done
)
( cd /usr/lib/os-probes
  for probe in common/* ; do
    ln -svf $probe .
  done
  cd init
  for probe in common/* ; do
    ln -svf $probe .
  done
  cd ../mounted
  for probe in common/* x86/* ; do
    ln -svf $probe .
  done
)
mkdir -pv /usr/lib/os-prober
cp -av newns /usr/lib/os-prober
mkdir -pv /usr/share/os-prober
cp -av common.sh /usr/share/os-prober
mkdir -pv /var/lib/os-prober
mkdir -pv /usr/doc/os-prober-1.65
cp -av README TODO /usr/doc/os-prober-1.65

This should expand the usefulness of Grub-2.02~beta2 a bit better.

ReaperX7 06-30-2015 09:57 PM

ZFS can be used quite effectively with LFS, especially if you screw up something.

By this, you have the ability to use ZFS's snapshot feature to effectively rollback the system to a previous state. For a distribution like LFS, that can be lifesaving to avoid heavy rebuilds.

To create a snapshot, use:

Code:

zfs snapshot -r ztank@install
This shouldn't take a long time.

To check the snapshot list use:

Code:

zfs list -t snapshot
To restore a snapshot of a dataset:

Code:

zfs rollback ztank/lfs/root@install
Now you can effectively keep a core LFS on-hand just in case you nuke something, and want to avoid rebuilding. ZFS +1, other filesystems 0.

ReaperX7 06-30-2015 10:13 PM

Booting with Grub-2.02~beta2 (patched)

Edit your /boot/grub/grub.cfg as so:

Code:

cat > /boot/grub/grub.cfg << "EOF"
# Begin /boot/grub/grub.cfg
set default=0
set timeout=5

insmod ext2
insmod part_msdos
insmod zfs
insmod zfsinfo

menuentry "LFS w/ ZFS 20150623-SVN (Linux 4.1)" {
insmod zfs
set root=(hd2,msdos2)
linux /vmlinuz-linux zfs=ztank/lfs/root rw zfs_force=0
}
EOF

This is currently posted for experimentation only. I will verify it works before finalizing this post.

ReaperX7 07-01-2015 09:46 PM

Update:

Build on hold due to error during compile:

Filed report with zfsonlinux developers and awaiting solution.

https://github.com/zfsonlinux/zfs/issues/3546

Pending the outcome, I may revert to using 7.7 as a baseline if GCC-5.1.0 is a source of the problem, otherwise, I'm going to wait for an official answer.

Contact from the project directed me to this commit:

https://git.kernel.org/cgit/linux/ke...b83fc4a4f3aa60

I think I can make a patch to fix this code from what was provided so tomorrow hopefully this can get back in gear and build.

Was able to patch the kernel, and continued onward:

include/linux/ftrace_event.h
Code:

edit line 202 from:

    const char *system;
to
    char *system;

include/trace/ftrace.h
Code:

edit line 43 from:

    .system = TRACE_SYSTEM_STRING, \
to
    .system = __stringify(TRACE_SYSTEM), \

edit lines 21~34 from:

[quote]#ifndef TRACE_SYSTEM_VAR
    #define TRACE_SYSTEM_VAR TRACE_SYSTEM
    #endif

    #define __app__(x, y) str__##x##y
    #define __app(x, y) __app__(x, y)

    #define TRACE_SYSTEM_STRING
    __app(TRACE_SYSTEM_VAR,__trace_system_name)

    #define TRACE_MAKE_SYSTEM_STR()        \
    static const char TRACE_SYSTEM_STRING[] = \
    __stringify(TRACE_SYSTEM)

    TRACE_MAKE_SYSTEM_STR();

to

    /*#ifndef TRACE_SYSTEM_VAR
    #define TRACE_SYSTEM_VAR TRACE_SYSTEM
    #endif

    #define __app__(x, y) str__##x##y
    #define __app(x, y) __app__(x, y)

    #define TRACE_SYSTEM_STRING
    __app(TRACE_SYSTEM_VAR,__trace_system_name)

    #define TRACE_MAKE_SYSTEM_STR()        \
    static const char TRACE_SYSTEM_STRING[] = \
    __stringify(TRACE_SYSTEM)

    TRACE_MAKE_SYSTEM_STR();*/

edit line 725 from:

    .system        = TRACE_SYSTEM_STRING, \

    .system        = __stringify(TRACE_SYSTEM), \

and edit line 768 from:

    #undef TRACE_SYSTEM_VAR

to

    /*#undef TRACE_SYSTEM_VAR*/

and the ZFS module can be rebuilt into the kernel. I'll try and create a patch file for this.

ReaperX7 07-03-2015 05:49 AM

After a day of fiddling with Grub to find out it's as useless as garbage with ZFS, even patched, I'm going to try and swap it out for syslinux. Really starting to wonder how well this will end up.

Krejzi 07-03-2015 06:27 AM

I apologize if you mentioned this somewhere, I just scrolled quickly without reading everything, but:

Why go with ZFS? I see you mention snapshot feature a lot. BTRFS offers similar features as ZFS (incl. snapshots), it's in the kernel, requires no patching, neither patching bootloader nor kernel, etc. Plus, the disk format was recently declared stable and preformance is decent when comparing to ext4 and xfs (faster than xfs in some cases, a bit slower than ext4).


All times are GMT -5. The time now is 06:59 PM.