MojoDB Partition Resize

Introduction
If you use your webOS device frequently, you have probably encountered the "Application database full" error, and were confused by it. It is a very confusing error, and the remedies are equally confusing. The error suggests deleting data, but it isn't clear what data. I learned that it meant app data (such as emails, contacts, calendar events), and not media. Though, the amount of files that you have on your USB partition can play a factor, too. Unfortunately, the tricks to get this error to go away are very few and short-lived. As a result, you will be greeted with the next evil error. That error will force you to reset your device. In this process, you are required to sign back into your Palm profile and watch in horror as all of your apps re-download, all of your Preware apps gone, as if you got the device new.... Nasty.

Well, there is a solution (and no, I won't be trying to sell you some anti-aging cream, or miracle spray, so rest assured, I have tried this on my own Pre3).

The Dirty Bits
webOS 2.0 came along and offered a new application data storage feature. It allowed you to store data in a database called db8. It is pretty magical, and allows apps to share data through permissions. But, this feature had one fatal flaw. It was placed on its own isolated partition. This is a great way to protect the data, to some extent, but it limits how much data you can have on your device. The partition is only 135MB in size... You can use that quickly if you have a ton of files on your USB partition (the media indexer uses this database to store the index of the files on the USB partition), a few email accounts syncing regularly and storing a large backlog, and Koto Player indexing your media... This partition is /var/db... We will resize it.

FAIR WARNING
I have seen people on the webOSNation forums recommend deleting large text files from the /var/db partition that do not have a ".db" extension. DO NOT (let me repeat that DO NOT) delete these files. They are database journal files. A journal is a small record of entries written to a database or filesystem that a data management system can look to in the event that it is abruptly and uncleanly shutdown. It allows the device to "replay" transactions (so to speak) if you, say, were to pull the battery because the device seemed frozen. Deleting these files can put the journal and database out of sync, and the results of that are pretty messy and require a few hours of patient database cleanup....

Pre-Operation Warnings
As should always be noted, there is always a chance that something could go HORRIBLY wrong. As a result, I provide absolutely NO warranty of any kind. You are on your own. As always, backup your data (using whatever process makes you feel the most secure, whether it is just copying off a few beloved photos, or doing a full mem dump).

I have only tested this on webOS 2.2.4 on a Pre3. It should work on any webOS 2.0+ device (likely including a TouchPad). If you do this on some other type of device, please report back!

Let's Go!
Basically, what you will do is shave some space off of your /media/internal partition, and hand that over to the application database. I went safe and did about 500MB for mine. "Memory is cheap", so why not? I'll give you the commands below.

You can check your current usage with this command:

df -h

I recommend getting your current usage (-h means "human"), then subtract about 512MB from it and use that number below when shrinking the media partition (My media partition was about 12.8G, so I just made it 12.2G, which gives me about 600MB available, and I enlarged my mojodb partition by 512MB, so I'll have a few MB leftover, which is fine since you may have to grow /var later on). Make sure that you have enough room to shrink your media partition! I recommend backing it up, and deleting anything to clear space if you need to.


 * 1) Shrink the media partition

pkill -SIGUSR1 cryptofs
 * 1) Need to stop the cryptofs process, or rather "pause" it

umount /media/internal
 * 1) Unmount the /media/internal partition

resizefat -v /dev/mapper/store-media 12.2G
 * 1) Shrink the partition (Replace 12.2G with the amount of space you want to reduce to. I think that the partition is 12.8 by default?)

lvreduce -L 12.2G /dev/mapper/store-media
 * 1) Reduce the logical volume (make the "physical" disk smaller) 12.2G is the **SAME** number as above.

mount /media/internal
 * 1) Remount

pkill -SIGUSR2 cryptofs
 * 1) Restart the cryptofs service


 * 1) Increase the Application Database

/sbin/stop mojodb
 * 1) Stop the MojoDB service

umount /dev/mapper/store-cryptodb
 * 1) Unmount the filesystem

lvextend -L 512M /dev/mapper/store-mojodb
 * 1) Extend the file system up

cryptsetup resize /dev/mapper/store-cryptodb
 * 1) Extend the encrypted size up

resize2fs -f -p /dev/mapper/store-cryptodb
 * 1) Resize the underlying filesystem

mount /dev/mapper/store-cryptodb
 * 1) Remount

/sbin/start mojodb
 * 1) Restart the service

It might be worth rebooting here, too. df -h should show that you have a roughly 512MB /var/db. The application database error should be in your past. :) The only time you may experience a serious error about the application database is if it happens to become corrupt...

I got an error :(
You might encounter errors, so here are some work-arounds.

umount: can't umount /media/internal: Device or resource busy
Run the following command:

ps -lf -p $(fuser -c /media/internal 2>/dev/null)

You will get output that looks like:

F S UID       PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY        TIME CMD 5 S root      998     1  0  80   0 -  3041 fuse_d 20:03 ? 0:18 cryptofs -o nonempty -o allow_other -s -r /media/internal/.palm /medi 4 S luna     1368     1  0  80   0 - 14577 poll_s 20:04 ? 0:01 /usr/bin/BrowserServer
 * 1) ps -lf  -p $(fuser -c /media/internal 2>/dev/null)

It looks like BrowserServer is stopping us... Let's stop it!

Use the following command:

stop browserserver

Then re-try the unmount command above. When done, execute this command to start the BrowserServer:

start browserserver

Future Looking
My goal is to add this feature to Tailor. What I really am considering is setting up the partition like /media/cryptofs. If you notice, it shares the same size attributes as /media/internal. That is because they are the same partition! /media/cryptofs is actually a special cryptofs partition ontop of /media/internal. I would think that one could do this to /var/db, too. This would give one the most flexibility over application installation, data storage, and media space.