[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Patches to correct live-sn



Greetings,

I am attaching patches for what I believe is a working live-sn setup.
I looked through all the options provided and removed many since a
working live-sn is essential and one good working way is better than
many that do not function or seem to be subsets of the essential need.
I believe with /etc/live-snapshot.list you tune in for what you want
like /home.

I have tested all the remaining persistent partitions types of
live-sn, live-rw, and home-rw and all worked ok on my development
machine. There is some tidy up if accepted that would be needed in the
live-snapshot man page and also the manual to reflect the available
options, but I believe the changes to be worth while.

Please consider merging to fix the broken live-sn.

P.S. On the live-initramfs.patch it also fixes the eject bug as
discussed on irc by remove the else return 0 in do_stop.
--- /etc/init.d/live-initramfs	2009-03-08 09:19:49.000000000 -0500
+++ live-initramfs	2009-05-05 20:33:14.000000000 -0500
@@ -95,19 +95,9 @@
 
 do_stop ()
 {
-	if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline
+	if ! grep -qs nopersistent /proc/cmdline && grep -qs persistent /proc/cmdline && [ ! -z "${SNAP}" ]
 	then
-		if [ ! -z "${ROOTSNAP}" ]
-		then
-			${DO_SNAPSHOT} --resync-string="${ROOTSNAP}"
-		fi
-
-		if [ ! -z "${HOMESNAP}" ]
-		then
-			${DO_SNAPSHOT} --resync-string="${HOMESNAP}"
-		fi
-	else
-		return 0
+		${DO_SNAPSHOT} --resync-string="${SNAP}"
 	fi
 
 	# check for netboot
--- /sbin/live-snapshot	2009-04-22 14:43:11.000000000 -0500
+++ live-snapshot	2009-05-05 18:25:54.000000000 -0500
@@ -27,8 +27,7 @@
 # can be found in /usr/share/common-licenses/GPL-3 file.
 
 # declare here two vars from /etc/live.conf because of "set -u"
-ROOTSNAP=""
-HOMESNAP=""
+SNAP=""
 
 if [ -n "${LIVE_SNAPSHOT_CHECK_UNBOUND}" ]
 then
@@ -50,9 +49,13 @@
 # Needs to be available at run and reboot time
 SAFE_TMPDIR="/live"
 
+MOUNTP="${SAFE_TMPDIR}/snap-backing"
 # Permits multiple runs
-MOUNTP="$(mktemp -d -p ${SAFE_TMPDIR} live-snapshot-mnt.XXXXXX)"
-DEST="${MOUNTP}/live-sn.cpio.gz"
+if [ ! -d "${MOUNTP}" ]
+then
+	mkdir "${MOUNTP}"
+fi
+DEST="/live-sn.cpio.gz"
 DEF_SNAP_COW="/live/cow"
 TMP_FILELIST="${PROGRAM}.list"
 
@@ -99,7 +102,6 @@
 	echo "  -o, --output: output image file (default: ${DEST})."
 	echo "  -r, --resync-string: internally used to resync previous made snapshots."
 	echo "  -f, --refresh: try to sync a running snapshot."
-	echo "  -t, --type: snapshot filesystem type. Options: \"squashfs\", \"ext2\", \"ext3\", \"ext4\", \"jffs2\" or \"cpio\".gz archive (default: ${SNAP_TYPE})"
 	echo
 	echo "Look at live-snapshot(1) man page for more information."
 
@@ -148,13 +150,8 @@
 Try_refresh ()
 {
 	FOUND=""
-	if [ -n "${ROOTSNAP}" ]; then
-		"${EXECUTABLE}" --resync-string="${ROOTSNAP}"
-		FOUND="Yes"
-	fi
-
-	if [ -n "${HOMESNAP}" ]; then
-		"${EXECUTABLE}" --resync-string="${HOMESNAP}"
+	if [ -n "${SNAP}" ]; then
+		"${EXECUTABLE}" --resync-string="${SNAP}"
 		FOUND="Yes"
 	fi
 
@@ -170,7 +167,7 @@
 {
 	# Parse command line
 	ARGS="${*}"
-	ARGUMENTS="$(getopt --longoptions cow:,device:,output,resync-string:,refresh,type:,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:fhuv --shell sh -- ${ARGS})"
+	ARGUMENTS="$(getopt --longoptions cow:,device:,output,resync-string:,refresh,help,usage,version --name=${PROGRAM} --options c:d:o:t:r:fhuv --shell sh -- ${ARGS})"
 
 	eval set -- "${ARGUMENTS}"
 
@@ -192,11 +189,6 @@
 				shift 2
 				;;
 
-			-t|--type)
-				SNAP_TYPE="${2}"
-				shift 2
-				;;
-
 			-r|--resync-string)
 				SNAP_RESYNC_STRING="${2}"
 				break
@@ -246,55 +238,17 @@
 				SNAP_TYPE="cpio"
 				;;
 
-			*.squashfs)
-				SNAP_TYPE="squashfs"
-				;;
-
-			*.jffs2)
-				SNAP_TYPE="jffs2"
-				;;
-
-			""|*.ext2|*.ext3)
-				SNAP_TYPE="ext2"
-				;;
-
-			*.ext4)
-				SNAP_TYPE="ext4"
-				;;
-
 			*)
 				Error "unrecognized resync string"
 				;;
 		esac
