Skip to content

Instantly share code, notes, and snippets.

@intrnl
Last active October 12, 2023 15:05
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save intrnl/27d710196d2bc9fe3ca19f6a9349899b to your computer and use it in GitHub Desktop.
Save intrnl/27d710196d2bc9fe3ca19f6a9349899b to your computer and use it in GitHub Desktop.
A guide to make Phantasy Star Online 2: New Genesis run faster on Linux.

PSO2 on Linux casefolding guide

Note
This guide is primarily written for the Global Steam version of the game, however it should also apply more or less the same with other versions like Global EGS version, and also Japanese version as well.

Proton-GE includes a patch which allows you to not do any of this, however, I'd still recommend following this guide over using Proton-GE as it's proven to be more reliable so far, and also applicable to any other games.

I do not hold any liability for what happens if you mess up, be warned.
I would recommend reading through the entire guide first even if certain parts may not apply to you.

PSO2 has a unique structure where each assets are contained in their own tiny files, mostly ranging around 3-4 KiB in size, and would even try to load assets that may potentially exist (nb. it doesn't), in turn this adds quite the considerable overhead for Wine to try to load these files off disk.

Most filesystems are designed with case sensitivity in mind, this means that the file foo is not the same as FOO, they are two separate files despite having the same name just with a different casing. However, this isn't the case for Windows. While NTFS does support case sensitivity, it is optional, and not used by Windows for legacy DOS compatibility reasons.

This means that Wine has to support case insensitivity within a case sensitive filesystem, it does this by traversing each directory in a provided path starting from the root directory, this is done everytime it needs to access a file.

There is one way however, and that's to store the game installation on a casefold-enabled partition.

Filesystems supporting the casefolding feature enables these use-cases of not having to care about case-sensitivity, while still allowing files and directories to retain their original casing. It's the most viable solution for achieving Windows compatibility as of now.

Getting a casefold-enabled partition

If you are running a Steam Deck, it should be noted that SD cards formatted to ext4 via Deck's interface will have casefold enabled, so if you are planning to install this game on that storage medium, feel free to skip this part. (this does not seem to apply to Deck's internal storage for some reason)

Make sure that you are running an up-to-date version of the Linux kernel, this is currently only supported by two filesystems:

  • ext4 requires Linux 5.2 and up
  • F2FS requires Linux 5.4 and up

You can try running this command to make sure that your kernel supports it:

# `ext4` or `f2fs`
$ cat /sys/fs/f2fs/features/casefold 
supported

There are three options you can take from here:

Format or create a new partition

If you're intending to create a new partition instead of using an existing partition to reformat, do note that tools like GParted might not allow you to configure formatting options like casefold, in that case, you can format it to any filesystem and then reformat it again with the commands below.

Next, find the partition you want to format using lsblk, and then format the partition using the commands below, making sure to prepend /dev/ (e.g. /dev/sda9)

# for ext4
$ sudo mkfs.ext4 -O casefold -E encoding_flags=strict /dev/sda9

# for F2FS
$ sudo mkfs.f2fs -O casefold -C utf8:strict /dev/sda9

Creating a loop device

This method is untested, if you don't want to create a new partition or reformat an existing partition for this, you do have the option of creating a loop device on your existing partition, and have that loop device formatted with ext4/F2FS with casefold. Note that this is very likely to be slower than running the game on an actual partition, but it's worth a shot.

# I'd recommend creating the image somewhere accessible, like directly on the / directory

# We will create an empty image
# Make sure to give around 130 GB+ of size
$ sudo truncate -s 130G pso2.img

# Format the image, here we use ext4 as example
$ sudo mkfs.ext4 -O casefold -E encoding_flags=strict pso2.img

# Make sure that root owns the image
$ sudo chown root:root pso2.img
$ sudo chmod 600 pso2.img

# Create an empty folder where the image should be mounted
$ sudo mkdir /opt/pso2
$ sudo mount -t ext4 -o loop {path}/pso2.img /opt/pso2

# Give everyone read-write access to the mounted directory
$ sudo chmod 777 /opt/pso2

The reason why we're making this available on root is so that we can have it automatically mount our images on boot, and to do that, add the following to /etc/fstab

{path}/pso2.img      /opt/pso2            ext4    loop            0 0

Be sure to reboot just in case.

Reconfiguring an existing partition

This is only applicable for ext4 partitions, using tune2fs you can skip having to reformat or create a new partition. You'd need to unmount the partition first, so do boot into a live USB if you are attempting to reconfigure your root partition.

$ sudo tune2fs -O casefold /dev/sda9

Now you can mount the partition, and add it as a Steam library.

I haven't installed the game

If you haven't installed the game, you might want to create the game install folder ahead of time so you don't have to do the steps below, it saves a bit of time.

# $STEAM_LIBRARY_FOLDER is the path to your added Steam library
# By default, this is on ~/.local/share/Steam/steamapps
~$ cd $STEAM_LIBRARY_FOLDER/common

# Create the folder, and mark it as casefolded
common$ mkdir -p PHANTASYSTARONLINE2_NA_STEAM
common$ chattr +F PHANTASYSTARONLINE2_NA_STEAM

# Be sure to check again that the folders have the `F` (casefolding) attribute
common$ lsattr
-----------I-----FN--- ./PHANTASYSTARONLINE2_NA_STEAM

I've already installed the game

If you are trying to follow this guide for another game, be sure to substitute the installation folders meant for PSO2 NGS with the game you're intending to apply this on.

After installing PSO2, we need to make sure that the game installation folder is marked as case insensitive, this is required as directories are still case-sensitive by default, it has to be opted-in. You can check this by seeing if the F attribute is present in the pso2_bin and any of its child directories.

# If `F` is present then you are good to go!
PHANTASYSTARONLINE2_NA_STEAM$ lsattr
-----------I-----FN--- ./pso2_bin

PHANTASYSTARONLINE2_NA_STEAM$ lsattr pso2_bin/
# Command output truncated for brevity
-----------I-----FN--- ./pso2_bin/data
-----------I-----FN--- ./pso2_bin/GameGuard

PHANTASYSTARONLINE2_NA_STEAM$ lsattr pso2_bin/data/
# So on, and so forth

If not, here's what you can do:

  1. Rename the pso2_bin directory to a temporary name (e.g tmp)
  2. Now make a new pso2_bin folder, and mark it as case insensitive
    $ chattr +F pso2_bin/
  3. As folders retains their attributes, we want to manually recreate the folder structure that inherits the case insensitivity attribute, you can run this find command inside the temporary directory to recreate it
    $ cd tmp/
    $ find . -type d -exec mkdir -p ../pso2_bin/{} \;
  4. Now you would want to move all the files from the temporary directory to the new one, in this case I just did a drag and drop from a file manager.
  5. Double check that all child directories still has their case-insensitivity attribute using the lsattr shown above.
  6. You might also want to do this for other directories like its Wine prefix folder, but as for Wine prefix folder specifically it should already be taken care of.

Note that we can't just run chattr +F on the existing directory is because the F attribute can only be applied to empty directories, it can't be applied on a directory that is currently filled with files. I would also point out that I do not recommend making the entire Steam library folder as case insensitive, only do it per-game as needed.

After that, boot up the game and see how fast it can run!

On my machine, with a 1 TB Samsung 980 NVMe drive, the initial loading time from character selection to Kvaris Camp now takes 13 seconds, down from 48 seconds. (bfq scheduler)

@intrnl
Copy link
Author

intrnl commented Jun 26, 2022

You may notice that the format commands have strict option, that's for strict case-folding and it is recommended that you keep it.

@intrnl
Copy link
Author

intrnl commented Jun 28, 2022

Updated the guide as ext4 casefold can be toggled on via tune2fs without having to reformat

@intrnl
Copy link
Author

intrnl commented Oct 26, 2022

Updated the guide to mention Proton-GE, however I'd still recommend following this guide over using Proton-GE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment