[OpenWrt-Devel] [PATCH] images: Add option build tar.gz suitable for use as LCX guest rootfs
openwrt at daniel.thecshore.com
openwrt at daniel.thecshore.com
Wed Dec 16 09:50:44 EST 2015
From: Daniel Dickinson <openwrt at daniel.thecshore.com>
An any target with targz image support we add the option of building
a tar.gz which is suitably configured to run as a LXC guest rootfs.
NB: This does not require kernel support; the LCX *host* requires
the appropriate kernel support, but building the guest does not
need such support enabled.
Note that the clearvar initscript is necessary for LXC guests because /tmp
doesn't go away on reboot.
Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
---
config/Config-images.in | 7 +++
include/image.mk | 16 ++++++
scripts/metadata.pl | 1 +
target/linux/ar71xx/mikrotik/target.mk | 2 +-
target/linux/at91/Makefile | 2 +-
.../linux/generic/base-files-lxc/etc/init.d/boot | 61 ++++++++++++++++++++++
.../generic/base-files-lxc/etc/init.d/clearvar | 12 +++++
target/linux/generic/base-files-lxc/etc/inittab | 6 +++
.../etc/uci-defaults/disablelxcinitscripts | 6 +++
target/linux/imx6/Makefile | 2 +-
target/linux/kirkwood/Makefile | 2 +-
target/linux/omap/Makefile | 2 +-
target/linux/omap24xx/Makefile | 2 +-
target/linux/orion/harddisk/target.mk | 2 +-
target/linux/rb532/Makefile | 2 +-
target/linux/x86/Makefile | 2 +-
target/linux/x86/xen_domu/target.mk | 2 +-
target/linux/xburst/Makefile | 2 +-
18 files changed, 120 insertions(+), 11 deletions(-)
create mode 100755 target/linux/generic/base-files-lxc/etc/init.d/boot
create mode 100755 target/linux/generic/base-files-lxc/etc/init.d/clearvar
create mode 100644 target/linux/generic/base-files-lxc/etc/inittab
create mode 100644 target/linux/generic/base-files-lxc/etc/uci-defaults/disablelxcinitscripts
diff --git a/config/Config-images.in b/config/Config-images.in
index a60dd50..ba0d79b 100644
--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -64,6 +64,13 @@ menu "Target Images"
help
Build a compressed tar archive of the root filesystem.
+ config TARGET_ROOTFS_LXC_TARGZ
+ bool "LXC guest .tar.gz"
+ default n
+ help
+ Build a compressed tar archive of the root filesystem for use
+ in an LXC guest.
+
comment "Root filesystem images"
menuconfig TARGET_ROOTFS_EXT4FS
diff --git a/include/image.mk b/include/image.mk
index 6b2fb1a..37eb28a 100644
--- a/include/image.mk
+++ b/include/image.mk
@@ -74,6 +74,7 @@ fs-types-$(CONFIG_TARGET_ROOTFS_ISO) += iso
fs-subtypes-$(CONFIG_TARGET_ROOTFS_JFFS2) += $(addsuffix -raw,$(addprefix jffs2-,$(JFFS2_BLOCKSIZE)))
fs-subtypes-$(CONFIG_TARGET_ROOTFS_CPIOGZ) += cpiogz
fs-subtypes-$(CONFIG_TARGET_ROOTFS_TARGZ) += targz
+fs-subtypes-$(CONFIG_TARGET_ROOTFS_LXC_TARGZ) += lxc-targz
TARGET_FILESYSTEMS := $(fs-types-y)
@@ -258,6 +259,21 @@ define Image/mkfs/targz
$(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-rootfs.tar.gz --numeric-owner --owner=0 --group=0 --sort=name -C $(TARGET_DIR)/ .
endef
+define Image/mkfs/lxc-targz
+ rm -rf $(TARGET_DIR).lxc
+ $(CP) $(TARGET_DIR) $(TARGET_DIR).lxc
+ rm -f $(TARGET_DIR).lxc/etc/uci-defaults/inittab
+ $(CP) $(TOPDIR)/target/linux/generic/base-files-lxc/* $(TARGET_DIR).lxc/
+ ( \
+ cd $(TARGET_DIR).lxc; \
+ for script in ./etc/init.d/*; do \
+ grep '#!/bin/sh /etc/rc.common' $$$$script >/dev/null || continue; \
+ IPKG_INSTROOT="$(TARGET_DIR).lxc" $$$$(which bash) ./etc/rc.common $$$$script enable; \
+ done; \
+ )
+ $(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)$(if $(PROFILE_SANITIZED),-$(PROFILE_SANITIZED))-lxc-rootfs.tar.gz --numeric-owner --owner=0 --group=0 --sort=name -C $(TARGET_DIR).lxc/ .
+endef
+
E2SIZE=$(shell echo $$(($(CONFIG_TARGET_ROOTFS_PARTSIZE)*1024*1024)))
define Image/mkfs/ext4
diff --git a/scripts/metadata.pl b/scripts/metadata.pl
index 54341c4..5b524d9 100755
--- a/scripts/metadata.pl
+++ b/scripts/metadata.pl
@@ -132,6 +132,7 @@ sub target_config_features(@) {
/jffs2_nand/ and $ret .= "\tselect USES_JFFS2_NAND\n";
/ext4/ and $ret .= "\tselect USES_EXT4\n";
/targz/ and $ret .= "\tselect USES_TARGZ\n";
+ /lxc-targz/ and $ret .= "\tselect USES_TARGZ\n";
/cpiogz/ and $ret .= "\tselect USES_CPIOGZ\n";
/ubifs/ and $ret .= "\tselect USES_UBIFS\n";
/fpu/ and $ret .= "\tselect HAS_FPU\n";
diff --git a/target/linux/ar71xx/mikrotik/target.mk b/target/linux/ar71xx/mikrotik/target.mk
index b2fb0df..49d49fb 100644
--- a/target/linux/ar71xx/mikrotik/target.mk
+++ b/target/linux/ar71xx/mikrotik/target.mk
@@ -1,5 +1,5 @@
BOARDNAME:=Mikrotik devices with NAND flash
-FEATURES += targz ramdisk
+FEATURES += targz lxc-targz ramdisk
define Target/Description
Build firmware images for Atheros AR71xx/AR913x based Mikrotik boards.
diff --git a/target/linux/at91/Makefile b/target/linux/at91/Makefile
index e1c771a..84f8463 100644
--- a/target/linux/at91/Makefile
+++ b/target/linux/at91/Makefile
@@ -10,7 +10,7 @@ ARCH:=arm
BOARD:=at91
MAINTAINER:=Claudio Mignanti <c.mignanti at gmail.com>
BOARDNAME:=Atmel AT91
-FEATURES:=squashfs targz ext2 usb usbgadget ubifs
+FEATURES:=squashfs targz lxc-targz ext2 usb usbgadget ubifs
SUBTARGETS:=legacy sama5d3
KERNEL_PATCHVER:=3.18
diff --git a/target/linux/generic/base-files-lxc/etc/init.d/boot b/target/linux/generic/base-files-lxc/etc/init.d/boot
new file mode 100755
index 0000000..c2b83f7
--- /dev/null
+++ b/target/linux/generic/base-files-lxc/etc/init.d/boot
@@ -0,0 +1,61 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006-2011 OpenWrt.org
+
+START=10
+STOP=98
+
+uci_apply_defaults() {
+ . /lib/functions/system.sh
+
+ cd /etc/uci-defaults || return 0
+ files="$(ls)"
+ [ -z "$files" ] && return 0
+ mkdir -p /tmp/.uci
+ for file in $files; do
+ ( . "./$(basename $file)" ) && rm -f "$file"
+ done
+ uci commit
+}
+
+boot() {
+# [ -f /proc/mounts ] || /sbin/mount_root
+# [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
+ [ -f /proc/net/vlan/config ] && vconfig set_name_type DEV_PLUS_VID_NO_PAD
+
+ mkdir -p /var/run
+ mkdir -p /var/log
+ mkdir -p /var/lock
+ mkdir -p /var/state
+ mkdir -p /tmp/.uci
+ chmod 0700 /tmp/.uci
+ mkdir -p /tmp/.jail
+ touch /var/log/wtmp
+ touch /var/log/lastlog
+ touch /tmp/resolv.conf.auto
+ ln -sf /tmp/resolv.conf.auto /tmp/resolv.conf
+# grep -q debugfs /proc/filesystems && /bin/mount -o noatime -t debugfs debugfs /sys/kernel/debug
+ [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
+
+# /sbin/kmodloader
+
+ # allow wifi modules time to settle
+ sleep 1
+
+# /sbin/wifi detect > /tmp/wireless.tmp
+ [ -s /tmp/wireless.tmp ] && {
+ cat /tmp/wireless.tmp >> /etc/config/wireless
+ }
+ rm -f /tmp/wireless.tmp
+
+# /bin/board_detect
+ uci_apply_defaults
+
+ # temporary hack until configd exists
+ /sbin/reload_config
+
+ # create /dev/root if it doesn't exist
+ [ -e /dev/root -o -h /dev/root ] || {
+ rootdev=$(awk 'BEGIN { RS=" "; FS="="; } $1 == "root" { print $2 }' < /proc/cmdline)
+ [ -n "$rootdev" ] && ln -s "$rootdev" /dev/root
+ }
+}
diff --git a/target/linux/generic/base-files-lxc/etc/init.d/clearvar b/target/linux/generic/base-files-lxc/etc/init.d/clearvar
new file mode 100755
index 0000000..46e6e54
--- /dev/null
+++ b/target/linux/generic/base-files-lxc/etc/init.d/clearvar
@@ -0,0 +1,12 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2013-2014 OpenWrt.org
+
+START=00
+
+boot() {
+ find /var -mindepth 1 ! -path '/var/run*' -print0 |xargs -0 rm -rf
+ find /tmp/run -mindepth 1 ! -name ubus.sock -print0 |xargs -0 rm -rf
+ mkdir /var/log /var/cache /var/state /var/etc /var/lock
+}
+
+
diff --git a/target/linux/generic/base-files-lxc/etc/inittab b/target/linux/generic/base-files-lxc/etc/inittab
new file mode 100644
index 0000000..3e83c29
--- /dev/null
+++ b/target/linux/generic/base-files-lxc/etc/inittab
@@ -0,0 +1,6 @@
+::sysinit:/etc/init.d/rcS S boot
+::shutdown:/etc/init.d/rcS K shutdown
+tty1::askfirst:/bin/ash --login
+tty2::askfirst:/bin/ash --login
+tty3::askfirst:/bin/ash --login
+tty4::askfirst:/bin/ash --login
diff --git a/target/linux/generic/base-files-lxc/etc/uci-defaults/disablelxcinitscripts b/target/linux/generic/base-files-lxc/etc/uci-defaults/disablelxcinitscripts
new file mode 100644
index 0000000..09bae86
--- /dev/null
+++ b/target/linux/generic/base-files-lxc/etc/uci-defaults/disablelxcinitscripts
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+/etc/init.d/sysntpd stop
+/etc/init.d/sysntpd disable
+/etc/inti.d/sysfixtime disable
+
diff --git a/target/linux/imx6/Makefile b/target/linux/imx6/Makefile
index cd938c8..4dea4a2 100644
--- a/target/linux/imx6/Makefile
+++ b/target/linux/imx6/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=arm
BOARD:=imx6
BOARDNAME:=Freescale i.MX 6
-FEATURES:=audio display fpu gpio pcie rtc usb usbgadget squashfs targz nand ubifs
+FEATURES:=audio display fpu gpio pcie rtc usb usbgadget squashfs targz lxc-targz nand ubifs
CPU_TYPE:=cortex-a9
CPU_SUBTYPE:=neon
MAINTAINER:=Luka Perkov <luka at openwrt.org>
diff --git a/target/linux/kirkwood/Makefile b/target/linux/kirkwood/Makefile
index 2db7e39..8faaba1 100644
--- a/target/linux/kirkwood/Makefile
+++ b/target/linux/kirkwood/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=arm
BOARD:=kirkwood
BOARDNAME:=Marvell Kirkwood
-FEATURES:=targz usb jffs2_nand nand ubifs squashfs
+FEATURES:=targz lxc-targz usb jffs2_nand nand ubifs squashfs
CPU_TYPE:=xscale
MAINTAINER:=Luka Perkov <luka at openwrt.org>
diff --git a/target/linux/omap/Makefile b/target/linux/omap/Makefile
index 20f7517..2b7fa21 100644
--- a/target/linux/omap/Makefile
+++ b/target/linux/omap/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=arm
BOARD:=omap
BOARDNAME:=TI OMAP3/4/AM33xx
-FEATURES:=usb usbgadget ext4 targz fpu audio display nand ubifs
+FEATURES:=usb usbgadget ext4 targz lxc-targz fpu audio display nand ubifs
CPU_TYPE:=cortex-a9
CPU_SUBTYPE:=vfpv3
diff --git a/target/linux/omap24xx/Makefile b/target/linux/omap24xx/Makefile
index 5dd5938..c1c622f 100644
--- a/target/linux/omap24xx/Makefile
+++ b/target/linux/omap24xx/Makefile
@@ -10,7 +10,7 @@ ARCH:=arm
BOARD:=omap24xx
BOARDNAME:=TI OMAP24xx
MAINTAINER:=Michael Buesch <m at bues.ch>
-FEATURES:=targz squashfs jffs2_nand usb usbgadget display gpio audio broken
+FEATURES:=targz lxc-targz squashfs jffs2_nand usb usbgadget display gpio audio broken
CPU_TYPE:=arm1136j-s
KERNEL_PATCHVER:=4.1
diff --git a/target/linux/orion/harddisk/target.mk b/target/linux/orion/harddisk/target.mk
index a3a0e41..b5b4472 100644
--- a/target/linux/orion/harddisk/target.mk
+++ b/target/linux/orion/harddisk/target.mk
@@ -6,7 +6,7 @@
#
BOARDNAME:=Internal Hard-Disk
-FEATURES:=targz
+FEATURES:=targz lxc-targz
define Target/Description
Build firmware images for Marvell Orion based boards that boot directly from internal disk storage.
diff --git a/target/linux/rb532/Makefile b/target/linux/rb532/Makefile
index e5c6ad7..6a50480 100644
--- a/target/linux/rb532/Makefile
+++ b/target/linux/rb532/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=mipsel
BOARD:=rb532
BOARDNAME:=Mikrotik RouterBoard 532
-FEATURES:=pci targz
+FEATURES:=pci targz lxc-targz
KERNEL_PATCHVER:=3.18
diff --git a/target/linux/x86/Makefile b/target/linux/x86/Makefile
index ba733c0..b20a849 100644
--- a/target/linux/x86/Makefile
+++ b/target/linux/x86/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=i386
BOARD:=x86
BOARDNAME:=x86
-FEATURES:=squashfs ext4 vdi vmdk pcmcia targz
+FEATURES:=squashfs ext4 vdi vmdk pcmcia targz lxc-targz
SUBTARGETS=generic xen_domu ep80579 geode kvm_guest rdc 64
MAINTAINER:=Felix Fietkau <nbd at openwrt.org>
diff --git a/target/linux/x86/xen_domu/target.mk b/target/linux/x86/xen_domu/target.mk
index 31d110c..397fc64 100644
--- a/target/linux/x86/xen_domu/target.mk
+++ b/target/linux/x86/xen_domu/target.mk
@@ -1,4 +1,4 @@
BOARDNAME:=Xen Paravirt Guest
DEFAULT_PACKAGES += kmod-xen-fs kmod-xen-evtchn kmod-xen-netdev kmod-xen-kbddev
-FEATURES:=display ext4 targz
+FEATURES:=display ext4 targz lxc-targz
CPU_TYPE := pentium4
diff --git a/target/linux/xburst/Makefile b/target/linux/xburst/Makefile
index 258a743..2291a97 100644
--- a/target/linux/xburst/Makefile
+++ b/target/linux/xburst/Makefile
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
ARCH:=mipsel
BOARD:=xburst
BOARDNAME:=Ingenic XBurst
-FEATURES:=targz nand ubifs audio
+FEATURES:=targz lxc-targz nand ubifs audio
SUBTARGETS:=qi_lb60
KERNEL_PATCHVER:=3.18
--
2.4.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list