-	elif [ -z "${SNAP_OUTPUT}" ]
-	then
-		# Set target file based on image
-		case "${SNAP_TYPE}" in
-			cpio)
-				DEST="${MOUNTP}/live-sn.cpio.gz"
-				;;
-
-			squashfs|jffs2|ext2)
-				DEST="${MOUNTP}/live-sn.${SNAP_TYPE}"
-				;;
-
-			ext3)
-				DEST="${MOUNTP}/live-sn.ext2"
-				;;
-
-			ext4)
-				DEST="${MOUNTP}/live-sn.ext4"
-				;;
-		esac
-	else
-		DEST="${SNAP_OUTPUT}"
 	fi
 }
 
 Validate_input ()
 {
 	case "${SNAP_TYPE}" in
-		cpio|squashfs|jffs2|ext2|ext3|ext4)
+		cpio)
 			;;
 
 		*)
@@ -395,59 +349,26 @@
 Do_snapshot ()
 {
 	TMP_FILELIST=$(mktemp -p "${SAFE_TMPDIR}" "${TMP_FILELIST}.XXXXXX")
-
-	case "${SNAP_TYPE}" in
-		squashfs)
-			echo ".${TMP_FILELIST}" > "${TMP_FILELIST}"
-			# Removing whiteheads of unionfs
-			cd "${SNAP_COW}"
-			find . -name '*.wh.*' >> "${TMP_FILELIST}"
-
-			if [ -e "${EXCLUDE_LIST}" ]
-			then
-				# Add explicitly excluded files
-				grep -v '^#.*$' "${EXCLUDE_LIST}" | grep -v '^ *$' >> "${TMP_FILELIST}"
-			fi
-
-			cd "${OLDPWD}"
-			mksquashfs "${SNAP_COW}" "${DEST}" -ef "${TMP_FILELIST}"
-			;;
-
-		cpio)
-			WORKING_DIR=$(Do_filelist "${TMP_FILELIST}")
-			cd "${WORKING_DIR}"
-			if [ -e "${EXCLUDE_LIST}" ]
-			then
-				# Convert \0 to \n and tag existing (rare but possible) \n in filenames,
-				# this to let grep -F -v do a proper work in filtering out
-				cat "${TMP_FILELIST}" | \
-					tr '\n' '\1' | \
-					tr '\0' '\n' | \
-					grep -F -v -f "${EXCLUDE_LIST}" | \
-					tr '\n' '\0' | \
-					tr '\1' '\n' | \
-					cpio --quiet -o0 -H newc | \
-					gzip -9c > "${DEST}" || exit 1
-			else
-				cat "${TMP_FILELIST}" | \
-					cpio --quiet -o0 -H newc | \
-					gzip -9c > "${DEST}" || exit 1
-			fi
-			cd "${OLDPWD}"
-			;;
-
-		# ext2|ext3|ext4 and jffs2 does not easily support an exclude list; files
-		# should be copied to another directory in order to filter content
-		ext2|ext3|ext4)
-			DU_DIM="$(du -ks ${SNAP_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="${SNAP_COW}" "${DEST}"
-			;;
-
-		jffs2)
-			mkfs.jffs2 --root="${SNAP_COW}" --output="${DEST}"
-			;;
-	esac
+	WORKING_DIR=$(Do_filelist "${TMP_FILELIST}")
+	cd "${WORKING_DIR}"
+	if [ -e "${EXCLUDE_LIST}" ]
+	then
+		# Convert \0 to \n and tag existing (rare but possible) \n in filenames,
+		# this to let grep -F -v do a proper work in filtering out
+		cat "${TMP_FILELIST}" | \
+			tr '\n' '\1' | \
+			tr '\0' '\n' | \
+			grep -F -v -f "${EXCLUDE_LIST}" | \
+			tr '\n' '\0' | \
+			tr '\1' '\n' | \
+			cpio --quiet -o0 -H newc | \
+			gzip -9c > "${DEST}" || exit 1
+	else
+		cat "${TMP_FILELIST}" | \
+			cpio --quiet -o0 -H newc | \
+			gzip -9c > "${DEST}" || exit 1
+	fi
+	cd "${OLDPWD}"
 
 	if [ -f "${TMP_FILELIST}" ]
 	then
