Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
616d626b
Commit
616d626b
authored
Jun 30, 2014
by
hallyn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #244 from xose/btrfs
lxc-ubuntu: use btrfs subvolumes and snapshots
parents
f2f54585
654bf1af
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
7 deletions
+46
-7
lxc-ubuntu.in
templates/lxc-ubuntu.in
+46
-7
No files found.
templates/lxc-ubuntu.in
View file @
616d626b
...
@@ -46,6 +46,37 @@ if [ -r /etc/default/lxc ]; then
...
@@ -46,6 +46,37 @@ if [ -r /etc/default/lxc ]; then
.
/etc/default/lxc
.
/etc/default/lxc
fi
fi
# Check if given path is in a btrfs partition
is_btrfs
()
{
[
-e
$1
-a
$(
stat
-f
-c
'%T'
$1
)
=
"btrfs"
]
}
# Check if given path is the root of a btrfs subvolume
is_btrfs_subvolume
()
{
[
-d
$1
-a
$(
stat
-f
-c
'%T'
$1
)
=
"btrfs"
-a
$(
stat
-c
'%i'
$1
)
-eq
256
]
}
try_mksubvolume
()
{
path
=
$1
[
-d
$path
]
&&
return
0
mkdir
-p
$(
dirname
$path
)
if
is_btrfs
$(
dirname
$path
)
;
then
btrfs subvolume create
$path
else
mkdir
-p
$path
fi
}
try_rmsubvolume
()
{
path
=
$1
[
-d
$path
]
||
return
0
if
is_btrfs_subvolume
$path
;
then
btrfs subvolume delete
$path
else
rm
-rf
$path
fi
}
configure_ubuntu
()
configure_ubuntu
()
{
{
rootfs
=
$1
rootfs
=
$1
...
@@ -278,8 +309,8 @@ install_packages()
...
@@ -278,8 +309,8 @@ install_packages()
cleanup
()
cleanup
()
{
{
rm
-rf
$cache
/partial-
$arch
try_rmsubvolume
$cache
/partial-
$arch
rm
-rf
$cache
/rootfs-
$arch
try_rmsubvolume
$cache
/rootfs-
$arch
}
}
suggest_flush
()
suggest_flush
()
...
@@ -311,7 +342,7 @@ download_ubuntu()
...
@@ -311,7 +342,7 @@ download_ubuntu()
trap
cleanup EXIT SIGHUP SIGINT SIGTERM
trap
cleanup EXIT SIGHUP SIGINT SIGTERM
# check the mini ubuntu was not already downloaded
# check the mini ubuntu was not already downloaded
mkdir
-p
"
$cache
/partial-
$arch
"
try_mksubvolume
"
$cache
/partial-
$arch
"
if
[
$?
-ne
0
]
;
then
if
[
$?
-ne
0
]
;
then
echo
"Failed to create '
$cache
/partial-
$arch
' directory"
echo
"Failed to create '
$cache
/partial-
$arch
' directory"
return
1
return
1
...
@@ -370,8 +401,16 @@ copy_ubuntu()
...
@@ -370,8 +401,16 @@ copy_ubuntu()
# make a local copy of the miniubuntu
# make a local copy of the miniubuntu
echo
"Copying rootfs to
$rootfs
..."
echo
"Copying rootfs to
$rootfs
..."
mkdir
-p
$rootfs
try_mksubvolume
$rootfs
rsync
-Ha
$cache
/rootfs-
$arch
/
$rootfs
/
||
return
1
if
is_btrfs_subvolume
$cache
/rootfs-
$arch
&&
is_btrfs_subvolume
$rootfs
;
then
realrootfs
=
$(
dirname
$config
)
/rootfs
umount
$rootfs
||
return
1
btrfs subvolume delete
$realrootfs
||
return
1
btrfs subvolume snapshot
$cache
/rootfs-
$arch
$realrootfs
||
return
1
mount
--bind
$realrootfs
$rootfs
||
return
1
else
rsync
-Ha
$cache
/rootfs-
$arch
/
$rootfs
/
||
return
1
fi
return
0
return
0
}
}
...
@@ -393,8 +432,8 @@ install_ubuntu()
...
@@ -393,8 +432,8 @@ install_ubuntu()
if
[
$flushcache
-eq
1
]
;
then
if
[
$flushcache
-eq
1
]
;
then
echo
"Flushing cache..."
echo
"Flushing cache..."
rm
-rf
"
$cache
/partial-
$arch
"
try_rmsubvolume
$cache
/partial-
$arch
rm
-rf
"
$cache
/rootfs-
$arch
"
try_rmsubvolume
$cache
/rootfs-
$arch
fi
fi
echo
"Checking cache download in
$cache
/rootfs-
$arch
... "
echo
"Checking cache download in
$cache
/rootfs-
$arch
... "
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment