vmklive: update to 0.7.0.

- Uses xbps-casper from host.
- Uses base-system-live rather than base-system by default.
- Uses kernel image/modules from host.
- Improved output.
This commit is contained in:
Juan RP 2012-02-04 18:11:26 +01:00
parent 5a8eea5fc9
commit 5a729f8ccd
2 changed files with 176 additions and 84 deletions

View file

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# #
# Public Domain, 2009-2011 - Juan RP <xtraeme@gmail.com> # Public Domain, 2009-2012 - Juan RP <xtraeme@gmail.com>
# #
trap "echo; error_out $?" INT QUIT trap "echo; error_out $?" INT QUIT
@ -41,11 +41,11 @@ error_out()
{ {
umount_pseudofs umount_pseudofs
if [ "$1" -ne 0 ]; then info_msg "There was an error! cleaning up $BUILDDIR, exiting..."
echo "ERROR: stage mentioned above returned $1!"
fi [ -d "$BUILDDIR" ] && rm -rf "$BUILDDIR"
info_msg "Cleaning up $BUILDDIR..." [ -f "$LOGFILE" ] && rm -f "$LOGFILE"
rm -rf "$BUILDDIR"
exit 1 exit 1
} }
@ -56,7 +56,7 @@ write_etc_motd()
Autogenerated by vmklive @@MKLIVE_VERSION@@. Autogenerated by vmklive @@MKLIVE_VERSION@@.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Welcome to the Void GNU/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).
@ -69,6 +69,8 @@ for more information and/or documentation about using the X Binary
Package System. If you think it is useful, please make a donation Package System. If you think it is useful, please make a donation
to improve further development from the above URL, thanks. to improve further development from the above URL, thanks.
To install Void Linux type 'sudo void-installer'.
############################################################################### ###############################################################################
_EOF _EOF
} }
@ -122,18 +124,49 @@ LOCALBOOT 0x80
_EOF _EOF
} }
write_conf_file()
{
cat > "$1" <<_EOF
# *-*- sh -*-*
# Default configuration file for vmklive-@VERSION@.
#
# List of packages to be installed into the live image.
# At least 'base-system' or 'base-system-live' is required.
PACKAGE_LIST="base-system-live"
# Syslinux splash image.
SPLASH_IMAGE=/usr/share/void-artwork/splash.png
# Default keymap to use.
KEYMAP=us
# Default locale to use.
LOCALE=en_US.UTF-8
# Path to XBPS utilities.
#XBPS_BIN_CMD=xbps-bin
#XBPS_REPO_CMD=xbps-repo
#XBPS_UHELPER_CMD=xbps-uhelper
# XBPS cache directory to install packages from.
#REPOSITORY_CACHE=/blah/foo
_EOF
chmod 644 "$1"
}
usage() usage()
{ {
cat <<_EOF cat <<_EOF
Usage: $(basename $0) [options] Usage: $(basename $0) [options] <kernel-version>
Options: Options:
-c comptype Compression type for the squashfs image. -C file Path to configuration file (defaults to ~/.mklive.conf)
-o outfile Output file name for the ISO image. -c (gzip|bzip2|xz) Compression type for the squashfs/initramfs image.
-r rootdir Rootfs directory. -o outfile Output file name for the ISO image.
-s splash Splash image file for isolinux. -r rootdir Rootfs directory.
-v volname ISO Volume name. -s splash Splash image file for isolinux.
-h Shows this message. -v volname ISO Volume name.
_EOF _EOF
exit 1 exit 1
} }
@ -141,63 +174,90 @@ _EOF
# #
# main() # main()
# #
while getopts "c:o:r:s:v:h" opt; do while getopts "C:c:o:r:s:v:" opt; do
case $opt in case $opt in
c) export SQUASHFS_COMPRESSION="$OPTARG";; C) CONFIG_FILE="$OPTARG";;
o) export OUTPUT_FILE="$OPTARG";; c) COMPRESSTYPE="$OPTARG";;
r) export ROOTDIR="$OPTARG";; o) OUTPUT_FILE="$OPTARG";;
s) export SPLASH_IMAGE="$OPTARG";; r) ROOTDIR="$OPTARG";;
v) export ISO_VOLUME="$OPTARG";; s) SPLASH_IMAGE="$OPTARG";;
h) usage;; v) ISO_VOLUME="$OPTARG";;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if [ "$(id -u)" -ne 0 ]; then KERNELVERSION="$1"
echo "ERROR: EPERM... got root?" if [ -z "$KERNELVERSION" ]; then
usage
fi
# Check that specific kernel version contains the unionfs module.
if [ ! -r "/boot/config-${KERNELVERSION}" ]; then
echo "Missing /boot/config-${KERNELVERSION} file, exiting..."
exit 1
elif ! grep -Eq "^CONFIG_UNION_FS=(y|m)$" /boot/config-${KERNELVERSION}; then
echo "kernel ${KERNELVERSION} does not contain unionfs support, exiting..."
exit 1 exit 1
fi fi
CONFIG_DIR="$HOME/.mklive" # Set defaults
CONFIG_FILE="$CONFIG_DIR/default.conf" if [ -z "$CONFIG_FILE" ]; then
CONFIG_FILE="$HOME/.mklive.conf"
fi
if [ -z "$OUTPUT_FILE" ]; then if [ -z "$OUTPUT_FILE" ]; then
OUTPUT_FILE="$HOME/void-live-$(uname -m)-$(date +%Y%m%d).iso" OUTPUT_FILE="$HOME/void-live-$(uname -m)-${KERNELVERSION}-$(date +%Y%m%d).iso"
fi fi
LOGFILE="$(mktemp -t vmklive-XXXXXXXXXX.log)"
if [ -z "$ISO_VOLUME" ]; then if [ -z "$ISO_VOLUME" ]; then
ISO_VOLUME="Void GNU/Linux Live $(uname -m)" ISO_VOLUME="Void Linux Live $(uname -m) ${KERNELVERSION}"
fi
if [ -z "$SYSLINUX_DATADIR" ]; then
SYSLINUX_DATADIR=/usr/share/syslinux
fi
if [ -z "$SPLASH_IMAGE" ]; then
SPLASH_IMAGE=/usr/share/void-artwork/splash.png
fi
if [ -z "$XBPS_REPO_CMD" ]; then
XBPS_REPO_CMD=xbps-repo
fi
if [ -z "$XBPS_BIN_CMD" ]; then
XBPS_BIN_CMD=xbps-bin
fi
if [ -z "$XBPS_UHELPER_CMD" ]; then
XBPS_UHELPER_CMD=xbps-uhelper
fi
if [ -z "$COMPRESSTYPE" ]; then
COMPRESSTYPE=xz
fi fi
# # Create or read configuration file.
# The following vars can be overwritten by the config file.
#
SYSLINUX_DATADIR="/usr/share/syslinux"
SPLASH_IMAGEDIR="/usr/share/void-artwork"
SPLASH_IMAGE="$SPLASH_IMAGEDIR/splash.png"
XBPS_REPO_CMD="xbps-repo"
XBPS_BIN_CMD="xbps-bin"
XBPS_UHELPER_CMD="xbps-uhelper"
if [ ! -r $CONFIG_FILE ]; then if [ ! -r $CONFIG_FILE ]; then
echo "Cannot find $CONFIG_FILE! exiting..." info_msg "Creating config file at $CONFIG_FILE."
error_out write_conf_file $CONFIG_FILE
fi fi
. $CONFIG_FILE . $CONFIG_FILE
if [ -z "$PACKAGE_LIST" ]; then if [ -z "$PACKAGE_LIST" ]; then
PACKAGE_LIST="xbps-casper base-system" PACKAGE_LIST="base-system-live"
else else
PACKAGE_LIST="xbps-casper base-system $PACKAGE_LIST" PACKAGE_LIST="base-system-live $PACKAGE_LIST"
fi fi
BUILDDIR=$(mktemp --tmpdir="$(pwd)" -d) || exit 1 BUILDDIR=$(mktemp --tmpdir=$HOME -d) || exit 1
BUILDDIR=$(readlink -f $BUILDDIR) BUILDDIR=$(readlink -f $BUILDDIR)
ROOTFS="$BUILDDIR/casper/rootfs" ROOTFS="$BUILDDIR/casper/rootfs"
ISOLINUX_DIR="$BUILDDIR/isolinux" ISOLINUX_DIR="$BUILDDIR/isolinux"
ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg" ISOLINUX_CFG="$ISOLINUX_DIR/isolinux.cfg"
if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then if [ ! -f $SYSLINUX_DATADIR/isolinux.bin ]; then
echo "Missing required isolinux files in $SYSLINUX_DATADIR!" echo "Missing required isolinux files in $SYSLINUX_DATADIR, exiting..."
error_out
fi
# Check for root permissions.
if [ "$(id -u)" -ne 0 ]; then
echo "Must be run as root, exiting..."
error_out error_out
fi fi
@ -207,68 +267,97 @@ fi
mount_pseudofs mount_pseudofs
mkdir -p "$ROOTFS/tmp" mkdir -p "$ROOTFS/tmp"
XBPS_ARGS="-r $ROOTFS -y"
if [ -n "$REPOSITORY_CACHE" ]; then
XBPS_ARGS="$XBPS_ARGS -c $REPOSITORY_CACHE"
fi
XBPS_VERSION=$($XBPS_BIN_CMD -V|awk '{print $2}')
case $XBPS_VERSION in
# XBPS >= 0.12
[0-9].[1-9][2-9]*);;
# XBPS < 0.12
*) purge_flag="-p" ;;
esac
info_msg "Redirecting stdout/stderr to $LOGFILE..."
info_msg "[1/9] Installing packages into the rootfs..."
for f in ${PACKAGE_LIST}; do
info_msg " $f"
done
if [ -z "$ROOTDIR" ]; then if [ -z "$ROOTDIR" ]; then
${XBPS_REPO_CMD} -r "$ROOTFS" sync || error_out $? ${XBPS_BIN_CMD} ${XBPS_ARGS} install ${PACKAGE_LIST} \
${XBPS_BIN_CMD} -r "$ROOTFS" -c $(pwd)/repocache-$(uname -m) \ 2>&1|cat >> $LOGFILE || error_out
-y install ${PACKAGE_LIST} || error_out $? ${XBPS_BIN_CMD} ${XBPS_ARGS} autoupdate \
${XBPS_BIN_CMD} -r "$ROOTFS" -c $(pwd)/repocache-$(uname -m) \ 2>&1|cat >> $LOGFILE || error_out
-y autoupdate || error_out $? ${XBPS_BIN_CMD} ${XBPS_ARGS} ${purge_flag} autoremove \
${XBPS_BIN_CMD} -r "$ROOTFS" -yp autoremove || error_out $? 2>&1|cat >> $LOGFILE || error_out
${XBPS_BIN_CMD} -r "$ROOTFS" -yvp purge all || error_out $?
fi fi
${XBPS_BIN_CMD} -r "$ROOTFS" list > \ ${XBPS_BIN_CMD} -r "$ROOTFS" list > \
"${OUTPUT_FILE%.iso}"-package-list.txt || error_out $? "${OUTPUT_FILE%.iso}"-package-list.txt || error_out
# #
# Prepare /etc/motd. # Prepare /etc/motd.
# #
info_msg "Creating /etc/motd..." info_msg "[2/9] Creating /etc/motd..."
write_etc_motd write_etc_motd
# #
# We must know the installed kernel package version. # Create the initramfs with XZ compression.
# #
kver=$(${XBPS_UHELPER_CMD} -r "$ROOTFS" version kernel) info_msg "[3/9] Creating initramfs image ($COMPRESSTYPE)..."
if [ -z "$kver" ]; then mkinitramfs -c ${COMPRESSTYPE} \
echo "Missing 'kernel' package in repository pool!" -o "$BUILDDIR/casper/initrd.lz" ${KERNELVERSION} \
error_out 2>/dev/null || error_out
fi
#
# Rebuild the initramfs image with LZMA compression.
#
info_msg "Copying initramfs image..."
INITRD_IMAGE=$(echo $ROOTFS/boot/initrd.img-*)
cp -f "$INITRD_IMAGE" "$BUILDDIR/casper/initrd.lz" || error_out $?
mkdir -p "$ROOTFS"/cow mkdir -p "$ROOTFS"/cow
# #
# Copy the linux image to the target directory. # Copy the linux image to the target directory.
# #
info_msg "Copying kernel image..." info_msg "[4/9] Copying kernel image/modules..."
KERNEL_IMG=$(echo $ROOTFS/boot/vmlinuz-*) cp -f /boot/vmlinuz-${KERNELVERSION} "$BUILDDIR/casper/vmlinuz" || error_out $?
cp -f "$KERNEL_IMG" "$BUILDDIR/casper/vmlinuz" || error_out $? mkdir -p "$ROOTFS/lib/modules"
cp -a /lib/modules/${KERNELVERSION} "$ROOTFS/lib/modules" || error_out $?
# XXX: install GNU find, grep and xargs.
for f in find grep xargs; do
install -Dm755 /usr/bin/${f} "$ROOTFS/usr/bin/$f" || error_out $?
done
# XXX: install lsblk and blkid from util-linux.
install -Dm755 /bin/lsblk "$ROOTFS/usr/bin/lsblk" || error_out $?
install -Dm755 /sbin/blkid "$ROOTFS/sbin/blkid" || error_out $?
# Install Void installer.
install -Dm755 $HOME/projects/void-installer/void-installer.sh \
"$ROOTFS/usr/sbin/void-installer" || error_out $?
rm -f "$ROOTFS/bin/grep" || error_out $?
# #
# Remove stuff that uses a lot of space. # Copy required xbps-casper files for autologin.
# #
info_msg "Cleaning up rootfs..." install -Dm644 /etc/casper.conf "$ROOTFS/etc/casper.conf" || error_out $?
rm -f "$ROOTFS"/boot/initrd* install -Dm755 /sbin/casper-getty "$ROOTFS/sbin/casper-getty" || error_out $?
rm -f "$ROOTFS"/boot/vmlinuz* install -Dm755 /sbin/casper-login "$ROOTFS/sbin/casper-login" || error_out $?
# #
# The pseudofs aren't needed anymore in target rootfs. # The pseudofs aren't needed anymore in target rootfs.
# #
umount_pseudofs umount_pseudofs
# Save a few MBs from /usr/share.
for d in info man examples doc; do
[ -d "$ROOTFS/usr/share/${d}" ] && rm -rf "$ROOTFS/usr/share/${d}"
done
# #
# Copy required isolinux files in the target rootfs. # Copy required isolinux files in the target rootfs.
# #
info_msg "[5/9] Copying isolinux files..."
mkdir -p "$ISOLINUX_DIR" mkdir -p "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/isolinux.bin "$ISOLINUX_DIR"
cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR" cp -f $SYSLINUX_DATADIR/vesamenu.c32 "$ISOLINUX_DIR"
write_default_isolinux_conf ${kver} write_default_isolinux_conf $(uname -r)
if [ -f "$SPLASH_IMAGE" ]; then if [ -f "$SPLASH_IMAGE" ]; then
cp -f $SPLASH_IMAGE "$ISOLINUX_DIR" cp -f $SPLASH_IMAGE "$ISOLINUX_DIR"
fi fi
@ -276,30 +365,32 @@ fi
# #
# Prepare the squashed rootfs image. # Prepare the squashed rootfs image.
# #
info_msg "Building squashed root filesystem..." info_msg "[6/9] Creating squashfs image ($COMPRESSTYPE) from rootfs..."
mksquashfs "$ROOTFS" "$BUILDDIR/casper/filesystem.squashfs" \ mksquashfs "$ROOTFS" "$BUILDDIR/casper/filesystem.squashfs" \
-root-becomes / -comp ${SQUASHFS_COMPRESSION:-gzip} && \ -root-becomes / -comp ${COMPRESSTYPE} \
chmod 444 "$BUILDDIR/casper/filesystem.squashfs" || error_out $? 2>&1 | cat >> $LOGFILE || error_out
chmod 444 "$BUILDDIR/casper/filesystem.squashfs" || error_out $?
if [ -n "$ROOTDIR" ]; then if [ -n "$ROOTDIR" ]; then
umount_pseudofs yes umount_pseudofs yes
else else
info_msg "Removing rootfs directory..." info_msg "[7/9] Removing rootfs directory..."
rm -rf "$ROOTFS" || error_out $? rm -rf "$ROOTFS" || error_out $?
fi fi
# #
# Prepare the ISO image. # Prepare the ISO image.
# #
info_msg "Building ISO image..." info_msg "[8/9] Building ISO image..."
mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \ mkisofs -J -r -V "$ISO_VOLUME" -b isolinux/isolinux.bin \
-c isolinux/boot.cat -no-emul-boot \ -c isolinux/boot.cat -no-emul-boot \
-boot-load-size 4 -boot-info-table \ -boot-load-size 4 -boot-info-table \
-o "$OUTPUT_FILE" "$BUILDDIR" || error_out $? -o "$OUTPUT_FILE" "$BUILDDIR" 2>&1 | cat >>$LOGFILE || error_out $?
info_msg "Removing build directory..." info_msg "[9/9] Removing build directory..."
rm -rf "$BUILDDIR" || error_out $? rm -rf "$BUILDDIR" || error_out $?
info_msg "Created $(readlink -f $OUTPUT_FILE) successfully." hsize=$(du -sh "$OUTPUT_FILE"|awk '{print $1}')
info_msg "Created $(readlink -f $OUTPUT_FILE) ($hsize) successfully."
exit 0 exit 0

View file

@ -1,6 +1,6 @@
# Template file for 'vmklive' # Template file for 'vmklive'
pkgname=vmklive pkgname=vmklive
version=0.6.3 version=0.7.0
short_desc="Void GNU/Linux live image maker" short_desc="Void GNU/Linux live image maker"
maintainer="Juan RP <xtraeme@gmail.com>" maintainer="Juan RP <xtraeme@gmail.com>"
license="Public domain" license="Public domain"
@ -13,10 +13,11 @@ replaces="xbps-mklive>=0 vanilla-mklive>=0"
noextract=yes noextract=yes
noarch=yes noarch=yes
Add_dependency full initramfs-tools
Add_dependency full xbps-casper
Add_dependency full cdrtools Add_dependency full cdrtools
Add_dependency full squashfs-tools Add_dependency full squashfs-tools
Add_dependency full syslinux Add_dependency full syslinux
Add_dependency full initramfs-tools
do_build() { do_build() {
sed "s|@@MKLIVE_VERSION@@|${version}|g" \ sed "s|@@MKLIVE_VERSION@@|${version}|g" \