https://github.com/wagoodman/tar-overlay
A shell script which creates and manages named overlayfs mounts backed by the contents from tar files.
https://github.com/wagoodman/tar-overlay
containers overlayfs systemd-nspawn tar
Last synced: about 1 year ago
JSON representation
A shell script which creates and manages named overlayfs mounts backed by the contents from tar files.
- Host: GitHub
- URL: https://github.com/wagoodman/tar-overlay
- Owner: wagoodman
- Created: 2016-01-22T17:50:12.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-07-06T15:58:37.000Z (almost 10 years ago)
- Last Synced: 2025-04-11T00:42:50.368Z (about 1 year ago)
- Topics: containers, overlayfs, systemd-nspawn, tar
- Language: Shell
- Homepage:
- Size: 9.77 KB
- Stars: 19
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tar-Overlay
A shell script which creates and manages named overlayfs mounts backed by the contents from tar files.
Note: this is a work in progress, so it is not stable yet.
## Example
Given a tar with a set of files, create two independent scratch 'instances' where you can add, modify,
and delete files that can be reverted on command:
1) install a tar, this becomes an immutable 'image':
```
[wagoodman@vm1 ~]$ tar-overlay install-image ~/Downloads/msgpack-python-0.4.6.tar.gz
[wagoodman@vm1 ~]$ tar-overlay list-images
msgpack-python-0.4.6
```
2) create a few instances and mount them:
```
[wagoodman@vm1 ~]$ tar-overlay create-overlay foo msgpack-python-0.4.6
[wagoodman@vm1 ~]$ tar-overlay create-overlay bar msgpack-python-0.4.6
[wagoodman@vm1 ~]$ tar-overlay list-overlays
scratch1
scratch2
[wagoodman@vm1 ~]$ tar-overlay mount-overlay foo
~/bin/tar-overlay/store/instances/foo/rootfs
[wagoodman@vm1 ~]$ tar-overlay mount-overlay bar
~/bin/tar-overlay/store/instances/bar/rootfs
```
Note: the output for each mount attempt is where the instance mountpoint is.
3) Make some changes in one of the instances (foo):
```
[wagoodman@vm1 ~]$ tree -L 1 ~/bin/tar-overlay/store/instances/foo/rootfs
~/bin/tar-overlay/store/instances/foo/rootfs
├── COPYING
├── msgpack
├── PKG-INFO
├── README.rst
├── setup.py
└── test
2 directories, 4 files
[wagoodman@vm1 ~]$ rm -rf ~/bin/tar-overlay/store/instances/foo/rootfs/test
```
Notice that we can query which files have changed:
```
[wagoodman@vm1 ~]$ tar-overlay show-changes foo
.
└── test
├── test_buffer.py
├── test_case.py
├── test_except.py
├── test_extension.py
├── test_format.py
├── test_limits.py
├── test_newspec.py
├── test_obj.py
├── test_pack.py
├── test_read_size.py
├── test_seq.py
├── test_sequnpack.py
├── test_subtype.py
├── test_unpack.py
└── test_unpack_raw.py
1 directories, 15 files
```
Also notice that the other instance (bar) still has the original file:
```
[wagoodman@vm1 ~]$ tree -L 1 ~/bin/tar-overlay/store/instances/bar/rootfs
~/bin/tar-overlay/store/instances/bar/rootfs
├── COPYING
├── msgpack
├── PKG-INFO
├── README.rst
├── setup.py
└── test
2 directories, 4 files
[wagoodman@vm1 ~]$ rm -rf ~/bin/tar-overlay/store/instances/bar/rootfs/test
```
(See, the 'test' dir is still there)
4) Restore the 'foo' instance back to the original contents from the tar:
```
[wagoodman@vm1 ~]$ tar-overlay reset-overlay foo
[wagoodman@vm1 ~]$ tree -L 1 ~/bin/tar-overlay/store/instances/foo/rootfs
~/bin/tar-overlay/store/instances/foo/rootfs
├── COPYING
├── msgpack
├── PKG-INFO
├── README.rst
├── setup.py
└── test
2 directories, 4 files
```
# Motivation
The motivation for this was to take a read-only directory tree and make several
read-write 'instances' of that directory tree, where changes made in each instance would
not affect files in the other instances. Furthermore, there were benefits with
having the functionality to restore any instance to the original directory tree,
as if no modifications were done. This could all be done by making copies of the
tar contents for each instance, however, some of these directory trees were 1 GB
or more in size and only a few files are modified between all of the instances.
Docker provides almost the same functionality via dockerfiles, however, I am
not using docker for this project... so building and managing images this way seemed
awkward if I wasn't planning to use docker for containers. Instead, since overlayfs
has been integrated into the kernel and a wrapper script seemed simple enough to
make, tar-overlay was born!
# Usage
```
tar-overlay [command] [options]
Image commands:
install-image Take the given tar and make it available as in immutable image.
list-images List all known images.
Overlay Commands:
create Instantiate an image (make an instance).
list List image instantiations.
mount Mount an instantiation for use.
mount-all Mount all overlays.
info Show all information regardin the given overlay name.
rename Rename the given instantiation.
reset Undo all changes made to original image.
show-changes Show a tree of all modified files
status Shows if the given overlay is mounted.
umount Unmount an instantiation.
umount-all Unmount all overlays.
Future Commands:
rename-image Rename the given image.
delete-image Delete the given image.
mount-image Mounts an image directly (not advised).
umount-image Unmounts a directly mounted image.
delete Delete the given instantiation.
```