Commits

Gregor Richards  committed bd7f11c

Making the entire process of building Snowflake not require root.

  • Participants
  • Parent commits 3fcff0b

Comments (0)

Files changed (10)

 $ ./a.out
 Hello, world!
 
-To build snowflake, make a config.sh (or use the existing one), and use the
-build scripts in core/, in this order:
+To build snowflake, make a config.sh (or use the existing one), and run
+build.sh (in core/). Building a Snowflake root filesystem does not require
+root. It runs the following sub-scripts, in this order:
 
 * ./buildcc.sh: Builds a cross-compiler targeting linux-musl. Due to a
   confluence of bugs, including possibly a bug in my GCC patch (which I'm
 
 * ./buildroot.sh: Builds a Snowflake root filesystem.
 
-* ./bootstraproot.sh: Builds the last few packages from within Snowflake. Note
-  that this will only work if your host kernel supports the necessary modules,
-  otherwise you will need to run Snowflake in a VM and bootstrap with
-  /src/bootstrap.sh.
-
-* ./enter-chroot.sh: chroots into a Snowflake root filesystem.
-
-* ./mk-hd-image.sh: Builds a Snowflake HD image from a root filesystem.
-
 It is possible to build out-of-source. To do so, set the environment variable
 SNOWFLAKE_BASE to the absolute path of core/, then run the scripts as usual.
 
+Once you have the root filesystem set up, write it to an HD image:
+
+* ./mk-hd-image.sh: Builds a Snowflake HD image from a root filesystem. This
+  requires root, but for very silly reasons (it needs fdisk and loop mounting).
+  If you don't have root, you can work around that requirement with, e.g.,
+  https://bitbucket.org/GregorR/umlbox . In that case, run it as `umlbox -fw /
+  -s ./mk-hd-image.sh`.
+
+You may also chroot directly into the root filesystem, if your host kernel has
+aufs. The first time you do so, you will have to run the init script, which
+does in-tree configuration:
+
+$ chroot root /usr/bin/init
+
+That step is done automatically if you run Snowflake in a VM or a real machine,
+it is only necessary if you use chroot.
+
+Once you're in the Snowflake filesystem, the final step is to bootstrap the
+last few packages.
+
+$ /src/bootstrap.sh
+
+
 Snowflake supports the NetBSD pkgsrc as a source of packages. The integration
 is imperfect but working. To include pkgsrc, set WITH_PKGSRC=yes in your
 config.sh. To use it, just `with pkgsrc` then build in /var/pkgsrc.
 Installation will automatically go into separated packages in /pkg.
 
+
 The default root password is "snowflake".
 
 

File core/bootstraproot.sh

-#!/bin/bash -x
-# Bootstrap the rootfs
-# 
-# Copyright (C) 2012 Gregor Richards
-# 
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-
-if [ ! "$SNOWFLAKE_BASE" ]
-then
-    SNOWFLAKE_BASE=`dirname "$0"`
-fi
-
-. "$SNOWFLAKE_BASE"/defs.sh
-
-"$SNOWFLAKE_BASE"/enter-chroot.sh /src/bootstrap.sh

File core/build.sh

+#!/bin/sh
+# Build a cross-compiler
+# 
+# Copyright (C) 2012 Gregor Richards
+# 
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+# 
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+# PERFORMANCE OF THIS SOFTWARE.
+
+if [ ! "$SNOWFLAKE_BASE" ]
+then
+    SNOWFLAKE_BASE=`dirname "$0"`
+fi
+
+# Fail on any command failing, show commands:
+set -ex
+
+"$SNOWFLAKE_BASE"/buildcc.sh &&
+"$SNOWFLAKE_BASE"/build-gcc-deps.sh &&
+"$SNOWFLAKE_BASE"/buildroot.sh

File core/buildroot.sh

     chmod 0755 "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/snps/$SNPS_VERSION/usr/bin"/*
 fi
 
-# make usrview setuid-root
-$SUDO chown 0:0 "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/usrview/$USRVIEW_VERSION/usr/bin/usrview"
-$SUDO chmod 4755 "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/usrview/$USRVIEW_VERSION/usr/bin/usrview"
-
 # make everything mountable
-$SUDO touch "$SNOWFLAKE_PREFIX/pkg/core/core/1.0/usr/.usr_ok"
+touch "$SNOWFLAKE_PREFIX/pkg/core/core/1.0/usr/.usr_ok"
 for pkg in minimal/1.0 default/1.0 \
     linux-headers/$LINUX_HEADERS_VERSION musl/$MUSL_VERSION \
     busybox/$BUSYBOX_VERSION quicklink/$QUICKLINK_VERSION \
     usrview/$USRVIEW_VERSION pkgresolve/$PKGRESOLVE_VERSION \
     binutils/$BINUTILS_VERSION gcc/$GCC_VERSION libgcc/$GCC_VERSION
 do
-    $SUDO touch "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/$pkg/usr/.usr_ok"
+    touch "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/$pkg/usr/.usr_ok"
 done
 if [ "$WITH_PKGSRC" = "yes" ]
 then
-    $SUDO touch "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/snps/$SNPS_VERSION/usr/.usr_ok"
+    touch "$SNOWFLAKE_PREFIX/pkg/$TRIPLE/snps/$SNPS_VERSION/usr/.usr_ok"
 fi
 
-# actually perform the linking (do this in multiple steps so we can cross-setup)
+# make a script to perform the linking
+mkdir -p "$SNOWFLAKE_PREFIX"/usr/bin
 echo '#!/pkg/'$TRIPLE'/busybox/'$BUSYBOX_VERSION'/usr/bin/sh
 /pkg/'$TRIPLE'/busybox/'$BUSYBOX_VERSION'/usr/bin/sh /pkg/'$TRIPLE'/quicklink/'$QUICKLINK_VERSION'/usr/bin/snowflake-quicklink '$TRIPLE'
+/bin/chmod 4755 /pkg/'$TRIPLE'/usrview/'$USRVIEW_VERSION'/usr/bin/usrview
 if [ "$$" = "1" ]
 then
     /bin/sync
     /bin/reboot -f
 fi' \
-    > "$SNOWFLAKE_PREFIX/setup_usr.sh"
-chmod a+x "$SNOWFLAKE_PREFIX/setup_usr.sh"
-if ! $SUDO chroot "$SNOWFLAKE_PREFIX" /setup_usr.sh
-then
-    # failed to setup usr, so run it as init
-    mkdir -p "$SNOWFLAKE_PREFIX"/usr/bin
-    mv "$SNOWFLAKE_PREFIX"/setup_usr.sh "$SNOWFLAKE_PREFIX"/usr/bin/init
-else
-    rm -f "$SNOWFLAKE_PREFIX/setup_usr.sh"
-fi
+    > "$SNOWFLAKE_PREFIX/usr/bin/init"
+chmod a+x "$SNOWFLAKE_PREFIX/usr/bin/init"

File core/clean.sh

 rm -rf \
     binutils-$BINUTILS_VERSION/ busybox-$BUSYBOX_VERSION/ mpc-$MPC_VERSION/ \
     mpfr-$MPFR_VERSION/ gcc-$GCC_VERSION/ gmp-$GMP_VERSION/ \
-    aufs3-linux-$LINUX_VERSION/ musl-$MUSL_VERSION/
-
-if [ -e root ]
-then
-    $SUDO rm -rf root/
-fi
+    aufs3-linux-$LINUX_VERSION/ musl-$MUSL_VERSION/ root/

File core/config.sh

 CC_BASE_PREFIX=/opt/cross
 SNOWFLAKE_PREFIX="$PWD/root"
 MAKEFLAGS=-j8
-SUDO=sudo
-WITH_PKGSRC=no
+WITH_PKGSRC=yes

File core/defs.sh

 esac
 
 
-# Don't need sudo if we're root
-if [ "`id -u`" = "0" ]
-then
-    SUDO=
-fi
-
 nolib64() {
     if [ ! -e "$1"/lib64 ]
     then

File core/enter-chroot-prime.sh

-#!/bin/bash -x
-# Copyright (C) 2012 Gregor Richards
-# 
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-
-if [ ! "$SNOWFLAKE_BASE" ]
-then
-    SNOWFLAKE_BASE=`dirname "$0"`
-fi
-
-. "$SNOWFLAKE_BASE"/defs.sh
-
-inchroot() {
-    $SUDO chroot "$SNOWFLAKE_PREFIX" "$@"
-}
-
-# check that we have all the filesystems we need
-FILESYSTEMS="proc sysfs devtmpfs tmpfs aufs"
-for fs in $FILESYSTEMS
-do
-    $SUDO modprobe $fs 2> /dev/null
-    if [ ! "`grep '\s'$fs'$' /proc/filesystems`" ]
-    then
-        echo 'To chroot into Snowflake, your host kernel must support the following filesystems: '"$FILESYSTEMS"
-        exit 1
-    fi
-done
-
-inchroot sh -c 'mount -t proc proc /proc;
-                mount -t sysfs sys /sys;
-                mount -t devtmpfs dev /dev;
-                mount -t tmpfs tmp /tmp;
-                mkdir /tmp/usr'
-if [ "$1" ]
-then
-    inchroot pkgresolve -- "$@"
-else
-    inchroot pkgresolve -- su -
-fi
-
-$SUDO umount "$SNOWFLAKE_PREFIX"/{proc,sys,dev,tmp}

File core/enter-chroot.sh

-#!/bin/bash -x
-# Enter a chroot
-# 
-# Copyright (C) 2012 Gregor Richards
-# 
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-# 
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
-# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-# PERFORMANCE OF THIS SOFTWARE.
-
-if [ ! "$SNOWFLAKE_BASE" ]
-then
-    SNOWFLAKE_BASE=`dirname "$0"`
-fi
-
-. "$SNOWFLAKE_BASE"/defs.sh
-
-$SUDO unshare -m env SNOWFLAKE_BASE="$SNOWFLAKE_BASE" \
-    "$SNOWFLAKE_BASE"/enter-chroot-prime.sh "$@"

File core/mk-hd-image.sh

 	UID="`id -u`"
 fi
 [ "$UID" = "0" ] || die "must be root"
+PATH="/sbin:/usr/sbin:$PATH"
+export PATH
 
 imagefile="$1"
 [ -z "$imagefile" ] && usage
 mount "$loopdev" "$mountdir" || die_unloop 'Failed to mount loop for /boot'
 
 if [ -d "$contents" ] ; then
-	cp -a "$contents"/boot/* "$mountdir"/ || die_unmount 'Failed to copy boot'
+	cp -dr "$contents"/boot/* "$mountdir"/ || die_unmount 'Failed to copy boot'
 else
 	tar -C "$mountdir" -xf "$contents" boot || die_unmount 'Failed to extract boot'
 	mv "$mountdir"/boot/* "$mountdir"/ || die_unmount 'Failed to move /boot content to root of boot partition'
 echo "copying contents, this will take a while"
 if [ -d "$contents" ]
 then
-	cp -a "$contents"/* "$mountdir"/ || die_unmount 'Failed to copy /'
+	cp -dr "$contents"/* "$mountdir"/ || die_unmount 'Failed to copy /'
 else
 	tar -C "$mountdir" -zxf "$contents" || die_unmount 'Failed to extract /'
 fi