@@ -470,21 +391,8 @@
 {
 	if [ -z "${SNAP_RESYNC_STRING}" ]
 	then
-		case ${SNAP_TYPE} in
-			cpio|ext2|ext3|ext4)
-				echo "Please move ${DEST} (if is not already in it)" > /dev/null 1>&2
-				echo "in a supported writable partition (e.g ext3, vfat)." > /dev/null 1>&2
-				;;
-
-			squashfs)
-				echo "To use ${DEST} you need to rebuild your media or add it" > /dev/null 1>&2
-				echo "to your multisession disc under the \"/live\" directory." > /dev/null 1>&2
-				;;
-
-			jffs2)
-				echo "Please cat or flashcp ${DEST} to your partition in order to start using it." > /dev/null 1>&2
-				;;
-		esac
+		echo "Please move ${DEST} (if is not already in it)" > /dev/null 1>&2
+		echo "in a supported writable partition (e.g ext3, vfat)." > /dev/null 1>&2
 
 		if grep -qv persistent /proc/cmdline
 		then
--- /usr/share/initramfs-tools/scripts/live	2009-05-04 10:35:39.000000000 -0500
+++ live	2009-05-05 16:52:19.000000000 -0500
@@ -13,7 +13,6 @@
 root_persistence="live-rw"
 home_persistence="home-rw"
 root_snapshot_label="live-sn"
-home_snapshot_label="home-sn"
 
 USERNAME="user"
 USERFULLNAME="Live user"
@@ -865,157 +864,54 @@
 	return ${rc}
 }
 
-do_snap_copy ()
-{
-	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=$(awk -v pat="$(base_path ${todir})" '$2 == pat { print $1 }' /proc/mounts)
-			freespace=$(df -k | awk '/'${todev}'/{print $4}')
-		else
-			freespace=$( expr $(awk '/MemFree/{print $2}' /proc/meminfo) + $( awk '/\<Cached/{print $2}' /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 -o ro -t "${fstype}" "${fromdev}" "${tomount}" || log_warning_msg "Error in mount -t ${fstype} -o ro ${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
-
-		log_warning_msg "Unable to find the snapshot ${snap_type} medium"
-	fi
-}
-
-find_snap ()
-{
-	# Look for ${snap_label}.* in block devices
-	snap_label="${1}"
-
-	if [ "${PERSISTENT}" != "nofiles" ]
-	then
-		# search for image files
-		snapdata=$(find_files "${snap_label}.squashfs ${snap_label}.cpio.gz ${snap_label}.ext2 ${snap_label}.ext3 ${snal_label}.ext4 ${snap_label}.jffs2")
-	fi
-
-	if [ -z "${snapdata}" ]
-	then
-		snapdata=$(find_cow_device "${snap_label}")
-	fi
-	echo "${snapdata}"
-}
-
 try_snap ()
 {
         # copy the contents of previously found snapshot to ${snap_mount}
 	# and remember the device and filename for resync on exit in live-initramfs.init
 
-	snapdata="${1}"
-	snap_mount="${2}"
-	snap_type="${3}"
-
-	if [ ! -z "${snapdata}" ]
-	then
-		log_success_msg "found snapshot: ${snapdata}"
-		snapdev="$(echo ${snapdata} | cut -f1 -d ' ')"
-		snapback="$(echo ${snapdata} | cut -f2 -d ' ')"
-		snapfile="$(echo ${snapdata} | cut -f3 -d ' ')"
+	snapdata="${#}"
+	snap_dev="${1}"
+	snap_mount="${2}/${3}-dir"
+	snap_file="${3}.cpio.gz"
+
+	if [ ! -z "${snap_dev}" ]
+	then
+		log_success_msg "Trying snapshot with the following parameters: ${snapdata}"
 
 		RES=""
-		if ! try_mount "${snapdev}" "${snapback}" "ro"
+		if [ ! -d "${snap_mount}" ]
 		then
-			break
+			mkdir "${snap_mount}"
 		fi
-
-		if echo "${snapfile}" | grep -qs '\(squashfs\|ext2\|ext3\|ext4\|jffs2\)'
+		if ! try_mount "${snap_dev}" "${snap_mount}" "ro"
 		then
-			# squashfs, jffs2 or ext2/ext3/ext4 snapshot
-			dev=$(get_backing_device "${snapback}/${snapfile}")
-
-			do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
-			RES=$?
-		else
-			# cpio.gz snapshot
-			cd "${snap_mount}"
-			zcat "${snapback}/${snapfile}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
-			RES=$?
-			if [ "${RES}" != "0" ]
-			then
-				log_warning_msg "failure to \"zcat ${snapback}/${snapfile} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
-			fi
-			cd "${OLDPWD}"
+			break
 		fi
 
-		umount "${snapback}" ||  log_warning_msg "failure to \"umount ${snapback}\""
-
+		# cpio.gz snapshot
+		log_begin_msg "Attemtping to restore snapshot ${snap_mount}/${snap_file}"
+		cd "/root"
+		zcat "${snap_mount}/${snap_file}" | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories > /dev/null 2>&1
+		RES=$?
 		if [ "${RES}" != "0" ]
 		then
-			log_warning_msg "Impossible to include the ${snapfile} Snapshot file"
-		fi
+			log_warning_msg "failure to \"zcat ${snap_mount}/${snap_file} | /bin/cpio --extract --preserve-modification-time --no-absolute-filenames --sparse --unconditional --make-directories\""
+			fi
+		cd "${OLDPWD}"
 
+		umount "${snap_mount}" ||  log_warning_msg "failure to \"umount ${snap_mount}\""
 
-	elif [ -b "${snapdata}" ]
-	then
-		# Try to find if it could be a snapshot partition
-		dev="${snapdata}"
-		log_success_msg "found snapshot device on ${dev}"
-		if echo "${dev}" | grep -qs loop
+		if [ "${RES}" != "0" ]
 		then
-			# strange things happens, user confused?
-			snaploop=$( losetup ${dev} | awk '{print $3}' | tr -d '()' )
-			snapfile=$(basename ${snaploop})
-			snapdev=$(awk -v pat="$( dirname ${snaploop})" '$2 == pat { print $1 }' /proc/mounts)
-		else
-			snapdev="${dev}"
+			log_warning_msg "Impossible to include the ${snap_file} Snapshot file"
 		fi
 
-		if ! do_snap_copy "${dev}" "${snap_mount}" "${snap_type}"
-		then
-			log_warning_msg "Impossible to include the ${snap_type} 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_type} Snapshot"
+		log_warning_msg "Impossible to include the ${snap_file} Snapshot"
 		return 1
 	fi
 
-	echo "export ${snap_type}SNAP="${snap_mount}":${snapdev}:${snapfile}" >> /etc/live.conf # for resync on reboot/halt
+	echo "export SNAP="${snap_mount}":${snap_dev}:${snap_file}" >> /etc/live.conf # for resync on reboot/halt
 	return 0
 }
 
@@ -1198,11 +1094,8 @@
 			PERSISTENCE_IS_ON="1"
 			export PERSISTENCE_IS_ON
 		fi
-		root_snapdata=$(find_snap "${root_snapshot_label}" "${blacklistdev}")
-		# This second type should be removed when snapshot will get smarter,
-		# hence when "/etc/live-snapshot*list" will be supported also by
-		# ext2|ext3|ext4|jffs2 snapshot types.
-		home_snapdata=$(find_snap "${home_snapshot_label}" "${blacklistdev}")
+		# root_snapdata is for live-sn
+		root_snapdata=$(find_cow_device "${root_snapshot_label}" "${blacklistdev}")
 
 		if [ -b "${cowprobe}" ]
 		then
@@ -1305,9 +1198,7 @@
 		fi
 
 		# Look for other snapshots to copy in
-		try_snap "${root_snapdata}" "${rootmnt}" "ROOT"
-		# This second type should be removed when snapshot grow smarter
-		try_snap "${home_snapdata}" "${rootmnt}/home" "HOME"
+		try_snap "${root_snapdata}" "${mountpoint}" "${root_snapshot_label}"
 	fi
 
 	if [ -n "${SHOWMOUNTS}" ]

Reply to: