[HOWTO] Magic Folders

Post tutorials, HOWTO's and other useful resources here.
User avatar
King of Docs
King of Docs
Posts: 1331
Joined: 28 Dec 2010, 15:18
Distribution: LXDE & Xfce 32/64-bit
Location: USA

[HOWTO] Magic Folders

Post#1 by Ahau » 18 Feb 2011, 17:10

As of version 1, Porteus comes with a feature called "Magic Folders", which was borrowed from falcony's FIDOSlax project. Many thanks to falcony, and to fanthom, for implementing this in Porteus!

See this thread for more background information: Magic Folders&new way saving data, automatic swap files

The short explanation is that magic folders will allow you to save changes that you make to a particular folder in your live filesystem to a particular folder (or .dat image file) on a hard disk, USB flash drive, or other media.

For example, if you do not want all of your persistent changes saved to the same place (e.g. save.dat), you can save save your changes to /root to root.dat and changes to /guest to guest.dat. Or, you can create a file on your flash drive that will save files to the same location across multiple users or installs (more on that later).

To begin using magic folders, you need to run the script from the command line. Open a console, and enter 'magic_folders'. The script will tell you about magic folders, and then prompt you for a folder in your live filesystem. For example, /home/guest/Downloads.

It will then prompt you for a location on a real device, where the changes will be saved. For example, /mnt/sdb1/Downloadsave.dat. If this file (or in this example, container) does not exist, the script will create one for you, at the size of your choosing. If you are saving changes to a FAT or NTFS filesystem, it is suggested that you use a .dat file container to avoid file corruption.

Once you've selected (or created) your destination, the script creates a configuration file in your rootcopy directory, at /porteus/rootcopy/etc/magic_folders/folders.cfg. This file is a list of paired folders, and you can edit it directly (or use the script again) to create more magic folders.

Upon reboot, your system will pair the folders, and changes in one location will show up in the other. Using my example above, any time I save something to my /home/guest/Downloads directory, it will also be saved to the Downloadsave.dat container on my flash drive, at /mnt/sdb1.

*NOTE* Changes saved to magic folders will survive reboot, even in 'Always Fresh' mode. Thus, I suggest we should have a new cheatcode, 'nomagic', so that someone can boot into 'Always Fresh' mode in the event something in a magic folder is corrupted or causes bootup failure.

Now, for a real example of one implementation I've come up with for myself:

I want a folder on my desktop, where I can save and access files directly, without navigating through a bunch of subdirectories. I want this to be accessible for both my 'root' and 'guest' users.

I created the following directories in my /porteus/rootcopy file:

This puts a folder on my desktop, within my live filesystem.

I then created a directory at the root of my flash drive and called it 'magic' as well:
cd /mnt/sdb1
mkdir magic

I then ran the magic_folders script, specifying /home/guest/Desktop/magic as my source location, and /mnt/sdb1/magic as my destination. This created the text file in /rootcopy/etc/magic_folders/folders.cfg, which I then edited to include the second linked file for my /root/Desktop folder. This is my folders.cfg file:

Code: Select all

/mnt/sdb1/magic /home/guest/Desktop/magic
/mnt/sdb1/magic /root/Desktop/magic
Upon reboot, the folders get linked together. If I log in as guest and put something in my 'magic' folder on the desktop, I can reboot as root, and access the same file that I put there earlier (as 'guest') by clicking on the 'magic' folder on root's desktop. I can also access this file from windows, by navigating to E:\magic. Note that I do not have 3 copies of these files on my flash drive. These files are only stored permanently on my pendrive, at /mnt/live/sdb1/magic, and are synced from there into the live filesystem at startup.

(yes, I know that I am not following my own advice to store my files to a .dat container when using a FAT filesystem. In this case, I am only storing documents and not system configuration files.)

This begins to demonstrate the flexibility of the magic folders system--I'd love for anyone else to post examples of how they are using them.

Thanks, and enjoy!

One final note: If you are using a flash drive and it is not mounted automatically at /mnt/sdXN at startup, try using the cheatcode 'delay=2' at boot time. This worked for me.
Please take a look at our online documentation, here. Suggestions are welcome!

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

Re: [HOWTO] Magic Folders

Post#2 by brokenman » 21 Feb 2011, 00:46

Excellent ... some people will wonder what the magic folders are about and will find this very useful.
How do i become super user?
Wear your underpants on the outside and put on a cape.

Post Reply