CLOSED : Underdog/Hybrid Debian Jessie (boot frugal or full)

A home for all kinds of Puppy related projects
Message
Author
User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#21 Post by rufwoof »

save2flash/snapmergepuppy upon which flush2disk is based uses find for searching for .wh files ...etc. The first time that runs find is somewhat slow as it scans through the disk. Subsequent runs tend to be quicker i.e. much/all of find has already been cached.

To help speed things up I've change my /usr/local/bin/flush2disk script code to kick off a find background process early into the scripts execution, throwing that into the background before doing a few other things, and then wait for that background find to finish before invoking the scripts find tasks. Overall that makes the script run a bit faster the first time its run. As part of that I've added a spinner to indicate that its working during the find process. Code now looks like the following :

Code: Select all

#!/bin/bash
#
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#Barry Kauler www.puppylinux.com
#Edited for 'porteus-boot' on Debiandog for the "save on exit" boot option, by fredx181
#2016-02-26 Change; Line 89 "--remove-destination" instead of "-f", workaround possible crashing when 
#              copying files from upgraded libc6
#2016-07-19 fredx181 make save 'on demand' (to directory) work also with live-boot (originally idea from
#              Toni (saintless) https://github.com/MintPup/DebianDog-Wheezy/commit/9d510cd0189be4bdfe8ead97 ).
#2016-07-22 fredx181 parse location of live folder more exact (works now on DebianDog also)
#2016-07-29 Rufwoof - renamed to avoid confusion from save2flash to flush2disk and changed to specifically
#              run on persistence persistence-read-only pure Debian Live CD frugal
#2016-07-30 Rufwoof changed the BASE grep to pick up just the first line (partition) [added -m 1 parameter]
#2016-08-08 fredx181 changed: do the copying by 'rsync' instead of 'cp'
#              rsync does a better job, will skip copying files that are earlier copied to BASE by this script,
#              so much faster then, also it will 'flush' the memory space (tmpfs) in SNAP to (almost) how it was
#              at startup (see last code block). 
#2016-10-05 Rufwoof - changed to launch find as early as possible as for first run that slows things down
#              Also added spinner that's shown whilst waiting for that pre-find to finish
################################################################################################################

spinner()
{
    local pid=$1
    local delay=0.25
    local spinstr='|/-\'
    while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
        local temp=${spinstr#?}
        printf " [%c]  " "$spinstr"
        local spinstr=$temp${spinstr%"$temp"}
        sleep $delay
        printf "\b\b\b\b\b\b"
    done
    printf "    \b\b\b\b"
}


if [ "`whoami`" != "root" ]; then
	exec sudo ${0}
fi


export LANG=C #110206 Dougal: I **think** this should not cause problems with filenames
PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R7/bin"


# Debian LiveCD defaults to use a partition with a label of persistence or a partition
# with a label that matches the perisistence-label= kernel boot parameter (menu.lst)
LABEL=`cat /proc/cmdline | grep persistence-label`
if [ -z "$LABEL" ]; then
 	LABEL="persistence"
else
 	LABEL=`cat /proc/cmdline | awk 'BEGIN{FS="persistence-label="} {print $2}' | awk 'BEGIN{FS=" "} {print $1}'`
fi
BASE=`mount -l | grep "\[$LABEL\]" | grep -m 1 /lib/live/mount/persistence | awk 'BEGIN{FS=" "} {print $3}'`
if [ -z "$BASE" ]; then
 	echo -----------------------------------------------------
 	echo Only valid when booted a Read Only session and when 
 	echo persistence-label boot parameter specified - exiting
 	echo -----------------------------------------------------
 	sleep 4
 	exit
fi


# Remount the 'home' partition read-write, otherwise we can't copy the changes
mount -o remount,rw $BASE 2> /dev/null


# help speed up find by pre-running as early as possible
find $BASE/. >/dev/null &
PID=$!      # record pid of background find


dialog --backtitle "Are you sure you want to flush all changes to disk?" --yesno " Save " 5 20
if test $? -ne 0
then
	exit
fi
clear


#dialog --backtitle "Should I leave existing network and graphics values?" --yesno " Save " 5 20
#if test $? -ne 0
#then
#	rm -f /etc/udev/rules.d/70-persistent*
#	rm -f /home/user/.config/autostart/LXRandR*
#	rm -f /etc/X11/xorg.conf
#fi
#clear


# fredx181 mod, create variable for list containing files to save (to be used further below).
FILESAVELIST="/tmp/filesave$RANDOM"


# By default overlay is mounted twice (in case no persistence), unmounting it, sort of 'releases' it, not sure why but it works ;)
# On DebianDog it's different, but doing the below does not harm  
umount /lib/live/mount/overlay 2> /dev/null


# Rufwoof append root to path
SNAP="/lib/live/mount/overlay/root/"
if [ ! -d /lib/live/mount/overlay/root ]
then
	echo "Looks like you're running a continual save session"
 	echo "Invalid operation. Exiting"
 	sleep 5
 	exit 
fi


# create BASE directory if not exist
mkdir $BASE 2> /dev/null
cd $SNAP || exit 1
echo "Merging $SNAP onto $BASE..."
if [ -f /mnt/live/tmp/modules ]; then
 	SFSPoints=$( ls -d -1 /mnt/live/memory/images/* |sort -u ) #110206 Dougal: get a list of the sfs mountpoints
else
 	# live-boot v3 or v4
 	SFSPoints=$( ls -d -1 /lib/live/mount/rootfs/* |sort -u ) #110206 Dougal: get a list of the sfs mountpoints
fi


# Wait for early launched find to finish, showing a spinner whilst waiting
echo -n "Scanning ..."
spinner ${PID}
#wait $PID # wait until background updatedb finishes
echo
echo "Updating ..."


#Handle Whiteouts...
find . -mount \( -regex '.*/\.wh\.[^/]*' -type f \) | sed -e 's/\.\///;s/\.wh\.//' |
while read N
do
 	BN="`basename "$N"`"
 	DN="`dirname "$N"`"
 	[ "$BN" = ".wh.aufs" ] && continue #w003 aufs has file .wh..wh.aufs in /initrd/pup_rw.
 	#[ "$DN" = "." ] && continue
 	#110212 unionfs and early aufs: '.wh.__dir_opaque' marks ignore all contents in lower layers...
 	if [ "$BN" = "__dir_opaque" ];then #w003
  		#'.wh.__dir_opaque' marks ignore all contents in lower layers...
  		rm -rf "${BASE}/${DN}" 2>/dev/null #wipe anything in save layer. 110212 delete entire dir.
  		mkdir -p "${BASE}/${DN}" #jemimah: files sometimes mysteriously reappear if you don't delete and recreate the directory, aufs bug? 111229 rerwin: need -p, may have to create parent dir.
  		#also need to save the whiteout file to block all lower layers (may be readonly)...
  		touch "${BASE}/${DN}/.wh.__dir_opaque" 2>/dev/null
  		rm -f "$SNAP/$DN/.wh.__dir_opaque" #should force aufs layer "reval".
  		continue
 	fi
 	#110212 recent aufs: .wh.__dir_opaque name changed to .wh..wh..opq ...
 	if [ "$BN" = ".wh..opq" ] ; then
  		rm -rf "${BASE}/${DN}" 2>/dev/null  #wipe anything in save layer.
  		mkdir -p "${BASE}/${DN}" #jemimah: files sometimes mysteriously reappear if you don't delete and recreate the directory, aufs bug? 111229 rerwin: need -p, may have to create parent dir.
  		#also need to save the whiteout file to block all lower layers (may be readonly)...
  		touch "${BASE}/${DN}/.wh..wh..opq" 2>/dev/null 
  		rm -f "$SNAP/$DN/.wh..wh..opq"  #should force aufs layer "reval".
  		continue
 	fi
 	#comes in here with the '.wh.' prefix stripped off, leaving actual filename...
 	rm -rf "$BASE/$N"
 	#if file exists on a lower layer, have to save the whiteout file...
 	#110206 Dougal: speedup and refine the search...
 	for P in $SFSPoints
 	do
   		if [ -e "$P/$N" ] ; then
     			[ ! -d "${BASE}/${DN}" ] && mkdir -p "${BASE}/${DN}"
     			touch "${BASE}/${DN}/.wh.${BN}"
     			break
   		fi
 	done #110206 End Dougal.
done


#Directories... v409 remove '^var'. w003 remove aufs .wh. dirs.
#w003 /dev/.udev also needs to be screened out... 100820 added var/tmp #110222 shinobar: remove all /dev
find . -mount -type d | busybox tail +2 | sed -e 's/\.\///' | grep -v -E '^mnt|^initrd|^proc|^sys|^tmp|^root/tmp|^\.wh\.|/\.wh\.|^dev/|^run|^var/run/udev|^run/udev|^var/tmp|^etc/blkid-cache' |
#110224 BK revert, leave save of /dev in for now, just take out some subdirs... 110503 added dev/snd
#find . -mount -type d | busybox tail +2 | sed -e 's/\.\///' | grep -v -E '^mnt|^initrd|^proc|^sys|^tmp|^root/tmp|^\.wh\.|/\.wh\.|^dev/\.|^dev/fd|^dev/pts|^dev/shm|^dev/snd|^var/tmp' |
while read N
do
 	mkdir -p "$BASE/$N"
 	# I think nathan advised this, to handle non-root user:
 	chmod "$BASE/$N" --reference="$N"
 	OWNER="`stat --format=%U "$N"`"
 	chown $OWNER "$BASE/$N"
 	GRP="`stat --format=%G "$N"`"
 	chgrp $GRP "$BASE/$N"
 	touch "$BASE/$N" --reference="$N"
done


#Copy Files... v409 remove '^var'. w003 screen out some /dev files. 100222 shinobar: more exclusions. 100422 added ^root/ftpd. 100429 modify 'trash' exclusion. 100820 added var/tmp #110222 shinobar: remove all /dev
find . -mount -not \( -regex '.*/\.wh\.[^/]*' -type f \) -not -type d |  sed -e 's/\.\///' | grep -v -E '^mnt|^initrd|^proc|^sys|^tmp|^pup_|^zdrv_|^root/tmp|_zdrv_|^dev/|^\.wh\.|^run|^var/run/udev|^run/udev|^root/ftpd|^var/tmp' | grep -v -E -i '\.thumbnails|\.trash|trash/|^etc/blkid-cache|\.part$'  |
#110224 BK: revert, leave save of /dev in for now... 120103 rerwin: add .XLOADED
#find . -mount -not \( -regex '.*/\.wh\.[^/]*' -type f \) -not -type d |  sed -e 's/\.\///' | grep -v -E '^mnt|^initrd|^proc|^sys|^tmp|^run|^pup_|^zdrv_|^root/tmp|_zdrv_|^dev/\.|^dev/fd|^dev/pts|^dev/shm|^\.wh\.|^var/run|^root/ftpd|^var/tmp|\.XLOADED$' | grep -v -E -i '\.thumbnails|\.trash|trash/|\.part$'  |
while read N
do
 	[ -L "$BASE/$N" ] && rm -f "$BASE/$N"
 	# Finally, copy files unconditionally.
 	# fredx181 mod, no, don't use 'cp' just create filelist (for to save) here and run rsync later. 
 	#cp -a --remove-destination "$N" "$BASE/$N"
 	echo "$N" >> "$FILESAVELIST"
 	BN="`basename "$N"`" #111229 rerwin: bugfix for jemimah code (110212).
 	DN="`dirname "$N"`" #111229  "
 	[ -e "$BASE/$DN/.wh.${BN}" ] && rm "$BASE/$DN/.wh.${BN}" #110212 jemimah bugfix - I/O errors if you don't do this
done


# fredx181 mod, rsync copy from $FILESAVELIST
[ -f "$FILESAVELIST" ] && rsync -a --files-from=$FILESAVELIST "$SNAP" "$BASE"


# Remove files, corresponding with .wh files, from zchanges.dir
# Taken from 'cleanup' script included in the official Porteus initrd.xz 
MNAME="$BASE"; NAME="basename "$MNAME""
find $MNAME -name ".wh.*" 2>/dev/null | while IFS= read -r NAME; do wh=`echo "$NAME" | sed -e 's^$MNAME^^g' -e 's/.wh.//g'`; test -e "$wh" && rm -rf "$NAME"; done


# fredx181 mod, remount BASE and remove the just copied files from SNAP. 
if [ -f "$FILESAVELIST" ]; then
 	# remount BASE 
 	mount -no remount,add:1:"$BASE"=ro+wh aufs /
 	REMOVE=$(echo $(cat "$FILESAVELIST" | grep -v '\->'))
 	cd "$SNAP"
 	# remove files from SNAP that had just been copied to BASE 
 	rm -fr $REMOVE
 	rm -f "$FILESAVELIST"
else
 	echo "No changes found, nothing to do!"
fi

sync &
echo Done
sleep 1

exit 0

###END###
fundamentally that's the only additional non Debian script ... i.e. that enables a frugal read only booted session to have the changes recorded in memory be flushed to disk (made persistent across reboots).

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#22 Post by rufwoof »

Most of the time I boot frugal read-only (that has the option to make changes persistent), without saving, so that I boot the exact same system time after time. The exception being that I periodically check for updates and save those.

If you create a sym link to the persistent layer then you can have some folders or programs that are persistent even when booted read only and no save being performed.

For example I have a Documents-Persistent folder in my home folder, so any files created in that folder persist across reboots. I also have my Osmo (calender/diary) folder as a sym link to the persistent layer.
Attachments
s.jpg
(10.92 KiB) Downloaded 356 times

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#23 Post by backi »

Seems you`re leading some lonely public monologues . :)

https://www.youtube.com/watch?v=TZup5YLOWLE

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#24 Post by rufwoof »

Indeed.

Decided to close the thread.

User avatar
rufwoof
Posts: 3690
Joined: Mon 24 Feb 2014, 17:47

#25 Post by rufwoof »

THREAD CLOSED

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#26 Post by s243a »

rufwoof wrote:THREAD CLOSED
Why is the tbread closed?

belham2
Posts: 1715
Joined: Mon 15 Aug 2016, 22:47

#27 Post by belham2 »

s243a wrote:
rufwoof wrote:THREAD CLOSED
Why is the tbread closed?

An artiste', in whatever endeavor in life, cannot work in the silence of the cave without some sort of feedback. From someone. From anyone. Anyone that is other than our German jackal Backi screeching, hooting and driving the artiste' looney.

If you're a fan of this particular bit/thread of said artiste's work, it's a little late to be chiming in and wondering what's going on. Show some love, and concern other than wondering why an artist decided to shutdown a particular painting.

The artiste' always comes back, especially when they got mad skills like rufwoof does. Some day, we will all see the Picaso instead of backi's attempt to make us see & laugh at a lonely, chagrined Linux painter. Shame on you, backi----the icon above says it all

s243a
Posts: 2580
Joined: Tue 02 Sep 2014, 04:48
Contact:

#28 Post by s243a »

belham2 wrote: If you're a fan of this particular bit/thread of said artiste's work, it's a little late to be chiming in and wondering what's going on. Show some love, and concern other than wondering why an artist decided to shutdown a particular painting.

The artiste' always comes back, especially when they got mad skills like rufwoof does. Some day, we will all see the Picaso instead of backi's attempt to make us see & laugh at a lonely, chagrined Linux painter. Shame on you, backi----the icon above says it all
I haven't had the opportunity to try it but if it is good then others should have the opportunity to comment. If rufwoof lost interest in this thread than perhaps someone else might comment.

The intro to this thread looks interesting though. I see sections related to the section of the wiki called, "how puppy works". I certainly will come back to at least read the first post of this thread.

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#29 Post by backi »

Hi ruf !
I hope i did not hurt or ridicule you in some way .
Just felt sorry for you and wanted to express my deep adoration for your lonesome genius ,just wanted give you some entertainment ...which is all i can share .
Found your situation somehow a bit tragic .
Although i don`t understand everything what your doing ,your knowledge is quite amazing ........maybe if your dead and gone ......people will realize which nuggets you did dig out of the dirt ,just to present them to an ignorant mankind .
Maybe later generation will recognize the impact of your work and writings .......( meant somehow kidding ... somehow meant really serious )

Keep the faith my friend :) :) :)
Last edited by backi on Sun 16 Oct 2016, 08:00, edited 1 time in total.

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#30 Post by backi »

Another question ......
where is fredx181 .........when rufwoof and we need him ( so bad ) ?

belham2
Posts: 1715
Joined: Mon 15 Aug 2016, 22:47

#31 Post by belham2 »

backi wrote:Hi ruf !
I hope i did not hurt or ridicule you in some way .
Just felt sorry for you and wanted to express my deep adoration for your lonesome genius ,just wanted give you some entertainment ...which is all i can share .
Found your situation somehow a bit tragic .
Although i don`t understand everything what your doing ,your knowledge is quite amazing ........maybe if your dead and gone ......people will realize which nuggets you did dig out of the dirt ,just to present them to an ignorant mankind .
Maybe later generation will recognize the impact of your work and writings .......( meant somehow kidding ... somehow meant really serious )

Keep the faith my friend :) :) :)
LOL, Backi, you are incorrigible!....deutsch-word, if I remember right: unverbesserlich!! or is it "unkündbar"? No more hefeweisens for two months for you :D :lol:

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#32 Post by fredx181 »

backi wrote:Another question ......
where is fredx181 .........when rufwoof and we need him ( so bad ) ?
I'm Here :)

(been busy with new DD for the last few weeks)

Fred

backi
Posts: 1922
Joined: Sun 27 Feb 2011, 22:00
Location: GERMANY

#33 Post by backi »

Hi fred !

Uuffff.......that will ease my pain .

Hi belham2 !
Sentenced to two long months without some weed ????
I hope your just kidding ! :D :D :D

Lord have mercy !!!

Post Reply