Update for 0.18; new options -l (generates a local repo) and -r to set rootdir.

-l "pkg pkg1 ..." If set generates a local repository (/packages)
		  in the live image with the package list.
-r rootdir	  To specify an alternative rootdir to build the image.
This commit is contained in:
Juan RP 2012-11-22 14:35:37 +01:00
parent 5159224c3d
commit 8783414cc7
3 changed files with 261 additions and 248 deletions

View File

@ -1,11 +1,12 @@
VERSION = 0.9.8 GITVER := $(shell git rev-parse HEAD)
VERSION = 0.10
PREFIX ?= /usr/local PREFIX ?= /usr/local
SBINDIR ?= $(PREFIX)/sbin SBINDIR ?= $(PREFIX)/sbin
SHAREDIR ?= $(PREFIX)/share SHAREDIR ?= $(PREFIX)/share
DRACUTMODDIR ?= $(PREFIX)/lib/dracut/modules.d/01vmklive DRACUTMODDIR ?= $(PREFIX)/lib/dracut/modules.d/01vmklive
all: all:
sed -e "s|@@MKLIVE_VERSION@@|${VERSION}|g" mklive.sh.in > mklive.sh sed -e "s|@@MKLIVE_VERSION@@|$(VERSION) $(GITVER)|g" mklive.sh.in > mklive.sh
install: all install: all
install -d $(DESTDIR)$(SBINDIR) install -d $(DESTDIR)$(SBINDIR)

26
README
View File

@ -5,32 +5,30 @@ Void linux distribution. The images contain the void-installer package
to be able to install Void linux to storage disks. to be able to install Void linux to storage disks.
The generated image can be booted from BIOS and EFI systems (dual boot). The generated image can be booted from BIOS and EFI systems (dual boot).
For BIOS isolinux is used and for EFI we use grub2. ISOLINUX is used to boot from PC-BIOS systems, while GRUB is used to
boot in EFI systems.
Dependencies: Dependencies:
- xbps>=0.18. - xbps>=0.18
- systemd - syslinux (to generate the PC-BIOS bootloader)
- util-linux agetty(8). - dosfstools (to generate the EFI bootloader)
- dracut - xorriso (to generate the ISO image)
- grub with support for PC-BIOS and x86_64 EFI - squashfs-tools (to generate the squashed rootfs)
- syslinux - linux-user-chroot (to chroot and bind mount pseudofs)
- dosfstools (for mkfs.vfat)
- xorriso
- squashfs-tools
- void-installer
Usage: void-mklive [options] Usage: void-mklive [options]
Options: Options:
-C file Path to configuration file (defaults to ~/.mklive.conf) -C file Path to configuration file (defaults to ~/.mklive.conf)
-c (gzip|bzip2|xz) Compression type for the squashfs/initramfs image. -c (gzip|bzip2|xz) Compression type for the squashfs/initramfs image.
-k version Kernel version to use. -l "pkgname ..." Generate a local repository in the image with these packages.
Packages must be delimited by blanks.
-r rootdir Use this directory to generate the image (if unset,
current working directory will be used).
-o outfile Output file name for the ISO image. -o outfile Output file name for the ISO image.
-s splash Splash image file for isolinux. -s splash Splash image file for isolinux.
* If -k not specified it will use $(uname -r) by default.
* The first time it is executed a config file will be created (~/mklive.conf). * The first time it is executed a config file will be created (~/mklive.conf).
* It's assumed that void-mklive is executed in a Void Linux system.
Take a look at the configuration file (~/mklive.conf) to tweak some Take a look at the configuration file (~/mklive.conf) to tweak some
default parameters in the generated image. default parameters in the generated image.

View File

@ -23,38 +23,23 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#- #-
# vim: set ts=4 sw=4 et:
trap "echo; error_out $?" INT QUIT trap "echo; error_out $?" INT QUIT
CHROOT_CMD="linux-user-chroot --unshare-ipc --unshare-pid --unshare-net \
--mount-bind /dev /dev --mount-bind /sys /sys --mount-proc /proc"
info_msg() { info_msg() {
printf "\033[1m$@\n\033[m" printf "\033[1m$@\n\033[m"
} }
mount_pseudofs() {
local fs
for fs in sys proc dev; do
if [ ! -d "$ROOTFS/$fs" ]; then
mkdir -p "$ROOTFS/$fs"
fi
mount --bind /$fs "$ROOTFS/$fs" || error_out $?
done
}
umount_pseudofs() {
local fs
for fs in sys proc dev; do
umount -f "$ROOTFS/$fs" >/dev/null 2>&1
done
}
error_out() { error_out() {
umount_pseudofs
info_msg "There was an error! cleaning up $BUILDDIR, exiting..." info_msg "There was an error! cleaning up $BUILDDIR, exiting..."
[ -d "$BUILDDIR" ] && rm -rf "$BUILDDIR" [ -d "$BUILDDIR" ] && rm -rf "$BUILDDIR"
[ -f "$LOGFILE" ] && rm -f "$LOGFILE" #[ -f "$LOGFILE" ] && rm -f "$LOGFILE"
exit 1 exit 1
} }
@ -62,15 +47,14 @@ error_out() {
write_etc_motd() { write_etc_motd() {
cat >> "$ROOTFS/etc/motd" <<_EOF cat >> "$ROOTFS/etc/motd" <<_EOF
############################################################################### ###############################################################################
Autogenerated by void-mklive @@MKLIVE_VERSION@@ Autogenerated by void-mklive "@@MKLIVE_VERSION@@"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Welcome to the Void Linux Live system, you have been autologged in. Welcome to the Void Linux Live system, you have been autologged in.
This user has full sudo(8) permissions without any password, be careful This user has full sudo(8) permissions without any password, be careful
executing commands through sudo(8). executing commands through sudo(8).
To play with package management use the xbps-bin(8) and xbps-repo(8) To play with package management use the xbps-* utilities. Please visit:
utilities. Please visit:
http://code.google.com/p/xbps/ http://code.google.com/p/xbps/
@ -94,8 +78,9 @@ write_conf_file() {
# Default configuration file for vmklive-@VERSION@. # Default configuration file for vmklive-@VERSION@.
# #
# List of packages to be installed into the live image. # List of packages to be installed into the live image.
# At least 'base-system' or 'base-system-live' is required. # By default the 'base-system-live' pkg is always installed because
PACKAGE_LIST="base-system-live" # it is required to generate a working image.
#PACKAGE_LIST="foo blah"
# Syslinux splash image. # Syslinux splash image.
SPLASH_IMAGE=/usr/share/void-artwork/splash.png SPLASH_IMAGE=/usr/share/void-artwork/splash.png
@ -104,11 +89,14 @@ SPLASH_IMAGE=/usr/share/void-artwork/splash.png
KEYMAP=us KEYMAP=us
# Default locale to use. # Default locale to use.
LOCALE=en_US LOCALE=en_US.UTF-8
# Path to XBPS utilities. # Path to XBPS utilities.
#XBPS_BIN_CMD=xbps-bin #XBPS_INSTALL_CMD=xbps-install
#XBPS_REPO_CMD=xbps-repo #XBPS_QUERY_CMD=xbps-query
#XBPS_RECONFIGURE_CMD=xbps-reconfigure
#XBPS_REMOVE_CMD=xbps-remove
#XBPS_RINDEX_CMD=xbps-rindex
#XBPS_UHELPER_CMD=xbps-uhelper #XBPS_UHELPER_CMD=xbps-uhelper
# XBPS cache directory to install packages from. # XBPS cache directory to install packages from.
@ -126,39 +114,194 @@ Usage: $(basename $0) [options]
Options: Options:
-C file Path to configuration file (defaults to ~/.mklive.conf) -C file Path to configuration file (defaults to ~/.mklive.conf)
-c (gzip|bzip2|xz) Compression type for the squashfs/initramfs image. -c (gzip|bzip2|xz) Compression type for the squashfs/initramfs image.
-k version Kernel version to use. -l "pkgname ..." Generate a local repository in the image with these packages.
Packages must be delimited by blanks.
-r rootdir Use this directory to generate the image (if unset,
current working directory will be used).
-o outfile Output file name for the ISO image. -o outfile Output file name for the ISO image.
-s splash Splash image file for isolinux. -s splash Splash image file for isolinux.
_EOF _EOF
exit 1 exit 1
} }
install_packages() {
for f in ${PACKAGE_LIST}; do
info_msg " $f"
done
# Check that all pkgs are reachable.
${XBPS_INSTALL_CMD} ${XBPS_ARGS} -n xbps-git \
${PACKAGE_LIST} >>$LOGFILE 2>&1
if [ $? -ne 0 ]; then
info_msg "Missing required binary packages, exiting..."
error_out
fi
${XBPS_INSTALL_CMD} ${XBPS_ARGS} xbps-git ${PACKAGE_LIST} >>$LOGFILE 2>&1
[ $? -ne 0 ] && error_out $?
${XBPS_INSTALL_CMD} ${XBPS_ARGS} -u >>$LOGFILE 2>&1
[ $? -ne 0 ] && error_out $?
${XBPS_REMOVE_CMD} ${XBPS_ARGS} -o >>$LOGFILE 2>&1
[ $? -ne 0 ] && error_out $?
${XBPS_QUERY_CMD} -r "$ROOTFS" -l > \
"${OUTPUT_FILE%.iso}"-package-list.txt || error_out
# Reconfigure all pkgs again via linux-user-chroot.
$CHROOT_CMD $ROOTFS xbps-reconfigure -fa >>$LOGFILE 2>&1
}
generate_initramfs() {
# Install required pkgs in a temporary rootdir to create
# the initramfs and to copy required files.
$XBPS_INSTALL_CMD -r $ROOTFS/kernel_temp -y \
base-system void-mklive >>$LOGFILE 2>&1
# Install some required utilities from util-linux.
install -Dm755 $ROOTFS/kernel_temp/usr/sbin/agetty \
"$ROOTFS/usr/sbin/agetty" || error_out $?
install -Dm755 $ROOTFS/kernel_temp/usr/bin/lsblk \
"$ROOTFS/usr/bin/lsblk" || error_out $?
$CHROOT_CMD $ROOTFS/kernel_temp dracut --no-hostonly \
--add "dmsquash-live vmklive" --${COMPRESSTYPE} \
"/boot/initrd.lz" 2>/dev/null || error_out
mv $ROOTFS/kernel_temp/boot/initrd.lz $BOOT_DIR
# We rely on pam now, so let's install the host login config.
install -Dm644 $ROOTFS/kernel_temp/etc/pam.d/login \
"$ROOTFS/etc/pam.d/login" || error_out $?
}
copy_kernel_and_modules() {
cp -a $ROOTFS/kernel_temp/boot/vmlinuz-${KERNELVERSION} \
$BOOT_DIR/vmlinuz
mkdir -p $ROOTFS/lib/modules
cp -a $ROOTFS/kernel_temp/lib/modules/${KERNELVERSION} \
$ROOTFS/lib/modules
# remove temporary rootfs.
rm -rf $ROOTFS/kernel_temp
}
generate_local_repository() {
mkdir -p $ROOTFS/packages
pkgs=$($XBPS_INSTALL_CMD -s -r /tmp/blah -n ${LOCALREPO_PKGLIST})
set -- ${pkgs}
while [ $# -ne 0 ]; do
pkgn=$1; action=$2; ver=$3; repo=$4; binpkg=$5; arch=$6
shift 6
bpkg=$repo/$arch/$binpkg
cp -f $bpkg $ROOTFS/packages
done
$XBPS_RINDEX_CMD -a $ROOTFS/packages/*.xbps 2>&1 >>$LOGFILE
rm -f $ROOTFS/packages/index-files.plist
}
generate_isolinux_boot() {
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" || error_out $?
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" || error_out $?
cp -f $MKLIVE_DATADIR/isolinux.cfg.in \
"$ISOLINUX_DIR"/isolinux.cfg || error_out $?
if [ -f "$SPLASH_IMAGE" ]; then
cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" || error_out $?
fi
sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$(uname -m)|" \
-e "s|@@LOCALE@@|${LOCALE}|" $ISOLINUX_DIR/isolinux.cfg
}
generate_grub_efi_boot() {
cp -f $MKLIVE_DATADIR/grub.cfg $GRUB_DIR || error_out $?
cp -f $MKLIVE_DATADIR/grub_void.cfg.in \
$GRUB_DIR/grub_void.cfg || error_out $?
sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$(uname -m)|" \
-e "s|@@LOCALE@@|${LOCALE}|" $GRUB_DIR/grub_void.cfg
mkdir -p $GRUB_DIR/fonts $GRUB_DIR/locale || error_out $?
cp -f $GRUB_DATADIR/unicode.pf2 $GRUB_DIR/fonts || error_out $?
cp -f /boot/grub/locale/* $GRUB_DIR/locale || error_out $?
# Create EFI vfat image.
dd if=/dev/zero of=$GRUB_DIR/efiboot.img bs=1024 count=4096 \
>>$LOGFILE 2>&1 || error_out $?
mkfs.vfat -F12 -S 512 -n "grub_uefi" "$GRUB_DIR/efiboot.img" \
>>$LOGFILE 2>&1 || error_out $?
GRUB_EFI_TMPDIR="$(mktemp --tmpdir=$HOME -d)"
LOOP_DEVICE="$(losetup --show --find ${GRUB_DIR}/efiboot.img)"
mount -o rw,flush -t vfat "${LOOP_DEVICE}" "${GRUB_EFI_TMPDIR}" \
>>$LOGFILE 2>&1 || error_out $?
mkdir -p "${GRUB_EFI_TMPDIR}/EFI/boot/" || error_out $?
cd "$BUILDDIR" || error_out $?
grub-mkstandalone --directory="/usr/lib/grub/x86_64-efi" \
--format="x86_64-efi" \
--compression="xz" --output="${GRUB_EFI_TMPDIR}/EFI/boot/bootx64.efi" \
"boot/grub/grub.cfg" >>$LOGFILE 2>&1 || error_out $?
umount "$GRUB_EFI_TMPDIR" || error_out $?
losetup --detach "${LOOP_DEVICE}" || error_out $?
rm -rf $GRUB_EFI_TMPDIR || error_out $?
}
generate_squashfs() {
# Find out required size for the rootfs and create an ext3fs image off it.
ROOTFS_SIZE=$(du -sk "$ROOTFS"|awk '{print $1}')
mkdir -p "$BUILDDIR/tmp/LiveOS"
dd if=/dev/zero of="$BUILDDIR/tmp/LiveOS/ext3fs.img" \
bs="$((${ROOTFS_SIZE}+($ROOTFS_SIZE/6)))K" count=1 \
>>$LOGFILE 2>&1 || error_out $?
mkdir -p "$BUILDDIR/tmp-rootfs"
mkfs.ext3 -F -m1 "$BUILDDIR/tmp/LiveOS/ext3fs.img" \
>>$LOGFILE 2>&1 || error_out $?
mount -o loop "$BUILDDIR/tmp/LiveOS/ext3fs.img" \
"$BUILDDIR/tmp-rootfs" || error_out $?
cd $BUILDDIR
cp -a rootfs/* tmp-rootfs/
umount -f "$BUILDDIR/tmp-rootfs"
mkdir -p "$BUILDDIR/LiveOS"
mksquashfs "$BUILDDIR/tmp" "$BUILDDIR/LiveOS/squashfs.img" \
-comp ${COMPRESSTYPE} >>$LOGFILE 2>&1 || error_out
chmod 444 "$BUILDDIR/LiveOS/squashfs.img" || error_out $?
# Remove rootfs and temporary dirs, we don't need them anymore.
rm -rf "$ROOTFS" "$BUILDDIR/tmp-rootfs" "$BUILDDIR/tmp" || error_out $?
}
generate_iso_image() {
xorriso -as mkisofs \
-iso-level 3 -rock -joliet \
-max-iso9660-filenames -omit-period \
-omit-version-number -relaxed-filenames -allow-lowercase \
-volid "VOID_LIVE" \
-eltorito-boot boot/isolinux/isolinux.bin \
-eltorito-catalog boot/isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot --efi-boot boot/grub/efiboot.img -no-emul-boot \
-isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \
-output "$OUTPUT_FILE" "$BUILDDIR" >>$LOGFILE 2>&1 || error_out $?
}
# #
# main() # main()
# #
while getopts "C:c:k:o:s:h" opt; do while getopts "C:c:l:o:r:s:h" opt; do
case $opt in case $opt in
C) CONFIG_FILE="$OPTARG";; C) CONFIG_FILE="$OPTARG";;
c) COMPRESSTYPE="$OPTARG";; c) COMPRESSTYPE="$OPTARG";;
k) KERNELVERSION="$OPTARG";; l) LOCALREPO_PKGLIST="$OPTARG";;
o) OUTPUT_FILE="$OPTARG";; o) OUTPUT_FILE="$OPTARG";;
r) ROOTDIR="$OPTARG";;
s) SPLASH_IMAGE="$OPTARG";; s) SPLASH_IMAGE="$OPTARG";;
h) usage;; h) usage;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ -z "$KERNELVERSION" ]; then
KERNELVERSION="$(uname -r)"
fi
# Set defaults # Set defaults
if [ -z "$CONFIG_FILE" ]; then if [ -z "$CONFIG_FILE" ]; then
CONFIG_FILE="$HOME/.mklive.conf" CONFIG_FILE="$HOME/.mklive.conf"
fi fi
if [ -z "$OUTPUT_FILE" ]; then
OUTPUT_FILE="$HOME/void-live-$(uname -m)-${KERNELVERSION}-$(date +%Y%m%d).iso"
fi
LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)" LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)"
if [ -z "$SYSLINUX_DATADIR" ]; then if [ -z "$SYSLINUX_DATADIR" ]; then
@ -173,15 +316,24 @@ fi
if [ -z "$SPLASH_IMAGE" ]; then if [ -z "$SPLASH_IMAGE" ]; then
SPLASH_IMAGE=/usr/share/void-artwork/splash.png SPLASH_IMAGE=/usr/share/void-artwork/splash.png
fi fi
if [ -z "$XBPS_REPO_CMD" ]; then if [ -z "$XBPS_INSTALL_CMD" ]; then
XBPS_REPO_CMD=xbps-repo XBPS_INSTALL_CMD=xbps-install
fi fi
if [ -z "$XBPS_BIN_CMD" ]; then if [ -z "$XBPS_REMOVE_CMD" ]; then
XBPS_BIN_CMD=xbps-bin XBPS_REMOVE_CMD=xbps-remove
fi
if [ -z "$XBPS_QUERY_CMD" ]; then
XBPS_QUERY_CMD=xbps-query
fi
if [ -z "$XBPS_RINDEX_CMD" ]; then
XBPS_RINDEX_CMD=xbps-rindex
fi fi
if [ -z "$XBPS_UHELPER_CMD" ]; then if [ -z "$XBPS_UHELPER_CMD" ]; then
XBPS_UHELPER_CMD=xbps-uhelper XBPS_UHELPER_CMD=xbps-uhelper
fi fi
if [ -z "$XBPS_RECONFIGURE_CMD" ]; then
XBPS_RECONFIGURE_CMD=xbps-reconfigure
fi
if [ -z "$COMPRESSTYPE" ]; then if [ -z "$COMPRESSTYPE" ]; then
COMPRESSTYPE=xz COMPRESSTYPE=xz
fi fi
@ -197,7 +349,7 @@ fi
if [ -z "$PACKAGE_LIST" ]; then if [ -z "$PACKAGE_LIST" ]; then
PACKAGE_LIST="base-system-live" PACKAGE_LIST="base-system-live"
else else
PACKAGE_LIST="$PACKAGE_LIST" PACKAGE_LIST="base-system-live $PACKAGE_LIST"
fi fi
if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then
echo "Missing required isolinux files in $SYSLINUX_DATADIR, exiting..." echo "Missing required isolinux files in $SYSLINUX_DATADIR, exiting..."
@ -211,7 +363,11 @@ if [ "$(id -u)" -ne 0 ]; then
fi fi
ISO_VOLUME="VOID_LIVE" ISO_VOLUME="VOID_LIVE"
BUILDDIR=$(mktemp --tmpdir=$HOME -d) || exit 1 if [ -n "$ROOTDIR" ]; then
BUILDDIR=$(mktemp --tmpdir="$ROOTDIR" -d) || exit 1
else
BUILDDIR=$(mktemp --tmpdir="$(pwd -P)" -d) || exit 1a
fi
BUILDDIR=$(readlink -f $BUILDDIR) BUILDDIR=$(readlink -f $BUILDDIR)
ROOTFS="$BUILDDIR/rootfs" ROOTFS="$BUILDDIR/rootfs"
BOOT_DIR="$BUILDDIR/boot" BOOT_DIR="$BUILDDIR/boot"
@ -219,235 +375,93 @@ ISOLINUX_DIR="$BOOT_DIR/isolinux"
GRUB_DIR="$BOOT_DIR/grub" GRUB_DIR="$BOOT_DIR/grub"
ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg" ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg"
mkdir -p $ISOLINUX_DIR $GRUB_DIR
# #
# Check there are repos registered before anything. # Check there are repos registered before anything.
# #
${XBPS_REPO_CMD} list >/dev/null 2>&1 ${XBPS_QUERY_CMD} -L >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "No repositories available, exiting..." echo "No repositories available, exiting..."
error_out error_out
fi fi
#
# Mount pseudofs in the target rootfs.
#
mount_pseudofs
mkdir -p "$ROOTFS/tmp" "$ISOLINUX_DIR" "$GRUB_DIR"
XBPS_ARGS="-r $ROOTFS -y" XBPS_ARGS="-r $ROOTFS -y"
if [ -n "$REPOSITORY_CACHE" ]; then if [ -n "$REPOSITORY_CACHE" ]; then
XBPS_ARGS="$XBPS_ARGS -c $REPOSITORY_CACHE" XBPS_ARGS="$XBPS_ARGS -c $REPOSITORY_CACHE"
fi fi
XBPS_VERSION=$($XBPS_BIN_CMD -V|awk '{print $2}') XBPS_VERSION=$($XBPS_QUERY_CMD -V|awk '{print $2}')
case $XBPS_VERSION in case $XBPS_VERSION in
# XBPS >= 0.17 # XBPS >= 0.18
[0-9].[1-9][7-9]*) XBPS_017=1;; [0-9].[1-9][8-9]*) ;;
*) echo "Your xbps utilities are too old ($XBPS_VERSION), 0.18 is required." && exit 1;;
esac esac
info_msg "Redirecting stdout/stderr to $LOGFILE ..." KERNELVERSION=$($XBPS_QUERY_CMD -R --property version kernel)
info_msg "[1/10] Installing packages into the rootfs..."
for f in ${PACKAGE_LIST}; do
info_msg " $f"
done
# Check that all pkgs are reachable.
${XBPS_BIN_CMD} ${XBPS_ARGS} -n install ${PACKAGE_LIST} >>$LOGFILE 2>&1
if [ $? -ne 0 ]; then
info_msg "Missing required binary packages, exiting..."
error_out
fi
${XBPS_BIN_CMD} ${XBPS_ARGS} install ${PACKAGE_LIST} \
2>&1|cat >> $LOGFILE || error_out
${XBPS_BIN_CMD} ${XBPS_ARGS} autoupdate \
2>&1|cat >> $LOGFILE || error_out
${XBPS_BIN_CMD} ${XBPS_ARGS} autoremove \
2>&1|cat >> $LOGFILE || error_out
${XBPS_BIN_CMD} -r "$ROOTFS" list > \ if [ -z "$OUTPUT_FILE" ]; then
"${OUTPUT_FILE%.iso}"-package-list.txt || error_out OUTPUT_FILE="$HOME/void-live-$(uname -m)-${KERNELVERSION}-$(date +%Y%m%d).iso"
fi
info_msg "Redirecting stdout/stderr to $LOGFILE ..."
#
# Install live system and specified packages.
#
info_msg "[1/9] Installing packages into the rootfs..."
install_packages
# #
# Prepare /etc/motd. # Prepare /etc/motd.
# #
info_msg "[2/10] Creating /etc/motd..."
mkdir -p "$ROOTFS"/etc mkdir -p "$ROOTFS"/etc
write_etc_motd write_etc_motd
# #
# Create the initramfs with XZ compression. # Generate the initramfs.
# #
info_msg "[3/10] Creating initramfs image ($COMPRESSTYPE)..." info_msg "[2/9] Generating initramfs image ($COMPRESSTYPE)..."
dracut --no-hostonly --add "dmsquash-live vmklive" --${COMPRESSTYPE} \ generate_initramfs
"${BOOT_DIR}/initrd.lz" ${KERNELVERSION} 2>/dev/null || error_out
# #
# Copy the linux image to the target directory. # Copy linux kernel and modules to rootfs.
# #
info_msg "[4/10] Copying kernel image/modules..." info_msg "[3/9] Copying kernel image/modules from temporary rootfs..."
cp -f /boot/vmlinuz-${KERNELVERSION} "${BOOT_DIR}/vmlinuz" || error_out $? copy_kernel_and_modules
mkdir -p "$ROOTFS/lib/modules"
cp -a /lib/modules/${KERNELVERSION} "$ROOTFS/lib/modules" || error_out $?
# Generate a sane xbps.conf for the rootfs. #
rm -f $ROOTFS/etc/xbps/xbps.conf # Generate the package local repository for void-installer.
echo "# xbps.conf generated by void-mklive-@@MKLIVE_VERSION@@" \ #
> $ROOTFS/etc/xbps/xbps.conf if [ -z "$LOCALREPO_PKGLIST" ]; then
echo "TransactionFrequencyFlush = 0" \ _skip="(disabled)"
>> $ROOTFS/etc/xbps/xbps.conf
echo "virtual-package rsyslog { targets = syslog-daemon-0 }" \
>> $ROOTFS/etc/xbps/xbps.conf
echo "virtual-package dcron { targets = cron-daemon-0 }" \
>> $ROOTFS/etc/xbps/xbps.conf
echo "virtual-package kmod { targets = module-init-tools-3.17 }" \
>> $ROOTFS/etc/xbps/xbps.conf
_devel=$($XBPS_UHELPER_CMD -r $ROOTFS version xbps-devel)
if [ -n "${_devel}" ]; then
echo "virtual-package xbps-devel { targets = xbps-9999 }" \
>> $ROOTFS/etc/xbps/xbps.conf
fi fi
info_msg "[4/9] Generating package local repository ${_skip}..."
# Generate a conf for local repositories. if [ -n "$LOCALREPO_PKGLIST" ]; then
cat > $ROOTFS/etc/xbps/local-repos.conf <<_EOF generate_local_repository
repositories = {
# XBPS >= 0.16
/packages,
}
_EOF
# Generate a conf for remote repositories.
cat > $ROOTFS/etc/xbps/network-repos.conf <<_EOF
repositories = {
# XBPS >= 0.16
http://xbps.hosting-unlimited.org/binpkgs,
http://xbps.goodluckwith.us/binpkgs,
http://xbps.nopcode.org/repos/current,
}
_EOF
chmod 644 $ROOTFS/etc/xbps/*.conf || error_out $?
# Create local repos for base-system and grub-x86_64-efi packages required by
# the void-installer pkg.
pkgs=$($XBPS_BIN_CMD -r /tmp/blah -n install base-system grub-x86_64-efi)
set -- ${pkgs}
while [ $# -ne 0 ]; do
pkgn=$1; action=$2; ver=$3; repo=$4; binpkg=$5; arch=$6
shift 6
mkdir -p $ROOTFS/packages/$arch
bpkg=$repo/$arch/$binpkg
cp -f $bpkg $ROOTFS/packages/$arch
ln -sfr $ROOTFS/packages/$arch/$binpkg $ROOTFS/packages/$binpkg
done
if [ -n "$XBPS_017" ]; then
$XBPS_REPO_CMD index-add $ROOTFS/packages/*.xbps 2>&1 >>$LOGFILE
rm -f $ROOTFS/packages/index-files.plist
else
${XBPS_REPO_CMD} genindex $ROOTFS/packages 2>&1 >>$LOGFILE
rm -f $ROOTFS/packages/index-files.plist
fi fi
# Install some required utilities from util-linux.
_lsblk=$(which lsblk)
install -Dm755 ${_lsblk} "$ROOTFS/usr/bin/lsblk" || error_out $?
# We rely on pam now, so let's install the host login config.
install -Dm644 /etc/pam.d/login "$ROOTFS/etc/pam.d/login" || error_out $?
# #
# The pseudofs aren't needed anymore in target rootfs. # Generate the isolinux boot.
# #
umount_pseudofs info_msg "[5/9] Generating isolinux support for PC-BIOS systems..."
generate_isolinux_boot
# #
# Prepare isolinux files in the target rootfs. # Generate the GRUB EFI boot.
# #
info_msg "[5/10] Preparing isolinux support for BIOS..." info_msg "[6/9] Generating GRUB support for EFI systems..."
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" || error_out $? generate_grub_efi_boot
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" || error_out $?
cp -f $MKLIVE_DATADIR/isolinux.cfg.in \
"$ISOLINUX_DIR"/isolinux.cfg || error_out $?
if [ -f "$SPLASH_IMAGE" ]; then
cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" || error_out $?
fi
sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$(uname -m)|" \
-e "s|@@LOCALE@@|${LOCALE}|" $ISOLINUX_DIR/isolinux.cfg
# #
# Prepare grub files for EFI. # Generate the squashfs image from rootfs.
# #
info_msg "[6/10] Preparing GRUB support for EFI..." info_msg "[7/9] Generating squashfs image ($COMPRESSTYPE) from rootfs..."
cp -f $MKLIVE_DATADIR/grub.cfg $GRUB_DIR || error_out $? generate_squashfs
cp -f $MKLIVE_DATADIR/grub_void.cfg.in $GRUB_DIR/grub_void.cfg || error_out $?
sed -i -e "s|@@SPLASHIMAGE@@|$(basename $SPLASH_IMAGE)|" \
-e "s|@@KERNVER@@|${KERNELVERSION}|" \
-e "s|@@KEYMAP@@|${KEYMAP}|" \
-e "s|@@ARCH@@|$(uname -m)|" \
-e "s|@@LOCALE@@|${LOCALE}|" $GRUB_DIR/grub_void.cfg
mkdir -p $GRUB_DIR/fonts $GRUB_DIR/locale || error_out $?
cp -f $GRUB_DATADIR/unicode.pf2 $GRUB_DIR/fonts || error_out $?
cp -f /boot/grub/locale/* $GRUB_DIR/locale || error_out $?
# Create EFI vfat image.
dd if=/dev/zero of=$GRUB_DIR/efiboot.img bs=1024 count=4096 \
2>&1 | cat >>$LOGFILE || error_out $?
mkfs.vfat -F12 -S 512 -n "grub_uefi" "$GRUB_DIR/efiboot.img" \
2>&1 | cat >>$LOGFILE || error_out $?
GRUB_EFI_TMPDIR="$(mktemp --tmpdir=$HOME -d)"
LOOP_DEVICE="$(losetup --show --find ${GRUB_DIR}/efiboot.img)"
mount -o rw,flush -t vfat "${LOOP_DEVICE}" "${GRUB_EFI_TMPDIR}" \
2>&1 | cat >>$LOGFILE || error_out $?
mkdir -p "${GRUB_EFI_TMPDIR}/EFI/boot/" || error_out $?
cd "$BUILDDIR" || error_out $?
grub-mkstandalone --directory="/usr/lib/grub/x86_64-efi" --format="x86_64-efi" \
--compression="xz" --output="${GRUB_EFI_TMPDIR}/EFI/boot/bootx64.efi" \
"boot/grub/grub.cfg" 2>&1 | cat >>$LOGFILE || error_out $?
umount "$GRUB_EFI_TMPDIR" || error_out $?
losetup --detach "${LOOP_DEVICE}" || error_out $?
rm -rf $GRUB_EFI_TMPDIR || error_out $?
# #
# Prepare the squashed rootfs image. # Generate the ISO image.
# #
info_msg "[7/10] Creating squashfs image ($COMPRESSTYPE) from rootfs..." info_msg "[8/9] Generating ISO image..."
# Find out required size for the rootfs and create an ext3fs image off it. generate_iso_image
ROOTFS_SIZE=$(du -sk "$ROOTFS"|awk '{print $1}')
mkdir -p "$BUILDDIR/tmp/LiveOS"
dd if=/dev/zero of="$BUILDDIR/tmp/LiveOS/ext3fs.img" \
bs="$((${ROOTFS_SIZE}+($ROOTFS_SIZE/6)))K" count=1 2>&1 | cat >>$LOGFILE || error_out $?
mkdir -p "$BUILDDIR/tmp-rootfs"
mkfs.ext3 -F -m1 "$BUILDDIR/tmp/LiveOS/ext3fs.img" 2>&1 | cat >>$LOGFILE || error_out $?
mount -o loop "$BUILDDIR/tmp/LiveOS/ext3fs.img" "$BUILDDIR/tmp-rootfs" || error_out $?
cd $BUILDDIR
cp -a rootfs/* tmp-rootfs/
umount -f "$BUILDDIR/tmp-rootfs"
mkdir -p "$BUILDDIR/LiveOS"
mksquashfs "$BUILDDIR/tmp" "$BUILDDIR/LiveOS/squashfs.img" \ info_msg "[9/9] Removing build directory..."
-comp ${COMPRESSTYPE} 2>&1 | cat >> $LOGFILE || error_out
chmod 444 "$BUILDDIR/LiveOS/squashfs.img" || error_out $?
info_msg "[8/10] Removing rootfs directory..."
rm -rf "$ROOTFS" "$BUILDDIR/tmp-rootfs" "$BUILDDIR/tmp" || error_out $?
#
# Prepare the ISO image.
#
info_msg "[9/10] Building ISO image..."
xorriso -as mkisofs \
-iso-level 3 -rock -joliet \
-max-iso9660-filenames -omit-period \
-omit-version-number -relaxed-filenames -allow-lowercase \
-volid "VOID_LIVE" \
-eltorito-boot boot/isolinux/isolinux.bin \
-eltorito-catalog boot/isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-eltorito-alt-boot --efi-boot boot/grub/efiboot.img -no-emul-boot \
-isohybrid-mbr /usr/share/syslinux/isohdpfx.bin \
-output "$OUTPUT_FILE" "$BUILDDIR" 2>&1 | cat >>$LOGFILE || error_out $?
info_msg "[10/10] Removing build directory..."
rm -rf "$BUILDDIR" || error_out $? rm -rf "$BUILDDIR" || error_out $?
hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}') hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}')