trynd / wren

Linux boot platform that provides a portable, multi-system, run-in-memory Linux environment.
GNU General Public License v3.0
0 stars 1 forks source link

Replace LVM with Btrfs #12

Closed codewithmichael closed 9 years ago

codewithmichael commented 9 years ago

Addressed Issues:

This pull request addresses issue #10 (Investigate ZFS and Btrfs) by fully replacing LVM with Btrfs and reintegrating snapshot functionality into Wren.

With these changes, Wren now boots using a Btrfs subvolume to store in-memory active save data. All supporting scripts have been updated to accommodate the change, maintaining their existing functionality with the exception of snapshots being re-enabled in save.sh.

All references to LVM functionality have been removed from the code base and the watershed and lvm2 package dependencies have been removed. However, LVM-related platform variables have been maintained with DEPRECATED headers in the platform.conf file to (temporarily) continue support of booting custom save instances based on version 0.1.x.

Documentation has been updated to reflect the change.

Notes:

Update Instructions:

codewithmichael commented 9 years ago

Update instructions should be included in README.md.

codewithmichael commented 9 years ago

There are some interesting differences with Btrfs. I'm using Wren GUI to monitor active space usage and changes.

codewithmichael commented 9 years ago

I updated the mount options for the active Btrfs volume. New options are as follows:

commit=5,notreelog,nobarrier,flushoncommit

These are in addition to the default options rw,noatime,loop.

flushoncommit ensures all dirty file data is flushed to disk (or memory in this case) when a transaction is committed and should be the default on modern kernels, but it doesn't hurt to manually specify it to be safe.

codewithmichael commented 9 years ago

A sync is now performed after taking the snapshot just to ensure the B-tree and associated metadata are up to date before copying to disk. This should automatically happen when the snapshot is created, but (as previously mentioned) it's a comprehensive measure to ensure the user can see how much space is actually used.

codewithmichael commented 9 years ago

So I experimented a bit with compression (mount option: compress=X). zlib provides the best compression, but it's slower than lzo, which I think is the better default.

I think this would be a great feature to add, as it leaves more available RAM for either extending the save size or just for general usage. However, it does create an issue with reporting, as df and du typically measure the actual disk usage, and monitoring applications like Wren GUI may incorrectly report the actual size of the file as they relate to the purpose of saving.

To get around that, the following command appears to provide the actual file sizes (in bytes), or at least a close approximation so long as both filesystems are using a 4K block size:

du -xa -B1 -d0 /mnt/wren/04-save | cut -f1

If we get Wren GUI updated with that command before releasing a Btrfs distro things should work out ok without confusing anyone.

Side Note: It's probably best to move the active volume mount options into platform.conf. That would allow users to disable compression or set/unset any other preferred Btrfs mount options without needing to perform a custom image build.

codewithmichael commented 9 years ago

I updated the Wren GUI project with some alternate wording on the labels and added an extra section to display "Uncompressed active data (if saved to disk)". That should suffice for now. If we go forward with Btrfs I'll release that as a follow up (since there are no other pending issues on Wren GUI at the moment).

codewithmichael commented 9 years ago

I added Btrfs compression (lzo) and moved the active volume mount options into platform.conf.

codewithmichael commented 9 years ago

Rebased for v0.1.2.

codewithmichael commented 9 years ago

This PR is already changing almost every file and requires testing every system, so I'm going to go ahead and add in issue #8 (Move to /opt/wren), as it only requires changing default_prefix=/etc to default_prefix=/opt in wrender (thanks to PR #19).

So noted in the PR's "Addressed Issues".

codewithmichael commented 9 years ago

In a fairly sweeping change to accommodate #8 (Move to /opt/wren), I've reorganized most of the source tree and updated setlist to copy installed package files into a more standard hierarchical tree — i.e. bin for executables, lib for libraries, and etc for configuration files. I left the tools directory separate, as those utilities aren't truly part of Wren as much as they're just quick ways to accomplish non-wren tasks.

codewithmichael commented 9 years ago

I updated initramfs-script to use getDiskUsage instead of getFileSize when determining the size of the save file. This addresses issue #22 (Incorrect active data capacity at startup).

To accomplish this, I also updated initramfs-hooks to copy_exec du in place of stat, since getDiskUsage uses du and there were no other references to stat or getFileSize in initramfs-script.

Note: save.sh already correctly used getDiskUsage to determine calculation sizes.

codewithmichael commented 9 years ago

I removed increase-save-size.sh script and made the active volume increase native to the wren control script. I added additional functionality to allow a specified number of bytes to increase by, to check whether the increase is necessary, and to determine if there is enough free memory to safely expand. There is a --force override option for when the action is not considered "safe".

Examples - Check:

user@computer:~$ sudo wren +active --check
Necessary:  No
Safe:       Yes
user@computer:~$ sudo wren +active --check -v
Resize Tolerance:     512.0M (536870912)
Active Free:          780.2M (818167808)
Memory Free:            2.5G (2778513408)
Memory Unallocated:     1.8G (1960345600)
Requested Increase:     1.0G (1073741824)
Necessary:                No
Safe:                    Yes

Example - Increase by 512MB:

user@computer:~$ sudo wren +active $((1024*1024*512)) -v
Resize Tolerance:     512.0M (536870912)
Active Free:            1.2G (1354698752)
Memory Free:            2.4G (2645508096)
Memory Unallocated:     1.2G (1290809344)
Requested Increase:   512.0M (536870912)
Necessary:                No
Safe:                    Yes
Increasing active storage capacity
codewithmichael commented 9 years ago

I added a crontab (/copy/config/cron/increase-active-capacity --> /etc/cron.d/increase-active-capacity) to check the active volume size and available memory every 30 seconds and increase the active capacity when "necessary" and "safe".

Technically, two entries were created to run once per minute. The second one is prefixed with a sleep 30 command to delay it.

This change addresses issue #23 (Cron job to increase active data capacity).

codewithmichael commented 9 years ago

All important issues seem to have been addressed and everything has tested well so far. I think this is ready to go.

codewithmichael commented 9 years ago

Merged into release-0.2.0 branch for testing.

codewithmichael commented 9 years ago

I'm thinking the wren control script should also have basic memory and usage stats in the status command like it does for the +active one. Since this has been merged, though, I'll open a new pull request based on the release-0.2.0 branch.