[solved] Porteus Persistent Script

Non release banter
Michele13
Black ninja
Black ninja
Posts: 60
Joined: 18 Aug 2013, 10:23
Distribution: Based on Debian and Slackware
Location: Italy

[solved] Porteus Persistent Script

Post#1 by Michele13 » 04 Oct 2013, 22:16

Please can you past me here the script that porteus uses to make itself persistent?

I have an Idea to make any linux distro persistent but I don't know how to achieve this.
This script should mount a loop file with a posix file system in /mnt/changes
and then all the changes made to the system... in porteus these changes are stored in /mnt/live/changes if I'm not wrong. I've tried to learn how it does from the init script inside the initrd but I can't understand it! :unknown: is there a way to make such persistent script?
Last edited by Michele13 on 02 Jan 2015, 12:28, edited 1 time in total.

User avatar
francois
Contributor
Contributor
Posts: 6434
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus nemesis
Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.

Re: Porteus Persistent Script

Post#2 by francois » 04 Oct 2013, 22:36

Welcome Michele. :)

Where do you want to install porteus, on a usb or on the hard disk drive of your computer? Have you already burned a porteus cd? If on your computer, do you already have some linux partition already or only a window system? Installing porteus is better onto linux partitions, but it is also possible on windows partition (fat, ntfs).

To keep the changes to the desktop modification all you need is to put a command called cheatcode on the bootloader instructions. The cheatcode is changes=.

If you install porteus with a porteus burned iso, the porteus installer (on a usb key formated with linux file system, ext2 or ext3) will configure the bootloader to save the changes as a standard option:
http://www.porteus.org/tutorials/37-ins ... .html#Hard Drive
Porteus allows users to save their changes (i.e., system settings, downloaded files, bookmarks, browser history, etc) to a folder or image file (aka container) that exists outside of Porteus' core files. The 'changes=' cheatcode parameter sets the location for these changes. When you start Porteus with this cheatcode (enabled by default for USB installations), it will boot up the operating system and then apply your changes from this location. By default, Porteus is set to save these changes to /porteus/changes


Here is an example of some bootloader instructions modified with the change cheatcode. Here the bootloader is syslinux. The instruction are in
/boot/syslinux/porteus.cfg. Cited from:
http://www.porteus.org/tutorials/37-ins ... .html#Hard Drive

Code: Select all

LABEL xconf
MENU LABEL Graphics mode (KDE).
KERNEL vmlinuz
APPEND initrd=initrd.xz changes=/porteus/
TEXT HELP
Run Porteus the best way we can.
Try to autoconfigure graphics
card and use the maximum
allowed resolution
ENDTEXT

LABEL lxde
MENU LABEL Graphics mode (LXDE).
KERNEL vmlinuz
APPEND initrd=initrd.xz lxde changes=/porteus/
TEXT HELP
Run Porteus the same as above.
Lightweight LXDE to be
launched as default desktop
ENDTEX
T

More instructions on installing porteus:
http://www.porteus.org/tutorials/37-ins ... uicknDirty

Do not hesitate to ask more questions.
Prendre son temps, profiter de celui qui passe.

Michele13
Black ninja
Black ninja
Posts: 60
Joined: 18 Aug 2013, 10:23
Distribution: Based on Debian and Slackware
Location: Italy

Re: Porteus Persistent Script

Post#3 by Michele13 » 05 Oct 2013, 07:00

I know how changes works, I was wondering how to achieve the same result on a distro that doesn't have a persistent feature :) i was asking for a script capable to do that

User avatar
ralcocer
Samurai
Samurai
Posts: 187
Joined: 02 Jan 2011, 12:53
Distribution: 3.2rc5 Xfce
Location: Puerto Rico
Contact:

Re: Porteus Persistent Script

Post#4 by ralcocer » 05 Oct 2013, 11:37

Check in the /mnt/live linuxrc # Setup changes: for the code.

Michele13
Black ninja
Black ninja
Posts: 60
Joined: 18 Aug 2013, 10:23
Distribution: Based on Debian and Slackware
Location: Italy

Re: Porteus Persistent Script

Post#5 by Michele13 » 05 Oct 2013, 16:53

ralcocer wrote:Check in the /mnt/live linuxrc # Setup changes: for the code.

Code: Select all

# Setup changes:
if [ $CHANGES ]; then
    echo $i"setting up directory for changes"
    CHNEXIT=`echo $CHANGES | cut -d: -f1`; [ $CHNEXIT = EXIT ] && CHANGES=`echo $CHANGES | cut -d: -f2-`
    locate -r $CHANGES
    if [ $? -eq 0 ]; then
	if [ -d /mnt/$DEV/$LPTH ]; then
	    mkdir -p /mnt/$DEV/$LPTH/changes 2>/dev/null && \
	    mount -o bind /mnt/$DEV/$LPTH/changes /memory/changes && touch /memory/changes/._test1 2>/dev/null
	else
	    if blkid /mnt/$DEV/$LPTH 2>/dev/null | cut -d" " -f3- | grep -q _LUKS; then
		for x in dm_crypt cryptd cbc sha256_generic aes_generic aes_x86_64; do modprobe $x 2>/dev/null; done
		losetup /dev/loop2 /mnt/$DEV/$LPTH
		echo $i"found encrypted .dat container"
		/opt/000-kernel/sbin/cryptsetup luksOpen /dev/loop2 crypt
		fsck_dat /dev/mapper/crypt
		mount /dev/mapper/crypt /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
	    else
		fsck_dat /mnt/$DEV/$LPTH
		mount -o loop /mnt/$DEV/$LPTH /memory/changes 2>/dev/null && touch /memory/changes/._test1 2>/dev/null
	    fi
	fi
	if [ $? -eq 0 ]; then
	    echo $i"testing filesystem on "$CHANGES" for posix compatibility"
	    ln -s /memory/changes/._test1 /memory/changes/._test2 2>/dev/null && chmod +x /memory/changes/._test1 2>/dev/null && [ -x /memory/changes/._test1 ] && chmod -x /memory/changes/._test1 2>/dev/null && [ ! -x /memory/changes/._test1 ] && rm -f /memory/changes/._test1 /memory/changes/._test2
	    if [ $? -ne 0 ]; then
		rm -f /memory/changes/._test1 /memory/changes/._test2; umount /memory/changes
		echo && echo -e "[1;33m""A Windows filesystem (FAT, NTFS) or other non-posix compatible filesystem\nhas been detected on $CHANGES.\nYour changes cannot be saved directly to the specified storage media with this\nsetup. Please use the '[1;36mPorteus save file manager[1;33m' to create a .dat container\nand use it for saving your changes after your next reboot.""[0m"
		echo "press enter to continue in '[1;36mAlways Fresh[0m' mode for this session"
		read; rmdir /mnt/$DEV/$LPTH/changes; fail_chn
	    else
		echo $i"filesystem is posix compatible"; CHNDEV=/mnt/$DEV
		rmdir /memory/changes/mnt/* 2>/dev/null
		rm -f /memory/changes/var/lock/subsys/* /var/run/laptop-mode-tools/*
		for x in `find /memory/changes/var/run -name "*pid" 2>/dev/null`; do rm $x; done
		if [ $CHNEXIT = EXIT ]; then
		    CHNEXIT=$CHNDEV/$LPTH; echo $CHNEXIT >/tmp/changes-exit
		    echo $i"[1;36m""changes will be saved only during reboot/shutdown""[0m"
		    for x in `find /memory/changes -name ".wh.*"`; do cp -a --parents $x /var; done
		    umount /memory/changes; mount -nt tmpfs -o size=$RAMSIZE tmpfs /memory/changes
		    # need to fix busybox bug on 'cp -a' as it does not preserve perms on dirs:
		    chown -R 1000:1000 /var/memory/changes/home/guest 2>/dev/null
		    mv /var/memory/changes/* /memory/changes 2>/dev/null; CHANGES=memory
		fi
	    fi
	else
	    echo $i"changes not writable, using memory instead"; umount /memory/changes 2>/dev/null; fail_chn
	fi
    else
	fail $CHANGES; fail_chn
    fi
else
     echo $i"changes cheatcode not found, using memory only"; fail_chn
fi

mkdir -p /memory/changes/mnt/live
There's the code, I've tried to understand it but I can't...I don't know wich line does what, can you help me to understand it? :%) Thanks In advance :)

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: Porteus Persistent Script

Post#6 by brokenman » 05 Oct 2013, 17:57

Please inspect the script /opt/porteus-scripts/save-changes or save-session which was designed for this purpose. Keep in mind that you should only run this script after booting into 'always fresh mode'.
How do i become super user?
Wear your underpants on the outside and put on a cape.

Michele13
Black ninja
Black ninja
Posts: 60
Joined: 18 Aug 2013, 10:23
Distribution: Based on Debian and Slackware
Location: Italy

Re: Porteus Persistent Script

Post#7 by Michele13 » 07 Oct 2013, 15:34

How do you do to make all the differences inside the root directories to go to /mnt/live/memory/changes?
Eg if I create a file called "file.txt" in the desktop of the guest user, this file is also copied to /mnt/live/memory/changes/home/guest/Desktop
How can I achieve this on another distro?

User avatar
fanthom
Moderator Team
Moderator Team
Posts: 5666
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland
Contact:

Re: Porteus Persistent Script

Post#8 by fanthom » 07 Oct 2013, 16:25

@Michele13

porteus uses aufs for persistence purpose but you could also use unionfs or overlayfs (never tried them myself). please read aufs man page:
http://aufs.sourceforge.net/aufs2/man.html
and aufs mailing list:
http://sourceforge.net/mailarchive/foru ... aufs-users
to find how to use aufs.

i'm sorry but i wont be able to explain every line from linuxrc (huge task). you should understand the main concept first (merge several aufs branches under one /union directory by using initrd) and then learn shell language to study our linuxrc.
after that you should be able to achieve what you want.
Please add [Solved] to your thread title if the solution was found.

Post Reply