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
80773206
Commit
80773206
authored
May 14, 2013
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-cirros updates
fix userdata consumption patch for console issue Signed-off-by:
Scott Moser
<
scott.moser@canonical.com
>
Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
parent
58a46e06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
123 additions
and
92 deletions
+123
-92
lxc-cirros.in
templates/lxc-cirros.in
+123
-92
No files found.
templates/lxc-cirros.in
View file @
80773206
...
@@ -21,18 +21,17 @@
...
@@ -21,18 +21,17 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
VERBOSITY
=
0
VERBOSITY
=
0
TEMP_D
=
""
DOWNLOAD_URL
=
"http://download.cirros-cloud.net/"
DOWNLOAD_URL
=
"http://download.cirros-cloud.net/"
CACHE_D
=
"/var/cache/lxc/cirros"
CACHE_D
=
"@LOCALSTATEDIR@/cache/lxc/cirros"
CACHE_D
=
"@LOCALSTATEDIR@/cache/lxc/cirros"
TMP_FILE
=
""
UNAME_M
=
$(
uname
-m
)
UNAME_M
=
$(
uname
-m
)
ARCHES
=(
i386 x86_64 amd64 arm
)
ARCHES
=(
i386 x86_64 amd64 arm
)
STREAMS
=(
released devel
)
STREAMS
=(
released devel
)
SOURCES
=(
nocloud none
)
BUILD
=
"standard"
BUILD
=
"standard"
DEF_VERSION
=
"released"
DEF_VERSION
=
"released"
DEF_SOURCE
=
"nocloud"
case
"
${
UNAME_M
}
"
in
case
"
${
UNAME_M
}
"
in
i?86
)
DEF_ARCH
=
"i386"
;;
i?86
)
DEF_ARCH
=
"i386"
;;
x86_64
)
DEF_ARCH
=
"x86_64"
;;
x86_64
)
DEF_ARCH
=
"x86_64"
;;
...
@@ -40,11 +39,7 @@ case "${UNAME_M}" in
...
@@ -40,11 +39,7 @@ case "${UNAME_M}" in
*
)
DEF_ARCH
=
"i386"
;;
*
)
DEF_ARCH
=
"i386"
;;
esac
esac
error
()
{
echo
"
$@
"
1>&2
;
}
error
()
{
echo
"
$@
"
1>&2
;
}
errorp
()
{
printf
"
$@
"
1>&2
;
}
fail
()
{
[
$#
-eq
0
]
||
error
"
$@
"
;
exit
1
;
}
failp
()
{
[
$#
-eq
0
]
||
errorp
"
$@
"
;
exit
1
;
}
inargs
()
{
inargs
()
{
local
needle
=
"
$1
"
x
=
""
local
needle
=
"
$1
"
x
=
""
shift
shift
...
@@ -58,7 +53,7 @@ Usage() {
...
@@ -58,7 +53,7 @@ Usage() {
cat
<<
EOF
cat
<<
EOF
${
0
##*/
}
[options]
${
0
##*/
}
[options]
-a | --arch A architecture to use [
${
ARCHES
}
]
-a | --arch A architecture to use [
${
ARCHES
[*]
}
]
default:
${
DEF_ARCH
}
default:
${
DEF_ARCH
}
-h | --help this usage
-h | --help this usage
-v | --verbose increase verbosity
-v | --verbose increase verbosity
...
@@ -66,14 +61,14 @@ ${0##*/} [options]
...
@@ -66,14 +61,14 @@ ${0##*/} [options]
-v | --version V version [
${
STREAMS
[*]
}
]
-v | --version V version [
${
STREAMS
[*]
}
]
default:
${
DEF_VERSION
}
default:
${
DEF_VERSION
}
-u | --userdata U user-data file
-u | --userdata U user-data file
--tarball T read from tarball 'T' rather than downloading
or using cache.
--source S insert userdata/metadata via source S
[
${
SOURCES
[*]
}
]
EOF
EOF
}
}
bad_Usage
()
{
Usage 1>&2
;
[
$#
-eq
0
]
||
error
"
$@
"
;
exit
1
;
}
bad_Usage
()
{
Usage 1>&2
;
[
$#
-eq
0
]
||
error
"
$@
"
;
return
1
;
}
cleanup
()
{
[
-z
"
${
TEMP_D
}
"
-o
!
-d
"
${
TEMP_D
}
"
]
||
rm
-Rf
"
${
TEMP_D
}
"
[
-z
"
${
TEMP_FILE
}
"
]
||
rm
-Rf
"
${
TEMP_FILE
}
"
}
debug
()
{
debug
()
{
local
level
=
${
1
}
;
shift
;
local
level
=
${
1
}
;
shift
;
...
@@ -144,8 +139,8 @@ lxc.cgroup.devices.allow = c 10:232 rwm
...
@@ -144,8 +139,8 @@ lxc.cgroup.devices.allow = c 10:232 rwm
EOF
EOF
}
}
insert_ds
()
{
insert_ds
_nocloud
()
{
local
root_d
=
"
$1
"
dstype
=
"
$2
"
authkey
=
"
$3
"
userdata
=
"
$4
"
local
root_d
=
"
$1
"
authkey
=
"
$2
"
udfile
=
"
$3
"
local
sdir
=
"
$root_d
/var/lib/cloud/seed/nocloud"
local
sdir
=
"
$root_d
/var/lib/cloud/seed/nocloud"
mkdir
-p
"
$sdir
"
||
mkdir
-p
"
$sdir
"
||
...
@@ -158,9 +153,19 @@ insert_ds() {
...
@@ -158,9 +153,19 @@ insert_ds() {
${
authkeys
:+
"public-keys=
${
authkeys
}
"
}
>
"
$sdir
/meta-data"
||
${
authkeys
:+
"public-keys=
${
authkeys
}
"
}
>
"
$sdir
/meta-data"
||
{
error
"failed to write metadata to
$sdir
/meta-data"
;
return
1
;
}
{
error
"failed to write metadata to
$sdir
/meta-data"
;
return
1
;
}
[
-z
"
$userdata
"
]
||
if
[
-n
"
$udfile
"
]
;
then
echo
"
$userdata
"
>
"
$sdir
/user-data"
||
cat
"
$udfile
"
>
"
$sdir
/user-data"
||
{
error
"failed to write user-data to
$sdir
"
;
return
1
;
}
{
error
"failed to write user-data to
$sdir
"
;
return
1
;
}
else
rm
-f
"
$sdir
/user-data"
fi
}
insert_ds
()
{
local
dstype
=
"
$1
"
root_d
=
"
$2
"
authkey
=
"
$3
"
udfile
=
"
$4
"
case
"
$dstype
"
in
nocloud
)
insert_ds_nocloud
"
$root_d
"
"
$authkey
"
"
$udfile
"
esac
}
}
extract_rootfs
()
{
extract_rootfs
()
{
...
@@ -187,6 +192,7 @@ download_tarball() {
...
@@ -187,6 +192,7 @@ download_tarball() {
mkdir
-p
"
${
outd
}
"
||
mkdir
-p
"
${
outd
}
"
||
{
error
"failed to create
${
outd
}
"
;
return
1
;
}
{
error
"failed to create
${
outd
}
"
;
return
1
;
}
debug 1
"downloading
${
baseurl
%/
}
/
$dlpath
"
to
"
${
cached
}
/
$dlpath
"
wget
"
${
baseurl
%/
}
/
$dlpath
"
-O
"
$cached
/
${
dlpath
}
.
$$
"
&&
wget
"
${
baseurl
%/
}
/
$dlpath
"
-O
"
$cached
/
${
dlpath
}
.
$$
"
&&
mv
"
$cached
/
$dlpath
.
$$
"
"
$cached
/
$dlpath
"
||
{
mv
"
$cached
/
$dlpath
.
$$
"
"
$cached
/
$dlpath
"
||
{
rm
-f
"
$cached
/
$dlpath
.
$$
"
;
rm
-f
"
$cached
/
$dlpath
.
$$
"
;
...
@@ -196,93 +202,118 @@ download_tarball() {
...
@@ -196,93 +202,118 @@ download_tarball() {
_RET
=
"
$cached
/
$dlpath
"
_RET
=
"
$cached
/
$dlpath
"
}
}
short_opts
=
"a:n:p:S:huV"
create_main
()
{
long_opts
=
"arch:,auth-key:,name:,path:,userdata:,verbose,version:
"
local
short_opts
=
"a:hn:p:S:uvV
"
getopt_out
=
$(
getopt
--name
"
${
0
##*/
}
"
\
local
long_opts
=
"arch:,auth-key:,name:,path:,tarball:,userdata:,verbose,version:"
--options
"
${
short_opts
}
"
--long
"
${
long_opts
}
"
--
"
$@
"
)
&&
local
getopt_out
=
""
eval set
--
"
${
getopt_out
}
"
||
getopt_out
=
$(
getopt
--name
"
${
0
##*/
}
"
\
bad_Usage
--options
"
${
short_opts
}
"
--long
"
${
long_opts
}
"
--
"
$@
"
)
&&
eval set
--
"
${
getopt_out
}
"
||
arch
=
"
${
DEF_ARCH
}
"
{
bad_Usage
;
return
;
}
version
=
"
${
DEF_VERSION
}
"
authkey_f
=
"
"
local arch
=
"
${
DEF_ARCH
}
"
dsource
=
"
${
DEF_SOURCE
}
"
version
=
"
${
DEF_VERSION
}
"
authkeys
=
""
local
authkey_f
=
""
authkeys
=
""
userdata_f
=
""
path
=
""
tarball
=
""
userdata
=
""
local
cur
=
""
next
=
""
seed
=
true
path
=
""
while
[
$#
-ne
0
]
;
do
cur
=
$1
;
next
=
$2
;
while
[
$#
-ne
0
]
;
do
case
"
$cur
"
in
cur
=
$1
;
next
=
$2
;
-a
|
--arch
)
arch
=
"
$next
"
;
shift
;
;
case
"
$cur
"
in
-h
|
--help
)
Usage
;
return
0
;;
-a
|
--arch
)
arch
=
"
$next
"
;
shift
;;
-n
|
--name
)
name
=
"
$next
"
;
shift
;;
-h
|
--help
)
Usage
;
exit
0
;;
-v
|
--verbose
)
VERBOSITY
=
$((${
VERBOSITY
}
+
1
))
;;
-n
|
--name
)
name
=
"
$next
"
;
shift
;;
-S
|
--auth-key
)
authkey_f
=
"
$next
"
;
shift
;;
-v
|
--verbose
)
VERBOSITY
=
$((${
VERBOSITY
}
+
1
))
;;
-p
|
--path
)
path
=
$next
;
shift
;;
-S
|
--auth-key
)
authkey_f
=
"
$next
"
;
shift
;;
-v
|
--version
)
version
=
$next
;
shift
;;
-p
|
--path
)
path
=
$next
;
shift
;;
-u
|
--userdata
)
userdata_f
=
"
$next
"
;
shift
;;
-v
|
--version
)
version
=
$next
;
shift
;;
--tarball
)
tarball
=
"
$next
"
;
shift
;;
-u
|
--userdata
)
userdata
=
"
$next
"
;
shift
;;
--source
)
dsource
=
"
$next
"
;
shift
;;
--
)
shift
;
break
;;
--
)
shift
;
break
;;
esac
esac
shift
;
shift
;
done
done
[
$#
-eq
0
]
||
bad_Usage
"unexpected arguments:
$*
"
[
$#
-eq
0
]
||
{
bad_Usage
"unexpected arguments:
$*
"
;
return
;
}
[
-n
"
$path
"
]
||
fail
"'path' parameter is required"
[
-n
"
$path
"
]
||
{
error
"'path' parameter is required"
;
return
1
;
}
if
[
"
$(
id
-u
)
"
!=
"0"
]
;
then
if
[
"
$(
id
-u
)
"
!=
"0"
]
;
then
fail
"must be run as root"
{
error
"must be run as root"
;
return
1
;
}
fi
fi
case
"
$arch
"
in
case
"
$arch
"
in
i?86
)
arch
=
"i386"
;;
i?86
)
arch
=
"i386"
;;
amd64
)
arch
=
"x86_65"
;;
amd64
)
arch
=
"x86_64"
;;
esac
esac
inargs
"
$arch
"
"
${
ARCHES
[@]
}
"
||
{
error
"bad arch '
$arch
'. allowed:
${
ARCHES
[*]
}
"
;
return
1
;
}
inargs
"
$dsource
"
"
${
SOURCES
[@]
}
"
||
{
error
"bad source '
$dsource
'. allowed:
${
SOURCES
[*]
}
"
;
return
1
;
}
inargs
"
$arch
"
"
${
ARCHES
[@]
}
"
||
if
[
"
$dsource
"
=
"none"
]
&&
[
-n
"
$userdata_f
"
-o
-n
"
$authkey_f
"
]
;
then
fail
"bad arch '
$arch
'. allowed:
${
ARCHES
[*]
}
"
error
"userdata and authkey are incompatible with --source=none"
;
return
1
;
fi
if
inargs
"
$version
"
"
${
STREAMS
[@]
}
"
;
then
if
[
-n
"
$authkey_f
"
]
;
then
out
=
$(
wget
-O
-
-q
"
${
DOWNLOAD_URL
%/
}
/version/
$version
"
)
||
if
[
!
-f
"
$authkey_f
"
]
;
then
fail
"failed to convert 'version=
$version
'"
error
"--auth-key=
${
authkey_f
}
must reference a file"
version
=
"
$out
"
return
1
fi
fi
authkeys
=
$(
cat
"
$authkey_f
"
)
||
{
error
"failed to read
${
authkey_f
}
"
;
return
1
;
}
fi
if
[
-n
"
$authkey_f
"
]
;
then
if
[
-n
"
$userdata_f
"
-a
!
-f
"
${
userdata_f
}
"
]
;
then
if
[
!
-f
"
$authkey_f
"
]
;
then
error
"
${
userdata_f
}
: --userdata arg not a file"
echo
"--auth-key=
${
authkey_f
}
must reference a file"
return
1
exit
1
fi
fi
authkeys
=
$(
cat
"
$authkey
"
)
fi
trap
cleanup EXIT
if
[
-z
"
$tarball
"
]
;
then
if
inargs
"
$version
"
"
${
STREAMS
[@]
}
"
;
then
out
=
$(
wget
-O
-
-q
"
${
DOWNLOAD_URL
%/
}
/version/
$version
"
)
||
{
error
"failed to convert 'version=
$version
'"
;
return
1
;
}
version
=
"
$out
"
fi
download_tarball
"
$arch
"
"
$version
"
"
${
CACHE_D
}
"
"
${
DOWNLOAD_URL
}
"
||
return
tarball
=
"
$_RET
"
fi
download_tarball
"
$arch
"
"
$version
"
"
${
CACHE_D
}
"
"
${
DOWNLOAD_URL
}
"
||
fail
local
rootfs_d
=
"
$path
/rootfs"
tarball
=
"
$_RET
"
extract_rootfs
"
${
tarball
}
"
"
${
rootfs_d
}
"
||
return
rootfs_d
=
"
$path
/rootfs"
# cirros 0.3.1 was broken for /dev/random and /dev/urandom
extract_rootfs
"
${
tarball
}
"
"
${
rootfs_d
}
"
||
fail
if
[
-b
"
$rootfs_d
/dev/random"
]
;
then
rm
-f
"
$rootfs_d
/dev/random"
&&
mknod
--mode
=
666
"
$rootfs_d
/dev/random"
c 1 8
||
{
error
"failed to fix /dev/random"
;
return
1
;
}
fi
if
[
-b
"
$rootfs_d
/dev/urandom"
]
;
then
rm
-f
"
$rootfs_d
/dev/urandom"
&&
mknod
--mode
=
666
"
$rootfs_d
/dev/urandom"
c 1 9
||
{
error
"failed to fix /dev/urandom"
;
return
1
;
}
fi
# oopsie - some cirros tarballs ship random as a blockdev, breaking
if
[
"
$version
"
=
"0.3.2~pre1"
]
;
then
# dropbear.
debug 1
"fixing console for lxc and '
$version
'"
if
[
-b
${
rootfs_d
}
/dev/random
]
;
then
sed
-i
's,^\(#console.* 115200 \)# /dev/console,\1 console,g'
\
rm
-f
${
rootfs_d
}
/dev/random
"
$rootfs_d
/etc/inittab"
||
rm
-f
${
rootfs_d
}
/dev/urandom
{
error
"failed to fix console entry for
$version
"
;
return
1
;
}
mknod
${
rootfs_d
}
/dev/random c 1 8
fi
mknod
${
rootfs_d
}
/dev/urandom c 1 9
chmod
777
${
rootfs_d
}
/dev/random
${
rootfs_d
}
/dev/urandom
fi
if
false
;
then
if
[
"
$dsource
"
!=
"none"
]
;
then
insert_ds
"
$path
/rootfs"
"nocloud"
"
$authkeys
"
"
$userdata
"
||
insert_ds
"
$dsource
"
"
$path
/rootfs"
"
$authkeys
"
"
$userdata_f
"
||
{
fail
"failed to insert userdata to
$path
/rootfs"
error
"failed to insert userdata to
$path
/rootfs"
else
return
1
# disable ec2, because its annoying
}
sed
-i
's,ec2,,'
"
$path
/rootfs/etc/cirros-init/config"
fi
fi
copy_configuration
"
$path
"
"
$path
/rootfs"
"
$name
"
"
$arch
"
"
$release
"
copy_configuration
"
$path
"
"
$path
/rootfs"
"
$name
"
"
$arch
"
"
$release
"
return
}
create_main
"
$@
"
# vi: ts=4 expandtab
# vi: ts=4 expandtab
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