lxc / create image / debian squeeze
I’m quite happy with our LXC environment on which I’ve got various
Debian and Ubuntu build VMs so I can package backports and other
fixes into nice .deb
packages.
Today I needed an old Debian/Squeeze machine to build backports on.
Step one: check the lists.
$ lxc remote list
+-----------------+--------------------------+---------------+-----+-----+
| NAME | URL | PROTOCOL | PUB | STC |
+-----------------+--------------------------+---------------+-----+-----+
| images | https://images.linuxco...| simplestreams | YES | NO |
+-----------------+--------------------------+---------------+-----+-----+
| local (default) | unix:// | lxd | NO | YES |
+-----------------+--------------------------+---------------+-----+-----+
| ubuntu | https://cloud-images.u.. | simplestreams | YES | YES |
+-----------------+--------------------------+---------------+-----+-----+
| ubuntu-daily | https://cloud-images.u.. | simplestreams | YES | YES |
+-----------------+--------------------------+---------------+-----+-----+
$ lxc image list images:
+---------------------+--------------+-----+-------------+--------+--------+
| ALIAS | FINGERPRINT | PUB | DESCRIPTION | ARCH | SIZE |
+---------------------+--------------+-----+-------------+--------+--------+
| alpine/3.1 (3 more) | e63bc8abc9cf | yes | Alpine 3.1 | x86_64 | 2.32MB |
+---------------------+--------------+-----+-------------+--------+--------+
...
Lots of images. Any Squeeze in there?
$ lxc image list images: | grep -i squeeze
$ lxc image list local: | grep -i squeeze
$ lxc image list ubuntu: | grep -i squeeze
$ lxc image list ubuntu-daily: | grep -i squeeze
Nope. And the internet wasn’t too helpful either.
So, on to build a custom LXC image.
The Ubuntu Insight website was pretty helpful with the Manually building an image topic:
- Generate a container filesystem. This entirely depends on the distribution you’re using. For Ubuntu and Debian, it would be by using debootstrap.
- Configure anything that’s needed for the distribution to work properly in a container (if anything is needed).
- Make a tarball of that container filesystem, optionally compress it.
- Write a new metadata.yaml file based on the one described above.
- Create another tarball containing that metadata.yaml file.
- Import those two tarballs as a LXD image with:
lxc image import <metadata tarball> <rootfs tarball> --alias some-name
Apparently that first step is automated by the scripts in the LXC repository:
$ ls lxc/templates
lxc/templates$ ls *.in
lxc-alpine.in lxc-cirros.in lxc-openmandriva.in lxc-slackware.in Makefile.in
lxc-altlinux.in lxc-debian.in lxc-opensuse.in lxc-sparclinux.in
lxc-archlinux.in lxc-download.in lxc-oracle.in lxc-sshd.in
lxc-busybox.in lxc-fedora.in lxc-plamo.in lxc-ubuntu-cloud.in
lxc-centos.in lxc-gentoo.in lxc-pld.in lxc-ubuntu.in
Try it:
$ sudo bash lxc-debian.in --path=/home/walter/debian-squeeze \
--arch=amd64 --release=squeeze \
--mirror=http://archive.debian.org/debian \
--security-mirror=http://archive.debian.org/debian
debootstrap is /usr/sbin/debootstrap
Invalid release squeeze, valid ones are: wheezy jessie stretch sid
I’m sure we can hack that a bit (I used git checkout 13dbc780
), by:
- fixing the paths (normally done by automake),
- adding ‘squeeze’ in the appropriate places,
- work around an issue where the nics count is not found.
--- lxc-debian.in 2016-09-14 13:43:07.739541126 +0200
+++ lxc-debian 2016-09-15 11:42:22.645638673 +0200
@@ -36,8 +36,8 @@ export GREP_OPTIONS=""
MIRROR=${MIRROR:-http://httpredir.debian.org/debian}
SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/}
-LOCALSTATEDIR="@LOCALSTATEDIR@"
-LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
+LOCALSTATEDIR="/tmp/lxc-create-var"
+LXC_TEMPLATE_CONFIG="/tmp/lxc-create-config"
# Allows the lxc-cache directory to be set by environment variable
LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
@@ -314,7 +314,7 @@ cleanup()
download_debian()
{
case "$release" in
- wheezy)
+ squeeze|wheezy)
init=sysvinit
;;
*)
@@ -490,6 +490,7 @@ copy_configuration()
# if there is exactly one veth network entry, make sure it has an
# associated hwaddr.
nics=$(grep -ce '^lxc\.network\.type[ \t]*=[ \t]*veth' "$path/config")
+ nics=0
if [ "$nics" -eq 1 ]; then
grep -q "^lxc.network.hwaddr" "$path/config" || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" "$path/config"
fi
@@ -753,7 +754,7 @@ fi
current_release=$(wget "${MIRROR}/dists/stable/Release" -O - 2> /dev/null | head |awk '/^Codename: (.*)$/ { print $2; }')
release=${release:-${current_release}}
-valid_releases=('wheezy' 'jessie' 'stretch' 'sid')
+valid_releases=('squeeze' 'wheezy' 'jessie' 'stretch' 'sid')
if [[ ! "${valid_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
echo "Invalid release ${release}, valid ones are: ${valid_releases[*]}"
exit 1
Run it:
$ sudo bash lxc-debian --path=/home/walter/debian-squeeze \
--arch=amd64 --release=squeeze \
--mirror=http://archive.debian.org/debian \
--security-mirror=http://archive.debian.org/debian
...
$ cd /home/walter/debian-squeeze
$ ls -l
total 13
-rw-r--r-- 1 root root 165 sep 14 14:04 config
drwxr-xr-x 20 root root 21 sep 14 14:09 rootfs
This needs a metadata.yaml
as described (on the same page mentioned
earlier) under Image
metadata.
The following is enough:
architecture: "amd64"
creation_date: 1473854884
properties:
architecture: "amd64"
description: "Debian GNU/Linux 6.0 (squeeze)"
os: "debian"
release: "squeeze"
Tar them together into a package and import it:
$ sudo tar zcf ../debian-squeeze.tar.gz metadata.yaml rootfs
$ lxc image import ../debian-squeeze.tar.gz
Transferring image: 100%
Image imported with fingerprint: 9bcaba951c4efabbd5ee32f74f01df567d7cb1c725cc67512283b0bb88ea7a91
$ lxc image alias create debian/squeeze 9bcaba951c4efabbd5ee32f74f01df567d7cb1c725cc67512283b0bb88ea7a91
Nice, it works. Do we have an image? Yes we do.
$ lxc image list local: | grep -i squeeze
| debian/squeeze | 9bcaba951c4e | no | Debian GNU/Linux 6.0 (squeeze) | x86_64 | 112.52MB | Sep 14, 2016 at 12:10pm (UTC) |
$ lxc launch debian/squeeze squeeze-builder
$ lxc exec squeeze-builder /bin/bash
root@squeeze-builder:~# cat /etc/issue.net
Debian GNU/Linux 6.0
It’s a bit bare, but it works. Some tweaks to /etc/hosts
and
/etc/hostname
seemed enough. Time to get building!