-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
129 lines (83 loc) · 4.01 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
lxc-snap: lxc container snapshot management tool
BACKGROUND
Lxc supports containers backed by overlayfs snapshots. The way this is
typically done is to create a container backed by a regular directory,
then create a new container which mounts the first container's rootfs
as a read-only lower mount, with a new private delta directory as
its read-write upper mount. For instance, you could
sudo lxc-create -t ubuntu -n r0 # create a normal directory
sudo lxc-clone -B overlayfs -s r0 o1 # create overlayfs clone
The second container, o1, when started up will mount /var/lib/lxc/o1/delta0
as a writeably overlay on top of /var/lib/lxc/r0/rootfs, and use that as its
root filesystem.
From here you can clone o1 to a new container o2. This simply copies the
the overlayfs delta from o1 to o2, and you is done with
sudo lxc-clone -s o1 o2
LXC-SNAP
One of the obvious use cases of these snapshot clones is to support
incremental development of rootfs images. Make some changes, snapshot,
make some more changes, snapshot, revert...
lxc-snap is a small program using the lxc API to more easily support
this use case. You begin with a overlayfs backed container, make some
changes, snapshot, make some changes, snapshot... This is a simpler
model than manually using clone because you continue developing the same
container, o1, while the snapshots are kept away until you need them.
EXAMPLE
Create your first container
sudo lxc-create -t ubuntu -n base
sudo lxc-clone -s -B overlayfs base mysql
Now make initial customizations, and snapshot:
sudo lxc-snap mysql
This will create a snapshot container /var/lib/lxc/snapshots/mysql_0. You can actually
start it up if you like using 'sudo lxc-start -P /var/lib/snapshots -n mysql_0'.
(However, that is not recommended, as it will cause changes in the rootfs)
Next, make some more changes. Write a comment about the changes you made in this
version,
echo "Initial definition of table doomahicky" > /tmp/comment
sudo lxc-snap -c /tmp/comment mysql
Do this a few times. Now you realize you lost something you needed. You can
see the list of containers which have snapshots using
lxc-snap -l
and the list of versions of container mysql using
lxc-snap -l mysql
Note that it shows you the time when the snapshot was created, and any comments
you logged with the snapshot. You see that what you wanted was version 2, so
recover that snapshot. You can destroy container mysql and restore version 2
to it, or (I would recommend) use a different name to restore the snapshot to.
Use a different name with:
sudo lxc-snap -r mysql_2 mysql_tmp
or destroy mysql and restore the snapshot to it using
sudo lxc-destroy -n mysql
sudo lxc-snap -r mysql_2 mysql
When you'd like to export a container, you can clone it back to a directory
backed container and tar it up:
sudo lxc-clone -B dir mysql mysql_ship
sudo tar zcf /srv/mysql_ship.tar.gz /var/lib/lxc/mysql_ship
BUILD AND INSTALL
To use lxc-snap, you currently need to be using lxc from the ubuntu-lxc
daily ppa. On an ubuntu system (at least 12.04) you can
sudo add-apt-repository ppa:ubuntu-lxc/daily
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install lxc-dev
lxc-snap will either become a part of the lxc package, or will become a
separate package. Currently it is available at
git://github.com/hallyn/lxc-snap. Fetch it using:
git clone git://github.com/hallyn/lxc-snap
Then build lxc-snap by typing 'make'.
cd lxc-snap
make
Install into /usr/bin by typing
sudo DESTDIR=/usr make install
or install into /home/$USER/bin by typing
mkdir /home/$USER/bin
DESTDIR=/home/$USER make install
Note that lxc-snap is in very early development, and its usage may
change over time. Using a package (as soon as it becomes available)
is recommended.
NOTES ON OVERLAYFS
Overlayfs appears to have a limit of 10G. This can be limiting
depending on the rootfs which you are developing.
NOTES ON LVM
LVM does not support snapshots of snapshots. Therefore when restoring a
LVM snapshot, it is restored using a copy clone, which copies the whole