Skip to content

Commit

Permalink
Merge pull request #8 from unclejack/live_environment_fixes
Browse files Browse the repository at this point in the history
Live environment fixes & persistent storage
  • Loading branch information
unclejack committed Feb 26, 2014
2 parents 5bca5c7 + 1dc1f17 commit 3f59ffb
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ RUN mkdir $LB ;\
--debootstrap-options "--variant=minbase" --firmware-chroot false \
--memtest none live
RUN cp /usr/share/doc/live-build/examples/hooks/stripped.chroot $LB/config/hooks/
RUN sed -i 's/rm -rf \/usr\/share\/zoneinfo\/\*//g' $LB/config/hooks/stripped.chroot
ADD hooks/ $LB/config/hooks/
ADD reqs.list.chroot $LB/config/package-lists/
ADD isolinux/ $LB/config/includes.binary/isolinux/
ADD includes.binary/ $LB/config/includes.binary/
ADD includes.chroot/ $LB/config/includes.chroot/
RUN echo "boot\ninitrd.img\nvmlinuz" > $LB/config/rootfs/excludes
WORKDIR /root/lb
CMD ["lb", "build"]
3 changes: 3 additions & 0 deletions hooks/clean.chroot
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ rm -f /usr/bin/omshell
rm -f /var/cache/debconf/templates.dat
rm -f /var/cache/debconf/templates.dat-old
rm -f /usr/bin/openssl
rm -rf /usr/share/mime/*
rm -rf /usr/share/X11/*
rm -rf /usr/share/fonts/*
2 changes: 2 additions & 0 deletions hooks/docker.chroot
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ devpts /dev/pts devpts defaults 0 0
tmpfs /run/shm tmpfs defaults 0 0
cgroup /cgroup cgroup defaults 0 0
EOF

update-rc.d docker defaults
34 changes: 32 additions & 2 deletions hooks/kernelclean.chroot
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,41 @@ rm -rf /lib/modules/*/kernel/drivers/infiniband/*
rm -rf /lib/modules/*/kernel/drivers/gpu/*
rm -rf /lib/modules/*/kernel/drivers/isdn/*
rm -rf /lib/modules/*/kernel/drivers/media/*
rm -rf /lib/modules/*/kernel/drivers/staging/media/*
rm -rf /lib/modules/*/kernel/drivers/staging/lustre/*
rm -rf /lib/modules/*/kernel/drivers/staging/comedi/*
rm -rf /lib/modules/*/kernel/drivers/staging/rtl8192e/*
rm -rf /lib/modules/*/kernel/drivers/staging/rtl8192u/*
rm -rf /lib/modules/*/kernel/drivers/staging/rtl8187se/*
rm -rf /lib/modules/*/kernel/drivers/staging/rtl8712/*
rm -rf /lib/modules/*/kernel/drivers/staging/speakup/*
rm -rf /lib/modules/*/kernel/fs/ocfs2/*
rm -rf /lib/modules/*/kernel/fs/ntfs/*
rm -rf /lib/modules/*/kernel/fs/cifs/*
rm -rf /lib/modules/*/kernel/net/bluetooth/*
rm -rf /lib/modules/*/kernel/fs/ubifs/*
rm -rf /lib/modules/*/kernel/fs/reiserfs/*
rm -rf /lib/modules/*/kernel/fs/jffs2/*
rm -rf /lib/modules/*/kernel/fs/hfsplus/*
rm -rf /lib/modules/*/kernel/fs/gfs2/*
rm -rf /lib/modules/*/kernel/fs/nfs/*
rm -rf /lib/modules/*/kernel/drivers/net/mac80211/*
rm -rf /lib/modules/*/kernel/drivers/net/wireless/*
rm -rf /lib/modules/*/kernel/drivers/net/wimax/*
rm -rf /lib/modules/*/kernel/drivers/net/irda/*
rm -rf /lib/modules/*/kernel/drivers/net/hamradio/*
rm -rf /lib/modules/*/kernel/drivers/net/arcnet/*
rm -rf /lib/modules/*/kernel/drivers/net/can/*
rm -rf /lib/modules/*/kernel/drivers/net/ethernet/qlogic/*
rm -rf /lib/modules/*/kernel/drivers/net/ethernet/mellanox/*
rm -rf /lib/modules/*/kernel/drivers/scsi/bfa/*
rm -rf /lib/modules/*/kernel/arch/x86/kvm/*
rm -rf /lib/modules/*/kernel/net/wireless/*
rm -rf /lib/modules/*/kernel/net/mac80211/*
rm -rf /lib/modules/*/kernel/net/sunrpc/*
rm -rf /lib/modules/*/kernel/net/wireless/*
rm -rf /lib/modules/*/kernel/net/bluetooth/*
rm -rf /lib/modules/*/kernel/net/irda/*

for i in `ls /lib/modules/`;
do
depmod $i
done
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ default debian2docker
label debian2docker
kernel /live/vmlinuz
initrd /live/initrd.img
append loglevel=3 username=docker console=ttyS0 console=tty0 boot=live config nomodeset norestore cgroup_enable=memory swapaccount=1
append loglevel=3 username=docker console=ttyS0 console=tty0 boot=live config noprompt noeject nomodeset norestore cgroup_enable=memory swapaccount=1 live-getty

implicit 0
prompt 1
Expand Down
2 changes: 2 additions & 0 deletions includes.chroot/etc/acpi/events/powerbtn
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
event=button[ /]power
action=/etc/acpi/powerbtn.sh
2 changes: 2 additions & 0 deletions includes.chroot/etc/acpi/powerbtn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/sbin/shutdown -h now "power button pressed - shutting down now"
12 changes: 12 additions & 0 deletions includes.chroot/etc/default/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Docker Upstart and SysVinit configuration file

# Customize location of Docker binary (especially for development testing).
#DOCKER="/usr/local/bin/docker"

DOCKER_HOST="tcp://0.0.0.0:4243"

# Use DOCKER_OPTS to modify the daemon startup options.
#DOCKER_OPTS="-dns 8.8.8.8"

# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy=http://127.0.0.1:3128/
112 changes: 112 additions & 0 deletions includes.chroot/etc/init.d/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/bin/sh

### BEGIN INIT INFO
# Provides: docker
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Create lightweight, portable, self-sufficient containers.
# Description:
# Docker is an open-source project to easily create lightweight, portable,
# self-sufficient containers from any application. The same container that a
# developer builds and tests on a laptop can run at scale, in production, on
# VMs, bare metal, OpenStack clusters, public clouds and more.
### END INIT INFO

BASE=$(basename $0)

DOCKER=/usr/bin/$BASE
DOCKER_PIDFILE=/var/run/$BASE.pid
DOCKER_OPTS=
DOCKER_HOST=
export DOCKER_DIR=`readlink -f /var/lib/docker`
export TMPDIR=$(readlink -f ${TMPDIR:-/tmp})

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

# Get lsb functions
. /lib/lsb/init-functions

if [ -f /etc/default/$BASE ]; then
. /etc/default/$BASE
fi

# if we're virtual, let's listen on $DOCKER_HOST, too
if /bin/dmesg | /bin/egrep -q '(VirtualBox|VMware|QEMU)'; then
DOCKER_OPTS="$DOCKER_OPTS -H $DOCKER_HOST"
fi

# if /var/lib/docker is on BTRFS, let's use the native btrfs driver
# (AUFS on top of BTRFS does very bad things)
DOCKER_DEVICE="$(/bin/df -P "$DOCKER_DIR" | /usr/bin/awk 'END { print $1 }')"
DOCKER_FSTYPE="$(/sbin/blkid -o export "$DOCKER_DEVICE" | /bin/grep TYPE= | /usr/bin/cut -d= -f2)"
if [ "$DOCKER_FSTYPE" = 'btrfs' ]; then
DOCKER_OPTS="$DOCKER_OPTS -s $DOCKER_FSTYPE"
fi

# see also init_is_upstart in /lib/lsb/init-functions (which isn't available in Ubuntu 12.04, or we'd use it)
if [ -x /sbin/initctl ] && /sbin/initctl version 2>/dev/null | /bin/grep -q upstart; then
log_failure_msg "Docker is managed via upstart, try using service $BASE $1"
exit 1
fi

# Check docker is present
if [ ! -x $DOCKER ]; then
log_failure_msg "$DOCKER not present or not executable"
exit 1
fi

fail_unless_root() {
if [ "$(id -u)" != '0' ]; then
log_failure_msg "Docker must be run as root"
exit 1
fi
}

case "$1" in
start)
fail_unless_root
log_begin_msg "Starting Docker: $BASE"
mount | grep cgroup >/dev/null || mount -t cgroup none /sys/fs/cgroup 2>/dev/null
start-stop-daemon --start --background \
--exec "$DOCKER" \
--pidfile "$DOCKER_PIDFILE" \
-- -d -p "$DOCKER_PIDFILE" \
$DOCKER_OPTS -g $DOCKER_DIR -H unix://
log_end_msg $?
;;

stop)
fail_unless_root
log_begin_msg "Stopping Docker: $BASE"
start-stop-daemon --stop \
--pidfile "$DOCKER_PIDFILE"
log_end_msg $?
;;

restart)
fail_unless_root
docker_pid=`cat "$DOCKER_PIDFILE" 2>/dev/null`
[ -n "$docker_pid" ] \
&& ps -p $docker_pid > /dev/null 2>&1 \
&& $0 stop
$0 start
;;

force-reload)
fail_unless_root
$0 restart
;;

status)
status_of_proc -p "$DOCKER_PIDFILE" "$DOCKER" docker
;;

*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac

exit 0
1 change: 1 addition & 0 deletions includes.chroot/etc/motd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debian2docker
98 changes: 98 additions & 0 deletions includes.chroot/lib/live/config/0161-automount
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/sh

LABELB2D=boot2docker-data
LABELD2D=debian2docker-data
MAGICB2D="boot2docker, please format-me"
MAGICB2D="debian2docker, please format-me"

# Look for partitions labeled boot2docker-data and debian2docker-data
BOOT2DOCKER_DATA=`blkid -o device -l -t LABEL=$LABELB2D || true`
DEBIAN2DOCKER_DATA=`blkid -o device -l -t LABEL=$LABELD2D || true`

if [ ! -n "$BOOT2DOCKER_DATA" -a ! -n "$BOOT2DOCKER_DATA" ]; then
# Is the disk unpartitioned?, test for the 'boot2docker format-me' string
UNPARTITIONED_HD=`fdisk -l | grep "doesn't contain a valid partition table" | head -n 1 | sed 's/Disk \(.*\) doesn.*/\1/'`

