How to Rename Firefox's Profile Path
I have recently ran into issues trying to rename Firefox's profile path for synchronization and automation purposes. In this article I'm going to show you how to make it work.

TL;DR

Prerequisite: install mozlz4.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
cd ~/.mozilla/firefox

# the current profile directory's name and the target profile directory name
ORIGINAL_NAME='abcd0efg.default-release'
TARGET_NAME='k4yt3x'

# replace path name references in text files
mv "$ORIGINAL_NAME" "$TARGET_NAME"
sed -i "s/$ORIGINAL_NAME/$TARGET_NAME/g" installs.ini
sed -i "s/$ORIGINAL_NAME/$TARGET_NAME/g" profiles.ini
sed -i "s/$ORIGINAL_NAME/$TARGET_NAME/g" "$TARGET_NAME/pkcs11.txt"
sed -i "s/$ORIGINAL_NAME/$TARGET_NAME/g" "$TARGET_NAME/extensions.json"

# decompress the addonStartup.json, replace the strings, and re-compress
cd "$TARGET_NAME"
mozlz4 -x addonStartup.json.lz4 > addonStartup.json
sed -i "s/$ORIGINAL_NAME/$TARGET_NAME/g" addonStartup.json
mozlz4 -z addonStartup.json addonStartup.json.lz4
rm addonStartup.json

My Firefox is heavily customized with dozens of extensions and settings spread across multiple configuration files such as user.js and perf.js. It is, thus, not practical for me to migrate my Firefox profile to a machine while ensuring that all settings are synchronized and that it will behave exactly the same way if I were to rely on Firefox’s built-in Sync. The most reliable and efficient, albeit slightly “hacky” way, to migrate my Firefox profile to machine is, therefore, to straight up copy the entire profile to the new machine. There might be a more elegant way to do this, but until then, this will be the method I have to rely on. Additionally, this approach also makes it easy to reliably synchronize all of my few hundreds of tabs over to a different machine.

While I was synchronizing the profile, I noticed that Firefox made a default name and path for the profile. The profile name I got is a random string (yrdz6hff.default-release) generated based on how stars were aligned the day I created the profile. I’d rather not having to embed this random string in my automation scripts and etc., so I decided to look into changing it. This string is used both as the displayed profile name in Firefox and the name of the profile’s directory on the file system.

The profile’s name can be easily changed in the about:profiles page:

However, the same cannot be said about the profile’s directory name on the file system. On my Arch Linux system, Firefox’s profile is located under .mozilla/firefox/$PROFILE_NAME. If you simply rename the directory, Firefox will not be able to find the profile anymore and will simply make a new profile for you. Thus, we will need to change Firefox’s configurations so the profile-related configurations point to the right path.

In order to find out which files we need to change, we can use ripgrep to list all the files that contain the profile’s name under Firefox’s profiles directory. The following command lists all files that contain the profile name’s string, including binary files:

Let’s first rename the profile’s directory and then replace all occurrences of yrdz6hff.default-release in all text files. In this example, I’ll rename my profile directory’s name to k4yt3x:

Let’s try and start Firefox. Unfortunately, we’ll see that the extensions are broken:

The broken extensions and the fact that we did not change addonStartup.json.lz4 provides a pretty clear hint that this file may be causing the troubles. In fact, this file is, indeed, the culprit. We will need to update the content of this file as well. However, this file is compress in an uncommon format used by Firefox named mozlz4. It cannot be decompressed by Linux utilities such as lz4 or 7z.

In order to decompress and re-compress the addonStartup.json file, we will need a tool named mozlz4. This tool is available on AUR in the name of mozlz4 and mozlz4-bin. If your platform’s repository does not have it, you can download the compiled binaries on their GitHub releases page. After getting the tool, you can use the following commands to decompress the file, update its content, and re-compress the file:

Now, if we start Firefox again, we will see that all the extensions load correctly again:

There you have it. I hope this post would help whomever that also happens to need to do the same hacky thing. If you notice that something isn’t working after this modification or if there are other files that should be updated as well, please reach out and I’ll update this guide.


最后修改于 2024-08-28

- 目录 -