xbps-casper: simplify and remove unused stuff.

- Removed support for snapshots.
- Removed support for multiple images, we only support one by default "filesystem.squashfs".
- Make all vars local to funcs.
This commit is contained in:
Juan RP 2011-05-20 14:25:04 +02:00
parent 040ed7a0cd
commit df7f341ba1
6 changed files with 91 additions and 667 deletions

View File

@ -1,309 +0,0 @@
#! /bin/bash
# casper-snapshot - utility to manage Debian Live systems snapshots
#
# This program mount a device (fallback to /tmpfs under /mnt/snapshot
# and save the /cow (or a different dir) filesystem in it for reusing
# in another casper session. Look at manpage for more info.
#
# Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# On Debian systems, the complete text of the GNU General Public License
# can be found in /usr/share/common-licenses/GPL file.
PROGRAM="`basename $0`"
VERSION=0.0.1
# Source casper conf
if [ -e /etc/casper.conf ]; then
. /etc/casper.conf
else
USERNAME=$(cat /etc/passwd | grep "999" | cut -f1 -d ':')
HOSTNAME=$(hostname)
BUILD_SYSTEM="Debian"
fi
export USERNAME USERFULLNAME HOSTNAME BUILD_SYSTEM
# Source helper functions
helpers="/usr/share/initramfs-tools/scripts/casper-helpers"
if [ -e "${helpers}" ]; then
. "${helpers}"
else
echo "Error: I cannot found helper functions \"${helpers}\"."
exit 1
fi
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
MOUNTP=""
COW=""
DEV=""
DEST=""
TYPE=""
DESKTOP_LINK=""
Header ()
{
echo "${PROGRAM} - utility to do Debian Live snapshots"
echo
echo "Usage: ${PROGRAM} [-c|--cow DIRECTORY] [-d|--device DEVICE] [-o|--output FILE] [-t|--type TYPE]"
echo "Usage: ${PROGRAM} [-r|--resync-string STRING]"
echo "Usage: ${PROGRAM} [-h|--help]"
echo "Usage: ${PROGRAM} [-u|--usage]"
echo "Usage: ${PROGRAM} [-v|--version]"
}
Usage ()
{
MESSAGE=${1}
Header
echo
echo "Try \"${PROGRAM} --help\" for more information."
if [ ! -z "${MESSAGE}" ]; then
echo -e "${MESSAGE}"
exit 1
else
exit 0
fi
}
Help ()
{
Header
echo
echo "Options:"
echo " -c, --cow: specifies the copy on write directory (default: /cow)."
echo " -d, --device: specifies the output snapshot device (default: none)."
echo " -o, --output: specifies the output image file (default: $type dependent)."
echo " -r, --resync-string: internally used to resync previous made snapshots."
echo " -t, --type: specifies the snapshot type between \"squashfs\", \"ext2\" or \"cpio\".gz archive (default: cpio)"
echo -e "\nLook at casper-snapshot(1) man page for more information."
exit 0
}
Version ()
{
echo "${PROGRAM}, version ${VERSION}"
echo
echo "Copyright (C) 2006 Marco Amadori <marco.amadori@gmail.com>"
echo
echo "This program is free software; you can redistribute it and/or modify"
echo "it under the terms of the GNU General Public License as published by"
echo "the Free Software Foundation; either version 2 of the License, or"
echo "(at your option) any later version."
echo
echo "This program is distributed in the hope that it will be useful,"
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of"
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the"
echo "GNU General Public License for more details."
echo
echo "You should have received a copy of the GNU General Public License"
echo "along with this program; if not, write to the Free Software"
echo "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA"
echo
echo "On Debian systems, the complete text of the GNU General Public License"
echo "can be found in /usr/share/common-licenses/GPL file."
echo
echo "Homepage: <http://live.debian.net/>"
exit 0
}
Do_snapshot ()
{
case "${TYPE}" in
squashfs)
echo "./tmp/exclude_list" > /tmp/exclude_list
( cd "${COW}" && find . -name '*.wh.*' >> /tmp/exclude_list )
mksquashfs "${COW}" "${DEST}" -ef /tmp/exclude_list || exit 1
rm /tmp/exclude_list
;;
cpio)
( cd "${COW}" && find . -path '*.wh.*' -prune -o -print0 | cpio --quiet -o0 -H newc | gzip -9c > "${DEST}" ) || exit 1
;;
ext2)
DU_DIM="`du -ks ${COW} | cut -f1`"
REAL_DIM="`expr ${DU_DIM} + ${DU_DIM} / 20`" # Just 5% more to be sure, need something more sophistcated here...
genext2fs --size-in-blocks=${REAL_DIM} --reserved-percentage=0 --root="${COW}" "${DEST}" || exit 1
;;
*)
echo "Internal error."
exit 1
;;
esac
}
Is_same_mount ()
{
dir1="`Base_path $1`"
dir2="`Base_path $2`"
if [ "${dir1}" == "${dir2}" ]; then
return 0
else
return 1
fi
}
Parse_args ()
{
# Parse command line
ARGUMENTS="`getopt --longoptions cow:,device:,output,resync-string:,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:,h,u,v --shell sh -- "$@"`"
if [ "$?" != "0" ]; then
echo "Terminating." >&2
exit 1
fi
eval set -- "${ARGUMENTS}"
while true; do
case "$1" in
-c|--cow)
SNAP_COW="$2"; shift 2 ;;
-d|--device)
SNAP_DEV="$2"; shift 2 ;;
-o|--output)
SNAP_OUTPUT="$2"; shift 2 ;;
-t|--type)
SNAP_TYPE="$2"; shift 2 ;;
-r|--resync-string)
SNAP_RSTRING="$2"; break ;;
-h|--help)
Help; shift ;;
-u|--usage)
Usage ; shift ;;
-v|--version)
Version; shift ;;
--)
shift; break ;;
*)
echo "Internal error."; exit 1 ;;
esac
done
}
Mount_device ()
{
dev="$1"
if [ ! -d "${MOUNTP}" ]; then
mkdir -p "${MOUNTP}"
fi
if [ -z "${dev}" ]; then
# create a temp
mount -t tmpfs -o rw tmpfs "${MOUNTP}"
if [ ! -L /home/$USERNAME/Desktop/casper-snapshot ]; then
ln -s "${MOUNTP}" /home/$USERNAME/Desktop/casper-snapshot
fi
else
if [ -b "${dev}" ] ; then
try_mount "${dev}" "${MOUNTP}" rw
fi
fi
}
Defaults ()
{
MOUNTP="/mnt/casper-snapshot"
COW="/cow"
DEV=""
TYPE="cpio"
DESKTOP_LINK=/home/$USERNAME/Desktop/casper-snapshot
if [ -n "${SNAP_RSTRING}" ]; then
COW=$(echo "${SNAP_RSTRING}" | cut -f1 -d ':')
DEV=$(echo "${SNAP_RSTRING}" | cut -f2 -d ':')
DEST="${MOUNTP}/$(echo "${SNAP_RSTRING}" | cut -f3 -d ':')"
case "${DEST}" in
*.cpio.gz)
TYPE="cpio" ;;
*.squashfs)
TYPE="squashfs" ;;
"")
TYPE="ext2" ;;
*.ext2)
TYPE="ext2" ;;
*)
Usage "Unrecognized String" ;;
esac
else
DEF_COW="/cow"
# Bad options handling
if [ -z "${SNAP_COW}" ]; then
COW="${DEF_COW}"
else
COW="${SNAP_COW}"
fi
case "${SNAP_TYPE}" in
"cpio"|"squashfs"|"ext2")
TYPE="${SNAP_TYPE}"
;;
"")
TYPE="cpio" ;;
*)
Usage "Error: unrecognized snapshot type"
;;
esac
case "${TYPE}" in
cpio)
DEST="${MOUNTP}/casper-sn.cpio.gz" ;;
squashfs)
DEST="${MOUNTP}/casper-sn.squashfs" ;;
ext2)
DEST="${MOUNTP}/casper-sn.ext2" ;;
*)
echo "Internal error."
exit 1
;;
esac
#if [ -d
#if Is_same_mount
fi
# check vars
if [ ! -d "${COW}" ]; then
Usage "Error: ${COW} is not a directory"
fi
Mount_device $DEV
}
Clean ()
{
if [ -n "$DEV" ]; then
umount "${MOUNTP}"
rmdir "${MOUNTP}"
rm
fi
}
Main ()
{
Parse_args "$@"
Defaults
Do_snapshot
Clean
}
Main "$@"

View File

@ -1 +0,0 @@
COMPCACHE_SIZE="25%"

View File

@ -58,7 +58,7 @@ manual_add_modules sbp2
manual_add_modules ohci1394
# Casper helpers.
for helper in getty login new-uuid snapshot; do
for helper in getty login new-uuid; do
ln -s /sbin/casper-${helper} ${DESTDIR}/bin
done
cp /usr/share/initramfs-tools/scripts/casper-helpers $DESTDIR/scripts

View File

@ -6,11 +6,7 @@ export PATH=/usr/bin:/usr/sbin:/bin:/sbin
mountpoint=/cdrom
LIVE_MEDIA_PATH=casper
root_persistence="casper-rw"
home_persistence="home-rw"
root_snapshot_label="casper-sn"
home_snapshot_label="home-sn"
LIVE_ROOTFS=filesystem.squashfs
USERNAME=casper
USERFULLNAME="Live session user"
@ -30,19 +26,18 @@ if [ ! -f /casper.vars ]; then
touch /casper.vars
fi
parse_cmdline() {
parse_cmdline()
{
for x in $(cat /proc/cmdline); do
case $x in
showmounts|show-cow)
export SHOWMOUNTS='Yes' ;;
persistent)
export PERSISTENT="Yes" ;;
nopersistent)
export PERSISTENT="" ;;
union=*)
export UNIONFS="${x#union=}";;
ignore_uuid)
IGNORE_UUID="Yes" ;;
live-rootfs=*)
LIVE_ROOTFS="${x#live-rootfs=}"
export LIVE_ROOTFS
echo "export LIVE_ROOTFS=\"$LIVE_ROOTFS\"" >> /etc/casper.conf ;;
live-media-path=*)
LIVE_MEDIA_PATH="${x#live-media-path=}"
export LIVE_MEDIA_PATH
@ -58,27 +53,27 @@ parse_cmdline() {
fi
}
is_casper_path() {
path=$1
is_casper_path()
{
local path=$1
if [ -d "$path/$LIVE_MEDIA_PATH" ]; then
if [ "$(echo $path/$LIVE_MEDIA_PATH/*.squashfs)" != \
"$path/$LIVE_MEDIA_PATH/*.squashfs" ] ||
[ "$(echo $path/$LIVE_MEDIA_PATH/*.ext2)" != \
"$path/$LIVE_MEDIA_PATH/*.ext2" ] ||
[ "$(echo $path/$LIVE_MEDIA_PATH/*.dir)" != \
"$path/$LIVE_MEDIA_PATH/*.dir" ]; then
"$path/$LIVE_MEDIA_PATH/*.squashfs" ]; then
return 0
fi
fi
return 1
}
matches_uuid() {
matches_uuid()
{
if [ "$IGNORE_UUID" ] || [ ! -e /conf/uuid.conf ]; then
return 0
fi
path="$1"
uuid="$(cat /conf/uuid.conf)"
local path="$1"
local uuid="$(cat /conf/uuid.conf)"
for try_uuid_file in "$path/.disk/casper-uuid"*; do
[ -e "$try_uuid_file" ] || continue
try_uuid="$(cat "$try_uuid_file")"
@ -89,44 +84,34 @@ matches_uuid() {
return 1
}
get_backing_device() {
get_backing_device()
{
case "$1" in
*.squashfs|*.ext2)
*.squashfs)
echo $(setup_loop "$1" "loop" "/sys/block/loop*")
;;
*.dir)
echo "directory"
;;
*)
panic "Unrecognized casper filesystem: $1"
;;
esac
}
match_files_in_dir() {
# Does any files match pattern $1 ?
mount_image_in_directory()
{
local directory="$1"
local rootmnt="$2"
local pattern="$1"
if [ "$(echo $pattern)" != "$pattern" ]; then
return 0
if [ ! -f "$directory/$LIVE_MEDIA_PATH/$LIVE_ROOTFS" ]; then
panic "Cannot find $directory/$LIVE_MEDIA_PATH/$LIVE_ROOTFS"
fi
return 1
}
mount_images_in_directory() {
directory="$1"
rootmnt="$2"
if match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.squashfs" ||
match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.ext2" ||
match_files_in_dir "$directory/$LIVE_MEDIA_PATH/*.dir"; then
setup_unionfs "$directory/$LIVE_MEDIA_PATH" "$rootmnt"
else
:
fi
}
is_nice_device() {
sysfs_path="${1#/sys}"
is_nice_device()
{
local sysfs_path="${1#/sys}"
if /lib/udev/path_id "${sysfs_path}" | egrep -q "ID_PATH=(usb|pci-[^-]*-(ide|scsi|usb)|platform-orion-ehci|platform-
mmc|platform-mxsdhci)"; then
return 0
@ -137,10 +122,12 @@ mmc|platform-mxsdhci)"; then
return 1
}
copy_live_to() {
copyfrom="${1}"
copytodev="${2}"
copyto="${copyfrom}_swap"
copy_live_to()
{
local copyfrom="${1}"
local copytodev="${2}"
local copyto="${copyfrom}_swap"
local size freespace mount_options free_string fstype dev
size=$(fs_size "" ${copyfrom} "used")
@ -181,120 +168,12 @@ copy_live_to() {
return 0
}
do_snap_copy ()
setup_unionfs()
{
fromdev="${1}"
todir="${2}"
snap_type="${3}"
size=$(fs_size "${fromdev}" "" "used")
if [ -b "${fromdev}" ]; then
# look for free mem
if [ -n "${HOMEMOUNTED}" -a "${snap_type}" = "HOME" ]; then
todev=$(cat /proc/mounts | grep -s " $(base_path ${todir}) " | awk '{print $1}' )
freespace=$(df -k | grep -s ${todev} | awk '{print $4}')
else
freespace=$(awk '/^MemFree:/{f=$2} /^Cached:/{c=$2} END{print f+c}' /proc/meminfo)
fi
tomount="/mnt/tmpsnap"
if [ ! -d "${tomount}" ] ; then
mkdir -p "${tomount}"
fi
fstype=$(get_fstype "${fromdev}")
if [ -n "${fstype}" ]; then
# Copying stuff...
mount -t "${fstype}" -o ro,noatime "${fromdev}" "${tomount}"
cp -a "${tomount}"/* ${todir}
umount "${tomount}"
else
log_warning_msg "Unrecognized fstype: ${fstype} on ${fromdev}:${snap_type}"
fi
rmdir "${tomount}"
if echo ${fromdev} | grep -qs loop; then
losetup -d "${fromdev}"
fi
return 0
else
return 1
[ "$quiet" != "y" ] && \
log_warning_msg "Unable to find the snapshot ${snap_type} medium"
fi
}
try_snap ()
{
# Look for $snap_label.* in block devices and copy the contents to $snap_mount
# and remember the device and filename for resync on exit in casper.init
snap_label="${1}"
snap_mount="${2}"
snap_type="${3}"
snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2")
if [ ! -z "${snapdata}" ]; then
snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\)'; then
# squashfs or ext2 snapshot
dev=$(get_backing_device "${snapback}/${snapfile}")
if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"; then
log_warning_msg "Impossible to include the ${snapfile} Snapshot"
return 1
fi
else
# cpio.gz snapshot
# Unfortunately klibc's cpio is incompatible with the rest of
# the world; everything else requires -u -d, while klibc doesn't
# implement them. Try to detect whether it's in use.
cpiopath="$(which cpio)" || true
if [ "$cpiopath" ] && grep -aq /lib/klibc "$cpiopath"; then
cpioargs=
else
cpioargs='-u -d'
fi
if ! (cd "${snap_mount}" && zcat "${snapback}/${snapfile}" | cpio -i $cpioargs 2>/dev/null) ; then
log_warning_msg "Impossible to include the ${snapfile} Snapshot"
return 1
fi
fi
umount "${snapback}"
else
dev=$(find_cow_device "${snap_label}")
if [ -b ${dev} ]; then
if echo "${dev}" | grep -qs loop; then
# strange things happens, user confused?
snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
snapfile=$(basename ${snaploop})
snapdev=$(cat /proc/mounts | awk '{print $2,$1}' | grep -es "^$( dirname ${snaploop} )" | cut -f2 -d ' ')
else
snapdev="${dev}"
fi
if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}" ; then
log_warning_msg "Impossible to include the ${snap_label} Snapshot"
return 1
else
if [ -n "${snapfile}" ]; then
# it was a loop device, user confused
umount ${snapdev}
fi
fi
else
log_warning_msg "Impossible to include the ${snap_label} Snapshot"
return 1
fi
fi
echo "export ${snap_type}SNAP="/cow${snap_mount#$rootmnt}":${snapdev}:${snapfile}" >> /etc/casper.conf # for resync on reboot/halt
return 0
}
setup_unionfs() {
image_directory="$1"
rootmnt="$2"
local image_directory="$1"
local rootmnt="$2"
local croot rofsstring rofslist roopt image imagename backdev
local fstype cowdevice cow_fstrype cow_mountopt
case ${UNIONFS} in
aufs|unionfs)
@ -306,39 +185,31 @@ setup_unionfs() {
# move all of these away before it runs anyway. No, we're not,
# put them in / since move-mounting them into / breaks mono and
# some other apps.
croot="/"
# Let's just mount the read-only file systems first
rofsstring=""
rofslist=""
if [ "${NETBOOT}" = "nfs" ] ; then
roopt="nfsro" # work around a bug in nfs-unionfs locking
elif [ "${UNIONFS}" = "aufs" ]; then
if [ "${UNIONFS}" = "aufs" ]; then
roopt="rr"
else
roopt="ro"
fi
mkdir -p "${croot}"
for image_type in "ext2" "squashfs" "dir" ; do
for image in "${image_directory}"/*."${image_type}"; do
imagename=$(basename "${image}")
if [ -d "${image}" ]; then
# it is a plain directory: do nothing
rofsstring="${image}=${roopt}:${rofsstring}"
rofslist="${image} ${rofslist}"
elif [ -f "${image}" ]; then
image="${image_directory}/${LIVE_ROOTFS}"
imagename=$(basename "$image")
backdev=$(get_backing_device "$image")
fstype=$(get_fstype "${backdev}")
if [ "${fstype}" = "unknown" ]; then
panic "Unknown file system type on ${backdev} (${image})"
fi
mkdir -p "${croot}/${imagename}"
mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" || panic "Can not mount $backdev ($image) on ${croot}/${imagename}" && rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}" && rofslist="${croot}/${imagename} ${rofslist}"
fi
done
done
mount -t "${fstype}" -o ro,noatime "${backdev}" "${croot}/${imagename}" \
|| panic "Can not mount $backdev ($image) on ${croot}/${imagename}"
rofsstring="${croot}/${imagename}=${roopt}:${rofsstring}"
rofslist="${croot}/${imagename} ${rofslist}"
rofsstring=${rofsstring%:}
mkdir -p /cow
@ -346,72 +217,23 @@ setup_unionfs() {
cow_fstype="tmpfs"
cow_mountopt="rw,noatime,mode=755"
# Looking for "${root_persistence}" device or file
if [ -n "${PERSISTENT}" ]; then
cowprobe=$(find_cow_device "${root_persistence}")
if [ -b "${cowprobe}" ]; then
cowdevice=${cowprobe}
cow_fstype=$(get_fstype "${cowprobe}")
cow_mountopt="rw,noatime"
else
[ "$quiet" != "y" ] && \
log_warning_msg "Unable to find the persistent medium"
fi
fi
mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} \
/cow || panic "Can not mount $cowdevice on /cow"
mount -t ${UNIONFS} -o noatime,dirs=/cow=rw:$rofsstring \
${UNIONFS} "$rootmnt" || panic "${UNIONFS} mount failed"
# Adding other custom mounts
if [ -n "${PERSISTENT}" ]; then
# directly mount /home
# FIXME: add a custom mounts configurable system
homecow=$(find_cow_device "${home_persistence}" )
if [ -b "${homecow}" ]; then
mount -t $(get_fstype "${homecow}") -o rw,noatime \
"${homecow}" "${rootmnt}/home"
# Used to proper calculate free space in do_snap_copy()
export HOMEMOUNTED=1
else
[ "$quiet" != "y" ] && \
log_warning_msg "Unable to find the persistent home medium"
fi
# Look for other snapshots to copy in
try_snap "${root_snapshot_label}" "${rootmnt}" "ROOT"
try_snap "${home_snapshot_label}" "${rootmnt}/home" "HOME"
fi
if [ -n "${SHOWMOUNTS}" ]; then
for d in ${rofslist}; do
mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
case d in
*.dir)
# do nothing
;;
*)
mount -o move "${d}" \
"${rootmnt}/${LIVE_MEDIA_PATH}/${d##*/}"
;;
esac
done
# shows cow fs on /cow for use by casper-snapshot
mkdir -p "${rootmnt}/cow"
mount -o bind /cow "${rootmnt}/cow"
fi
# XXX: hardcode the image name for now (xtraeme).
# move the first mount.
mkdir -p "${rootmnt}/rofs"
mount -o move /filesystem.squashfs "${rootmnt}/rofs"
mount -o move ${croot}${imagename} "${rootmnt}/rofs"
}
check_dev()
{
sysdev="${1}"
devname="${2}"
skip_uuid_check="${3}"
local sysdev="${1}"
local devname="${2}"
local skip_uuid_check="${3}"
local loopdevname devuid
if [ -z "${devname}" ]; then
devname=$(sys2dev "${sysdev}")
fi
@ -454,8 +276,11 @@ check_dev ()
return 1
}
find_livefs() {
timeout="${1}"
find_livefs()
{
local timeout="${1}"
local devname fstype dev
# first look at the one specified in the command line
if [ ! -z "${LIVEMEDIA}" ]; then
if check_dev "null" "${LIVEMEDIA}" "skip_uuid_check"; then
@ -484,10 +309,7 @@ find_livefs() {
return 0
fi
done
elif [ "${fstype}" = "squashfs" -o \
"${fstype}" = "ext4" -o \
"${fstype}" = "ext3" -o \
"${fstype}" = "ext2" ]; then
elif [ "${fstype}" = "squashfs" ]; then
# This is an ugly hack situation, the block device has
# an image directly on it. It's hopefully
# casper, so take it and run with it.
@ -499,7 +321,10 @@ find_livefs() {
return 1
}
mountroot() {
mountroot()
{
local i livefs_root live_dest
parse_cmdline
wait_for_udev 10
@ -510,7 +335,7 @@ mountroot() {
# Scan local devices for the image
i=0
while [ "$i" -lt 60 ]; do
while [ "$i" -lt 10 ]; do
livefs_root=$(find_livefs $i)
[ -n "${livefs_root}" ] && break
sleep 1
@ -532,7 +357,7 @@ mountroot() {
log_end_msg
fi
mount_images_in_directory "${livefs_root}" "${rootmnt}"
mount_image_in_directory "${livefs_root}" "${rootmnt}"
maybe_break casper-bottom
log_begin_msg "Running /scripts/casper-bottom"

View File

@ -1,13 +1,15 @@
## Casper helper functions, used by casper on boot and by casper-snapshot
## Casper helper functions, used by casper on boot.
MP_QUIET="-q"
sys2dev() {
sys2dev()
{
sysdev=${1#/sys}
echo "/dev/$(/sbin/udevadm info -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})"
}
subdevices() {
subdevices()
{
sysblock=$1
r=""
for dev in "${sysblock}" "${sysblock}"/*; do
@ -18,7 +20,8 @@ subdevices() {
echo ${r}
}
is_supported_fs () {
is_supported_fs()
{
# FIXME: do something better like the scan of supported filesystems
fstype="${1}"
case ${fstype} in
@ -29,11 +32,13 @@ is_supported_fs () {
return 1
}
get_fstype() {
get_fstype()
{
/sbin/blkid -s TYPE -o value $1 2>/dev/null
}
where_is_mounted() {
where_is_mounted()
{
device=$1
if grep -q "^$device " /proc/mounts; then
mountpoint="$(grep "^$device " /proc/mounts | awk '{print $2; exit}')"
@ -44,30 +49,6 @@ where_is_mounted() {
return 1
}
lastline() {
while read lines ; do
line=${lines}
done
echo "${line}"
}
base_path ()
{
testpath="${1}"
mounts="$(awk '{print $2}' /proc/mounts)"
testpath="$(busybox realpath ${testpath})"
while true ; do
if echo "${mounts}" | grep -qs "^${testpath}" ; then
set -- `echo "${mounts}" | grep "^${testpath}" | lastline`
echo ${1}
break
else
testpath=`dirname $testpath`
fi
done
}
fs_size()
{
# Returns used/free fs kbytes + 5% more
@ -147,73 +128,3 @@ setup_loop() {
panic "No loop devices available"
fi
}
try_mount ()
{
dev="${1}"
mountp="${2}"
opts="${3}"
if where_is_mounted ${dev} > /dev/null; then
if [ "${opts}" != "ro" ]; then
mount -o remount,"${opts}" ${dev} $(where_is_mounted ${dev}) || panic "Remounting failed"
fi
mount -o bind $(where_is_mounted ${dev}) ${mountp} || panic "Cannot bind-mount"
else
mount -t $(get_fstype "${dev}") -o "${opts}" "${dev}" "${mountp}" || panic "Cannot mount ${dev} on ${mountp}"
fi
}
find_cow_device() {
pers_label="${1}"
cow_backing="/${pers_label}-backing"
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
for dev in $(subdevices "${sysblock}"); do
devname=$(sys2dev "${dev}")
if [ "$(/sbin/blkid -s LABEL -o value $devname 2>/dev/null)" = "${pers_label}" ]; then
echo "$devname"
return
# Do not add any filesystem types here that might be able to
# mount a journalled filesystem and replay the journal. Doing so
# will cause data loss when a live CD is booted on a system
# where filesystems are in use by hibernated operating systems.
elif [ "$(get_fstype ${devname})" = "vfat" ]; then
mkdir -p "${cow_backing}"
try_mount "${devname}" "${cow_backing}" "rw"
if [ -e "${cow_backing}/${pers_label}" ]; then
echo $(setup_loop "${cow_backing}/${pers_label}" "loop" "/sys/block/loop*")
return 0
else
umount ${cow_backing}
fi
fi
done
done
}
find_files()
# return the first of $filenames found on vfat and ext2 devices
# FIXME: merge with above function
{
filenames="${1}"
snap_backing="/snap-backing"
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
for dev in $(subdevices "${sysblock}"); do
devname=$(sys2dev "${dev}")
devfstype="$(get_fstype ${devname})"
if [ "${devfstype}" = "vfat" ] || [ "${devfstype}" = "ext2" ] ; then # FIXME: all supported block devices should be scanned
mkdir -p "${snap_backing}"
try_mount "${devname}" "${snap_backing}" "ro"
for filename in ${filenames}; do
if [ -e "${snap_backing}/${filename}" ]; then
echo "${devname} ${snap_backing} ${filename}"
return 0
fi
done
umount ${snap_backing}
fi
done
done
}

View File

@ -1,6 +1,6 @@
# Template file for 'xbps-casper'
pkgname=xbps-casper
_localver=0.16 # XBPS package version
_localver=0.17 # XBPS package version
_distver=1.236 # This should match the upstream (Ubuntu) version
version=${_localver}.${_distver}
build_style=custom-install
@ -30,12 +30,10 @@ do_install()
# initramfs-tools hooks/scripts
initramfsdir=${DESTDIR}/usr/share/initramfs-tools
install -d ${initramfsdir}/hooks ${initramfsdir}/scripts/casper-bottom \
${initramfsdir}/conf.d
install -d ${initramfsdir}/hooks ${initramfsdir}/scripts/casper-bottom
install -m 755 ${FILESDIR}/hooks/* ${initramfsdir}/hooks
install -m 755 ${FILESDIR}/scripts/casper-bottom/* \
${initramfsdir}/scripts/casper-bottom
install -m 644 ${FILESDIR}/scripts/{casper,casper-helpers} \
${initramfsdir}/scripts
install -m 644 ${FILESDIR}/conf.d/* ${initramfsdir}/conf.d
}