if [ -n "$UNPARTITIONED_HD" ]; then
# Test for our magic string (it means that the disk was made by ./boot2docker init)
HEADERB2D=`dd if=$UNPARTITIONED_HD bs=1 count=${#MAGICB2D} 2>/dev/null`
HEADERD2D=`dd if=$UNPARTITIONED_HD bs=1 count=${#MAGICB2D} 2>/dev/null`

if [ "$HEADERD2D" = "$MAGICD2D"]; then
# Create the partition, format it and then mount it
echo "NEW debian2docker managed disk image ($UNPARTITIONED_HD): formatting it for use"
echo "NEW debian2docker managed disk image ($UNPARTITIONED_HD): formatting it for use" > /home/docker/log.log

# make one big partition
(echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $UNPARTITIONED_HD
DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
mkfs.ext4 -L $LABEL $DOCKER_DATA

elif [ "$HEADERB2D" = "$MAGICB2D" ]; then
# Create the partition, format it and then mount it
echo "NEW boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use"
echo "NEW boot2docker managed disk image ($UNPARTITIONED_HD): formatting it for use" > /home/docker/log.log

# make one big partition
(echo n; echo p; echo 1; echo ; echo ; echo w) | fdisk $UNPARTITIONED_HD
DOCKER_DATA=`echo "${UNPARTITIONED_HD}1"`
mkfs.ext4 -L $LABEL $DOCKER_DATA
fi
else
# Pick the first ext4 as a fallback
# TODO: mount all Linux partitions and look for a /var/lib/docker...
DOCKER_DATA=`blkid | grep 'TYPE="ext4"' | head -n 1 | sed 's/:.*//'`
fi
fi

if [ -n "$DEBIAN2DOCKER_DATA" ]; then
DOCKER_DATA=$DEBIAN2DOCKER_DATA
elif [ -n "$BOOT2DOCKER_DATA" ]; then
DOCKER_DATA=$BOOT2DOCKER_DATA
fi


if [ -n "$DOCKER_DATA" ]; then
PARTNAME=`echo "$DOCKER_DATA" | sed 's/.*\///'`
mkdir -p /mnt/$PARTNAME
if ! mount $DOCKER_DATA /mnt/$PARTNAME 2>/dev/null; then
# for some reason, mount doesn't like to modprobe btrfs
DOCKER_FSTYPE=`blkid -o export $DOCKER_DATA | grep TYPE= | cut -d= -f2`
modprobe $DOCKER_FSTYPE || true
mount $DOCKER_DATA /mnt/$PARTNAME
fi

# Just in case, the links will fail if not
rm -rf /var/lib/docker /var/lib/boot2docker /var/lib/debian2docker
if [ -d /mnt/$PARTNAME/vm ]; then
# The old behavior - use the entire disk for boot2docker data
ln -s /mnt/$PARTNAME /var/lib/docker

# Give us a link to the new cusomisation location
ln -s /var/lib/docker/vm /var/lib/debian2docker

# Make sure /tmp is on the disk too too
if [ -d /var/lib/debian2docker/tmp ]; then
rm -rf /var/lib/debian2docker/tmp
fi
mv /tmp /var/lib/debian2docker/tmp
ln -s /var/lib/debian2docker/tmp /tmp
else
# Detected a disk with a normal linux install (/var/lib/docker + more))
mkdir -p /var/lib

mkdir -p /mnt/$PARTNAME/var/lib/docker
ln -s /mnt/$PARTNAME/var/lib/docker /var/lib/docker

mkdir -p /mnt/$PARTNAME/var/lib/debian2docker
ln -s /mnt/$PARTNAME/var/lib/debian2docker /var/lib/debian2docker

# Make sure /tmp is on the disk too too
if [ -d /mnt/$PARTNAME/tmp ]; then
rm -rf /mnt/$PARTNAME/tmp
fi
mv /tmp /mnt/$PARTNAME/tmp
ln -s /mnt/$PARTNAME/tmp /tmp
fi

fi
2 changes: 1 addition & 1 deletion reqs.list.chroot
Original file line number Diff line number Diff line change
@@ -1 +1 @@
iproute isc-dhcp-client isc-dhcp-common ifupdown iptables xz-utils user-setup sudo live-config live-tools aufs-tools ca-certificates wget lxc
iproute isc-dhcp-client isc-dhcp-common ifupdown iptables xz-utils user-setup sudo live-config live-tools aufs-tools ca-certificates wget file btrfs-tools dropbear traceroute iputils-ping acpid lxc

0 comments on commit 3f59ffb

Please sign in to comment.