[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Here is a place for your projects which are not officially supported by the Porteus Team. For example: your own kernel patched with extra features; desktops not included in the standard ISO like Gnome; base modules that are different than the standard ISO, etc...
fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#1 by fulalas » 26 Oct 2021, 10:33

If you don't use rootcopy, this topic is probably not for you.

***Background***

This issue was raised one year ago here. But because we haven't pushed the change into official Porteus, I'm going to provide a way to fix this for those who are interested.

***Explanation***

For those who, like me, use rootcopy in FAT/NTFS units (for restoring volatile files during boot) you may end up with wrong permissions in some system folders, which may break some applications, like VirtualBox:
https://www.mediafire.com/view/vgca2wu5 ... before.png

This is a limitation in the original /boot/syslinux/initrd.xz. Here's the code of the relevant part:

Code: Select all

if param norootcopy; then
    ROOTCOPY=none
    echo $i"skipping /rootcopy directory"
else
    if [ $ROOTCOPY ]; then
	locate -d $ROOTCOPY
	if [ $? -eq 0 ]; then echo $i"copying content of $ROOTCOPY directory"; cp -af /mnt/$DEV/$LPTH/. /union/. 2>/dev/null; else fail $ROOTCOPY; ROOTCOPY=none; fi
    else
	ROOTCOPY=none
	echo $i"copying content of $PTH/rootcopy directory"
	cp -af $PTH/rootcopy/. /union/. 2>/dev/null
    fi
fi
***Sugestion***

With this change we can make sure that when rootcopy is in a POSIX file system (i.e. not FAT/NTFS) it will restore the original permissions (just like original Porteus), however if rootcopy in a NON-POSIX file system (FAT/NTFS) it will not change the destination folders/files permissions if they already exist in the system, and it will give drwxr-xr-x/-rwxr-xr-x permission for those that don't exist in the system:

Code: Select all

if param norootcopy; then
    ROOTCOPY=none
    echo $i"skipping /rootcopy directory"
else
	FILESYSTEM=$(cat /etc/fstab | grep -o /mnt/$DEV.* | cut -f2- -d' ' | cut -f1 -d' ')
	if [ $FILESYSTEM = "ntfs" ] || [ $FILESYSTEM = "vfat" ]; then
		ISPOSIX=0
		COPYPARAMS="-rf"
	else
		ISPOSIX=1
		COPYPARAMS="-af"
	fi
	if [ $ROOTCOPY ]; then
		locate -d $ROOTCOPY
		if [ $? -eq 0 ]; then echo $i"copying content of $ROOTCOPY directory"; cp $COPYPARAMS /mnt/$DEV/$LPTH/. /union/. 2>/dev/null; else fail $ROOTCOPY; ROOTCOPY=none; fi
	else
		ROOTCOPY=none
		echo $i"copying content of $PTH/rootcopy directory"
		cp $COPYPARAMS $PTH/rootcopy/. /union/. 2>/dev/null
	fi
	if [ $ISPOSIX -eq 0 ]; then chown -R guest /union/home/guest 2>/dev/null; fi
fi
We can achieve this:
https://www.mediafire.com/view/hyifwcea ... /after.png

***Fixing***

1- Make a backup of /boot/syslinux/initrd.xz
2- Copy the new initrd.xz, reboot and be happy :)

https://www.mediafire.com/file/l70qmmat ... /initrd.xz

User avatar
M. Eerie
Moderator
Moderator
Posts: 620
Joined: 31 Aug 2017, 21:18
Distribution: Nemesis Xfce/MATE x64

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#2 by M. Eerie » 26 Oct 2021, 13:25

Thanks, fulalas

Will give it a try.

:)
> Does not compute_ 🖖

https://forum.porteus.org/viewtopic.php?p=94310#p94310
https://forum.porteus.org/viewtopic.php?p=84002#p84002
https://forum.porteus.org/viewtopic.php?p=77174#p77174
https://forum.porteus.org/viewtopic.php?f=39&t=8584

User avatar
babam
Warlord
Warlord
Posts: 526
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 5.0rc3 Xfce K6.1.1
Location: Rainy city

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#3 by babam » 28 Oct 2021, 10:24

What about for files and directories located in /etc or /usr?

Because some files and directories located in /etc or /usr require special permissions.
Sorry, my English is bad.

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#4 by fulalas » 28 Oct 2021, 11:52

It's not going to change any permission in the file system, including folder and files, period.

For the folders/files in rootcopy that don't exist in the system it will give drwxr-xr-x/-rwxr-xr-x permission, which is the default one. In the rare cases of folders/files in rootcopy that don't exist in the system and that require other permission, well there's nothing we can do since this information is lost in FAT/NTFS partitions. At least we are:
1- not breaking the system when restoring rootcopy files;
2- increasing the chances that everything will work as expected;

User avatar
babam
Warlord
Warlord
Posts: 526
Joined: 16 Nov 2016, 10:30
Distribution: Porteus 5.0rc3 Xfce K6.1.1
Location: Rainy city

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#5 by babam » 28 Oct 2021, 12:25

Because there are some files located under /etc that must be owned by "root" and must have certain permissions (-rw-r-----)
Sorry, my English is bad.

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#6 by fulalas » 28 Oct 2021, 12:28

@babam, if the file/folder in rootcopy already exists in the system, this new initrd won't change the permission. If the file/folder doesn't exist in the system, it will give drwxr-xr-x/-rwxr-xr-x permission. That's the best we can do given the fact that FAT/NTFS partitions don't keep permissions.

In the case of a file in a FAT/NTFS rootcopy that doesn't exist in the system AND that requires -rw-r----- it won't work. But that's the current behavior of official Porteus anyway. The idea here is not to make magic, it's just to do our best to not break stuff.

I updated the original post to make it clear.

Thanks!

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#7 by Ed_P » 28 Oct 2021, 16:15

fulalas, what is the difference between the rootcopy, which I have never used, and extramod, which is what I use for modules on NTFS drives, cheatcodes?? I boot ISOs and add .xzm modules all the time for changes and function and I have always used the extramod cheatcode.
Ed

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#8 by ncmprhnsbl » 29 Oct 2021, 01:27

Ed_P wrote:
28 Oct 2021, 16:15
what is the difference between the rootcopy, which I have never used, and extramod,
the simplest description i can think of would be "a readonly changes folder" that you construct manually yourself (same fakeroot way as a module, but not compressed)
.. in that it's copied over the root (/) at boot (and you can manually make changes to it that won't be picked till next boot)
if you're booting isos it's not really available unless you bake it into the iso.. which pretty much defeats the purpose (the convenience of instant access(no decompress/compress or loopmount steps)
whereas a module is loop mounted(AUFS style) and no issues with the filesystem type it's stored on.
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

fulalas
DEV Team
DEV Team
Posts: 2050
Joined: 26 Oct 2016, 15:34
Distribution: Porteus
Location: Brazil

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#9 by fulalas » 29 Oct 2021, 01:34

Modules are somehow static, while with rootcopy you can store files that keep changing, like browser history, audio playlist, current torrents, etc.

In my case, wifi password is inside a module because it doesn't change, but my browser history is inside rootcopy because it changes every time -- I use rc.shutdown script to update.

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#10 by ncmprhnsbl » 29 Oct 2021, 01:36

ncmprhnsbl wrote:
29 Oct 2021, 01:27
and you can manually make changes to it that won't be picked till next boot)
or like fulalas says, use some sort of script to update it..
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#11 by Ed_P » 29 Oct 2021, 04:23

Thank you guys, I understand it better now. Rootcopy is for files on .ext4 file systems.

With changes I want to keep I run a script that makes a module of them. Another option I've used to save changes is to copy my save.dat file to a new file and name it as an .xzm file.
Ed

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#12 by ncmprhnsbl » 29 Oct 2021, 12:37

another thing worth mentioning is the cheatcode : rootcopy=/path/to/rootcopy
which allows you to use a rootcopy folder on a different partition or drive..
a scenario would be that you partition your usb with a first large ntfs or fat32(where the boot/efi/porteus and data you want available to window and other devices) and a second smaller ext partition where rootcopy and/or even a changes folder would go..
benefits being: no permissions issues and that partition would not be visible to windows and other devices.

another way is to partition that way but put just boot/efi folders on the first and all of porteus folder on the second(perhaps bigger) partition.
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

User avatar
Ed_P
Contributor
Contributor
Posts: 8341
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.01 ISO
Location: Western NY, USA

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#13 by Ed_P » 29 Oct 2021, 15:02

ncmprhnsbl wrote:
29 Oct 2021, 12:37
another thing worth mentioning is the cheatcode : rootcopy=/path/to/rootcopy
I thought that was what this whole thread is about. :hmmm:

Will future ISO's be built with fulalas's initrd.xz in them? Should Porteus testers boot their ISOs with it?
Ed

Kulle
Warlord
Warlord
Posts: 594
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#14 by Kulle » 29 Oct 2021, 18:54

Hi fulalas,
does this also apply to Porteus 4.0?
When I unzip initrd, it creates a lot of folders and some files.
where is the code to be changed?

Kulle
Warlord
Warlord
Posts: 594
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

[TUTORIAL] Allowing safe rootocopy on FAT/NTFS

Post#15 by Kulle » 29 Oct 2021, 19:07

In my Porteus 4.0 initrd.xz: 804.8 KB
The new initrd.xz on mediafire: 764.48 KB
Hence my question above

Post Reply