Skip to content

Instantly share code, notes, and snippets.

@yjuba
Last active April 30, 2017 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yjuba/d3dec3f7f6959921320258ba76d08e93 to your computer and use it in GitHub Desktop.
Save yjuba/d3dec3f7f6959921320258ba76d08e93 to your computer and use it in GitHub Desktop.
LXD用のUbuntu Xenialイメージ作成スクリプト
#!/bin/bash
set -eu
set -x
REPO_URL='http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/ubuntu/'
work=$(mktemp -d work.XXXXXX)
cd ${work}
mkdir -p rootfs
mkdir -p templates
debootstrap --arch amd64 xenial rootfs ${REPO_URL}
cat > rootfs/etc/apt/sources.list <<EOF
deb ${REPO_URL} xenial main restricted universe multiverse
deb ${REPO_URL} xenial-updates main restricted universe multiverse
deb ${REPO_URL} xenial-security main restricted universe multiverse
EOF
cat > rootfs/etc/network/interfaces.d/lo <<EOF
auto lo
iface lo inet loopback
EOF
cat > rootfs/etc/network/interfaces.d/eth0 <<EOF
auto eth0
iface eth0 inet dhcp
EOF
cat > templates/hostname.tpl <<EOF
{{ container.name }}
EOF
cat > metadata.yaml <<EOF
architecture: x86_64
creation_date: $(date +%s)
properties:
description: Xenial
os: Ubuntu
release: "xenial"
templates:
/etc/hostname:
when:
- create
- copy
template: hostname.tpl
EOF
tar czf ubuntu.tar.gz metadata.yaml rootfs templates
lxc image import ubuntu.tar.gz --alias my-ubuntu
cd ..
rm -rf ${work}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment