How do I symbollically link 2 directories between 2 SD cards?


Hồng Thất Công

Đả Cẩu Bổng Pháp
Joined
Dec 19, 2012
Messages
4,386
Location
Cái Bang
OK.  Please help me with following:

  1. On SD card #1, I have a rom directory for PS1 games in /media/psd1/appdata/pcsx_rearmed/roms.  This SD card has reached its maximum capacity.
  2. On SD card #2, I also have a rom directory for PS1 games in /media/psd2/games/ps1 as the first card is filled up.
  3. How do I symbollically link these 2 directories between 2 SD cards to allow PCSX-ReArmed to see and run all the games in just one directory?
  4. Would be nice to have this automatically done when PCSX-ReArmed is launched and I don't have to use the terminal every time.
Thanks,

Shenmue

Edit: Forgot to mention that my SD cards are ext4.
 
Last edited by a moderator:
You cannot link two directories "together" (unless you're talking about something like UnionFS), that's not how symbolic links work. What you can do, is put all your roms in a directory on your second SD card and add a symlink to that from your first SD card, e.g. (assuming all your roms are in /media/psd2/games/ps1)


ln -s /media/psd2/games/ps1 /media/psd1/appdata/pcsx_rearmed/roms
Of course that only works if /media/psd1 is a filesystem that supports symlinks (e.g. ext{2,3,4}, but not FAT). The link will be persistent, but of course if its target (on your second SD card) is not available, it will be a broken link.

But I guess this is not really what you want. If you don't have enough space on either of the SD cards, so you really have to spread the roms over the two cards, there are two options.

Option 1: make a subdirectory in your main rom directory to point to the other SD card. That way you don't get all your roms in one directory, but at least it does not take a lot of effort to navigate to the other directory.


ln -s /media/psd2/games/ps1 /media/psd1/appdata/pcsx_rearmed/roms/others
Option 2: make links for each game on the second SD card. That way you get to see all roms in one directory. The downside is that you need to maintain the links when you add or remove roms from the second SD card.

Code:
ln -s -t /media/psd1/appdata/pcsx_rearmed/roms /media/psd2/games/ps1/*
 
You can't link two directories like that, not even on ext. What you need is a union mount.

Code:
sudo mount -t aufs dirs="/media/SDCARD1/ps1_path":"/media/SDCARD2/ps1_path" none "/media/SDCARD2/combined_path"
where /media/SDCARD1/ps1_path is the first PS1 location, /media/SDCARD2/ps1_path is the second location (duh), and /media/SDCARD2/combined_path is a third directory that you must create where you want the combined games to appear.
 
^^ ok, already answered (mostly), I'll post my reply anyway:


You could do


# mkdir -p ~/psx/games
# cd $_
# ln -s /media/psd1/appdata/pcsx_rearmed/roms/* .
# ln -s /media/psd2/games/ps1/* .

and select that directory (/home/shenmue/psx/games, if your user is called shenmue) in PCSX.

However, you would have to re-run these commands each time you've added a game, and if you deleted one, the symlink would become stale (point to non-existing file).


What you probably want aren't symlinks, but a union filesystem (aufs).

Open a shell and type


# mkdir /media/psd1/appdata/pcsx_rearmed/all_roms
# sudo mount -t aufs -o br=/media/psd1/appdata/pcsx_rearmed/roms:/media/psd2/games/ps1/ none /media/psd1/appdata/pcsx_rearmed/all_roms


The 'all_roms' directory should now contain all games located in both directories.


Be aware that the mounted union fs disappears when you remove (one of) the SDCards.

I am not sure what the proper way is to make this permament, there's probably a script that is run when an sdcard is inserted/removed, you could hook your mount script into that, I guess.

The added script lines would look like this:


PSX_UNIONDIR=/home/shenmue/psx/games/
PSX_DIR1=/media/psd1/appdata/pcsx_rearmed/roms
PSX_DIR2=/media/psd2/games/ps1/

if [ -z "`ls -1 ${PSX_UNIONDIR}`" ]; then
  mount -t aufs -o br=${PSX_DIR1}:${PSX_DIR2} none ${PSX_UNIONDIR}
else
  echo "already mounted"
fi
Question is: Which (system) script is run when an SDCard is inserted ?
 
You can't link two directories like that, not even on ext. What you need is a union mount.

sudo mount -t aufs dirs="/media/SDCARD1/ps1_path":"/media/SDCARD2/ps1_path" none "/media/SDCARD2/combined_path"where /media/SDCARD1/ps1_path is the first PS1 location, /media/SDCARD2/ps1_path is the second location (duh), and /media/SDCARD2/combined_path is a third directory that you must create where you want the combined games to appear.
How safe is that? I'm not up on the Linux UNIONFS, but I remember the *BSD implementation was somewhat risky, is the Linux one reliable?
 
Whoa!  Thanks for all the quick responses.  I'll give each a try.

Thanks a millions!

Additional question:  Would it be possible to implement  this UnionFS thing P2?  So, to users, it looks like you have 128GB of storage even though you have 2 separate cards.  Something like the PSP MS Pro Duo Dual Slot Adapter where you put in 2, say 32GB, microSDs but PSP recognizes it as 1 giant 64GB card?  <-- Very convenient if can be done on P2. :)
 
Last edited by a moderator:
You can't link two directories like that, not even on ext. What you need is a union mount.


sudo mount -t aufs dirs="/media/SDCARD1/ps1_path":"/media/SDCARD2/ps1_path" none "/media/SDCARD2/combined_path"
where /media/SDCARD1/ps1_path is the first PS1 location, /media/SDCARD2/ps1_path is the second location (duh), and /media/SDCARD2/combined_path is a third directory that you must create where you want the combined games to appear.
How safe is that? I'm not up on the Linux UNIONFS, but I remember the *BSD implementation was somewhat risky, is the Linux one reliable?
It's what is used to mount PNDs so the PND contents and the appdata dir get united. So I guess it's pretty reliable.
 
..and here's a ready-to-use set of scripts for ya.

the scripts set up the union fs each time an SD card is inserted, which is necessary since the union fs mount disappears when an SD card is removed.


Installation:

On your Pandora, type


# sudo tar xfz mmc_insert_script-17Nov2013.tar.gz -C /
this will add the following scripts:

/etc/udev/rules.d/mmc_script.rules:


KERNEL=="mmcblk[0-9]", SUBSYSTEMS=="mmc", ATTRS{name}=="?*", ATTRS{serial}=="?*", ENV{ID_NAME}="$attr{name}", ENV{ID_SERIAL}="$attr{serial}", OPTIONS+="last_rule", RUN+="/home/root/mmc_insert.sh"
/home/root/mmc_insert.sh:


#!/bin/bash

/home/root/mount_aufs.sh &
/home/root/mount_aufs.sh:


#!/bin/bash

AUFS_DIR1=/sd1/tmp/a
AUFS_DIR2=/sd1/tmp/b
AUFS_MOUNTPOINT=/sd1/tmp/u

#AUFS_DIR1=/media/psd1/appdata/pcsx_rearmed/roms
#AUFS_DIR2=/media/psd2/games/ps1/
#AUFS_MOUNTPOINT=/media/psd1/appdata/pcsx_rearmed/all_roms

mkdir -p "${AUFS_MOUNTPOINT}"

# Wait until filesystem is mounted
sleep 5

# mount read-only. for readwrite, remove "ro" option
/bin/mount -t aufs -o ro,br=${AUFS_DIR1}:${AUFS_DIR2} none ${AUFS_MOUNTPOINT}
You will want to change the AUFS_DIR1, AUFS_DIR2 and AUFS_MOUNTPOINT variables to match your filesystem layout (I already included those vars for Shenmue's system, just uncomment them).

p.s.: almost forgot one import detail: You have to restart your Pandora after installing the scripts!

mmc_insert_script-17Nov2013.tar.gz
 

Attachments

  • mmc_insert_script-17Nov2013.tar.gz
    633 bytes · Views: 133
Last edited by a moderator:
Can you explain a little more by what you mean by this?

"You will want to change the AUFS_DIR1, AUFS_DIR2 and AUFS_MOUNTPOINT variables to match your filesystem layout (I already included those vars for Shenmue's system, just uncomment them)."
 
Change the three lines so that they point to the correct directory path for your PSX roms.

These two are the paths to your disks:

AUFS_DIR1=/media/psd1/appdata/pcsx_rearmed/roms

AUFS_DIR2=/media/psd2/games/ps1/

And this one is the directory where they will appear altogether:

AUFS_MOUNTPOINT=/media/psd1/appdata/pcsx_rearmed/all_roms
 
There is already a boot.txt file used to configure boot.

Can't we improve bsp's scripts and include in the Pandora OS to search for some mount.txt file and create the union-fs?
 
OK.  Tried it but it didn't work.  Here what's I did:

In /home/root/mount_aufs.sh:


#!/bin/bash

AUFS_DIR1=/sd1/tmp/a
AUFS_DIR2=/sd1/tmp/b
AUFS_MOUNTPOINT=/sd1/tmp/u

AUFS_DIR1=/media/psd1/pandora/appdata/pcsx_rearmed/roms
AUFS_DIR2=/media/psd2/pandora/games/ps1/
AUFS_MOUNTPOINT=/media/psd1/appdata/pcsx_rearmed/all_roms

mkdir -p "${AUFS_MOUNTPOINT}"

# Wait until filesystem is mounted
sleep 5

# mount read-only. for readwrite, remove "ro" option
/bin/mount -t aufs -o ro,br=${AUFS_DIR1}:${AUFS_DIR2} none ${AUFS_MOUNTPOINT}

Where is that "all_roms" directory? Couldn't find it any where after restarting.
 
You create it.

Also I think bsp has it set up to run the script on mount, so simply removing and re-inserting the card should be enough, no need to reboot.
 
Last edited by a moderator:
Still doesn't work after creating a directory called "all_roms" in /media/psd1/appdata/pcsx_rearmed/ and reboot/re-inserted the cards.

Does it matter if the "roms" and "ps1" directories have sub-directories?  I have each ps1 game in a separate sub-directory.
 
The "all_roms" directory is created by this line:

mkdir -p "${AUFS_MOUNTPOINT}"

but I think I've spotted the problem: There's a typo in the pathname.

Instead of

AUFS_MOUNTPOINT=/media/psd1/appdata/pcsx_rearmed/all_roms

please use

AUFS_MOUNTPOINT=/media/psd1/pandora/appdata/pcsx_rearmed/all_roms


You only need to reboot once after installing the .tar.gz since /etc/init.d/udev does not support the 'restart' option.

Once the new udev rule (mmc_script.rules) is installed, no more restarts are needed (e.g. after modifying the other scripts).

And yep, WizardStan is correct, removing and re-inserting one of the cards should trigger a script re-run.
 
I noticed that too and fixed that as you can see in post #14.  But still doesn't work.  Looks like my post #16 and your post #17 crossed each other in cyber space.  Do you think that it could be the problem I stated in post #16?
 
Last edited by a moderator:
 I noticed that too and fixed that as you can see in post #14.  But still doesn't work.  Looks like my post #16 and your post #17 crossed each other in cyber space.  Do you think that it could be the problem I stated in post #16?
Does it matter if the "roms" and "ps1" directories have sub-directories?  I have each ps1 game in a separate sub-directory.
that does not matter (same here, one dir. per game).

I've just (re-)tested the scripts with two ROM directories located on different SD cards -- works fine here.

Did you install the mmc_insert_script-17Nov2013.tar.gz like I said ? (file permissions are important)

p.s.: previously I said that the mount disappears when an SD card is removed. That is not exactly true, it only happens when the mount point is placed on the removed SD card. 'unmount' does not work so I'd suggest to do that or you'll end up with duplicate mounts.
 
Last edited by a moderator:
Yes I did exactly what you've instructed.  I saw all the scripts in the proper directories but just no "all_roms" folder created anywhere.

My psd1 is max out so I don't know whether this is the problem as the 3 games on psd2 are totalled up more than 2GB.  Could this be the reason why "all_roms" couldn't get created on psd1?
 
Last edited by a moderator:
Back
Top