[Buildroot] [PATCH] Improved initramfs and iso target support (revised patch)
heiko at zuerker.org
heiko at zuerker.org
Mon Dec 6 14:24:28 UTC 2010
From: Heiko Zuerker <smiley73 at users.sourceforge.net>
A small initramfs is now supported in order to initialize the system.
New options to create a bootable CD with optional support for a
minimal initramfs, isolinux boot loader and zisofs have been added.
The iso filesystem doesn't need the ext2 image anymore, but the old
functionality is still available.
Signed-off-by: Heiko Zuerker <smiley73 at users.sourceforge.net>
---
fs/initramfs/Config.in | 55 ++++++++++++++++++++++++++++++++++++++++++++-
fs/initramfs/initramfs.mk | 41 +++++++++++++++++++++++++++++++++
fs/iso9660/Config.in | 44 ++++++++++++++++++++++++++++++++++-
fs/iso9660/iso9660.mk | 50 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 187 insertions(+), 3 deletions(-)
diff --git a/fs/initramfs/Config.in b/fs/initramfs/Config.in
index abb3c0c..596d323 100644
--- a/fs/initramfs/Config.in
+++ b/fs/initramfs/Config.in
@@ -1,6 +1,17 @@
-config BR2_TARGET_ROOTFS_INITRAMFS
+config BR2_TARGET_DO_INITRAMFS
bool "initramfs for initial ramdisk of linux kernel"
depends on BR2_LINUX_KERNEL
+
+menu "initramfs options"
+depends on BR2_TARGET_DO_INITRAMFS
+
+choice
+ prompt "initramfs type"
+ default BR2_TARGET_ROOTFS_INITRAMFS
+ depends on BR2_TARGET_DO_INITRAMFS
+
+config BR2_TARGET_ROOTFS_INITRAMFS
+ bool "full"
help
Integrate the root filesystem generated by Buildroot as an
initramfs inside the kernel image. This integration will
@@ -16,5 +27,47 @@ config BR2_TARGET_ROOTFS_INITRAMFS
identical root filesystems, one embedded inside the kernel
image, and one separatly.
+config BR2_TARGET_ROOTFS_MINI_INITRAMFS
+ bool "minimal"
+ help
+ Only create a minimal initramfs to prepare system for boot.
+ This is just like a initrd (initial ram disk).
+
+endchoice
+
+config BR2_TARGET_ROOTFS_MINI_INITRAMFS_COPYLIST
+ string "List with files to be copied"
+ depends on BR2_TARGET_DO_INITRAMFS
+ depends on BR2_TARGET_ROOTFS_MINI_INITRAMFS
+ default ""
+ help
+ The contents of this file list the files and directories
+ to be copied from the target file system.
+ All path names are relativ to the output/target directory.
+ This is an optional parameter.
+
+config BR2_TARGET_ROOTFS_MINI_INITRAMFS_SKELETON
+ string "initramfs skeleton"
+ depends on BR2_TARGET_DO_INITRAMFS
+ depends on BR2_TARGET_ROOTFS_MINI_INITRAMFS
+ default ""
+ help
+ A skeleton directory which is copied before any files
+ from the target filesystem are copied into the initramfs
+ directory structure.
+ This is an optional parameter.
+
+config BR2_TARGET_ROOTFS_MINI_INITRAMFS_INSTALL_BUSYBOX
+ bool "copy and install busybox"
+ depends on BR2_TARGET_DO_INITRAMFS
+ depends on BR2_TARGET_ROOTFS_MINI_INITRAMFS
+ help
+ Copy the busybox binary into the initramfs and create all
+ symlinks.
+ Busybox should be statically compiled for this.
+
+endmenu
+
comment "initramfs requires a Linux kernel to be built"
depends on !BR2_LINUX_KERNEL
+
diff --git a/fs/initramfs/initramfs.mk b/fs/initramfs/initramfs.mk
index 73122a8..fca7a67 100644
--- a/fs/initramfs/initramfs.mk
+++ b/fs/initramfs/initramfs.mk
@@ -6,6 +6,8 @@
#
#############################################################
+### use initramfs for the full target file system
+ifeq ($(BR2_TARGET_ROOTFS_INITRAMFS),y)
define ROOTFS_INITRAMFS_INIT_SYMLINK
if [ ! -e $(TARGET_DIR)/init ]; then \
ln -sf sbin/init $(TARGET_DIR)/init; \
@@ -21,3 +23,42 @@ endef
ROOTFS_INITRAMFS_POST_TARGETS += linux26-rebuild-with-initramfs
$(eval $(call ROOTFS_TARGET,initramfs))
+endif
+### end full target on initramfs
+
+### create a minimal initramfs
+extradeps=
+INITRAMFSTMPDIR=$(BUILD_DIR)/initramfs.tmp
+
+ifeq ($(BR2_TARGET_ROOTFS_MINI_INITRAMFS_INSTALL_BUSYBOX),y)
+ extradeps += busybox
+endif
+
+$(BINARIES_DIR)/initramfs.gz: $(extradeps)
+ @$(call MESSAGE,"Generating root filesystem image initramfs.gz")
+ -rm -rf $(INITRAMFSTMPDIR)
+ mkdir -p $(INITRAMFSTMPDIR)
+ifneq ($(BR2_TARGET_ROOTFS_MINI_INITRAMFS_SKELETON),"")
+ cp -dpfR $(BR2_TARGET_ROOTFS_MINI_INITRAMFS_SKELETON)/* $(INITRAMFSTMPDIR)/
+endif
+ifneq ($(BR2_TARGET_ROOTFS_MINI_INITRAMFS_COPYLIST),"")
+ for FILE in `cat $(BR2_TARGET_ROOTFS_MINI_INITRAMFS_COPYLIST)` ; do cp -dpfR $(TARGET_DIR)/$${FILE} $(INITRAMFSTMPDIR)/ ; done
+endif
+ifeq ($(BR2_TARGET_ROOTFS_MINI_INITRAMFS_INSTALL_BUSYBOX),y)
+ cp $(TARGET_DIR)/bin/busybox $(INITRAMFSTMPDIR)/bin/
+ # if neccessary, create missing busybox.links
+ test -e $(BUSYBOX_DIR)/busybox.links || make -C $(BUSYBOX_DIR) busybox.links
+ for LINK in `cat $(BUSYBOX_DIR)/busybox.links | grep -v linuxrc` ; do ln -sf ../bin/busybox $(INITRAMFSTMPDIR)$${LINK}; done
+endif
+ pushd $(INITRAMFSTMPDIR); find . | cpio -H newc -o -O $(BINARIES_DIR)/initramfs; popd
+ -rm -rf $(INITRAMFSTMPDIR)
+ gzip -f -9 $(BINARIES_DIR)/initramfs
+
+mini-initramfs: $(BINARIES_DIR)/initramfs.gz
+
+ifeq ($(BR2_TARGET_ROOTFS_MINI_INITRAMFS),y)
+#TARGETS+=mini-initramfs
+$(eval $(call ROOTFS_TARGET,mini-initramfs))
+endif
+
+### end minimal initramfs
diff --git a/fs/iso9660/Config.in b/fs/iso9660/Config.in
index 4c00583..2e4c375 100644
--- a/fs/iso9660/Config.in
+++ b/fs/iso9660/Config.in
@@ -2,15 +2,55 @@ config BR2_TARGET_ROOTFS_ISO9660
bool "iso image"
depends on (BR2_i386 || BR2_x86_64)
depends on BR2_LINUX_KERNEL
- select BR2_TARGET_ROOTFS_EXT2
- select BR2_TARGET_GRUB
help
Build a bootable iso9660 image
+menu "iso image options"
+depends on BR2_TARGET_ROOTFS_ISO9660
+
+choice
+ prompt "Bootloader"
+ default BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_ISOLINUX
+ depends on BR2_TARGET_ROOTFS_ISO9660
+ help
+ Select compressor for ext2 filesystem of the root filesystem
+
+config BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_ISOLINUX
+ bool "isolinux"
+ select BR2_TARGET_SYSLINUX
+ help
+ Use isolinux from syslinux package as the boot loader
+
+config BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_GRUB
+ bool "grub"
+ depends on BR2_i386
+ select BR2_TARGET_GRUB
+ select BR2_TARGET_ROOTFS_EXT2
+ help
+ Use grub as the boot loader
+endchoice
+
config BR2_TARGET_ROOTFS_ISO9660_BOOT_MENU
string "Boot menu.lst file"
depends on BR2_TARGET_ROOTFS_ISO9660
default "fs/iso9660/menu.lst"
+config BR2_TARGET_ROOTFS_ISO9660_COPY_INITRAMFS
+ bool "copy initramfs into /boot"
+ select BR2_TARGET_DO_INITRAMFS
+ select BR2_PACKAGE_BUSYBOX
+ depends on BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_ISOLINUX
+
+config BR2_TARGET_ROOTFS_ISO9660_COMPRESS
+ bool "compress ISO image contents"
+ depends on BR2_TARGET_DO_INITRAMFS
+ depends on BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_ISOLINUX
+ help
+ Compresses the contents of the ISO image via mkzftree, creating
+ a ZISOFS.
+ You'll need a kernel with the CONFIG_ZISOFS option enabled.
+
+endmenu
+
comment "iso image requires a Linux kernel to be built"
depends on (BR2_i386 || BR2_x86_64) && !BR2_LINUX_KERNEL
diff --git a/fs/iso9660/iso9660.mk b/fs/iso9660/iso9660.mk
index 2a5288c..2a92497 100644
--- a/fs/iso9660/iso9660.mk
+++ b/fs/iso9660/iso9660.mk
@@ -15,6 +15,8 @@ ifeq ($(BR2_TARGET_ROOTFS_ISO9660_SQUASH),y)
ISO9660_OPTS+=-U
endif
+### using grub as a boot loader and using the ext2 image
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_GRUB),y)
$(BINARIES_DIR)/rootfs.iso9660: host-cdrkit host-fakeroot linux26 rootfs-ext2 grub
@$(call MESSAGE,"Generating root filesystem image rootfs.iso9660")
mkdir -p $(ISO9660_TARGET_DIR)
@@ -36,7 +38,55 @@ $(BINARIES_DIR)/rootfs.iso9660: host-cdrkit host-fakeroot linux26 rootfs-ext2 gr
$(HOST_DIR)/usr/bin/fakeroot -- $(FAKEROOT_SCRIPT)
- at rm -f $(FAKEROOT_SCRIPT)
- at rm -rf $(ISO9660_TARGET_DIR)
+endif
+
+### using isolinux and the files directly on the CD
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_BOOTLOADER_ISOLINUX),y)
+
+extradeps=
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_COPY_INITRAMFS),y)
+ extradeps += mini-initramfs
+endif
+
+ISO9660_SOURCE_DIR = $(TARGET_DIR)
+
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_COMPRESS),y)
+ extradeps += host-zisofs-tools
+ ISO9660_SOURCE_DIR = $(BUILD_DIR)/iso9660.tmp
+endif
+$(BINARIES_DIR)/rootfs.iso9660: host-cdrkit linux26 syslinux $(extradeps)
+ @$(call MESSAGE,"Generating root filesystem image rootfs.iso9660")
+ genisoimage_extraoptions=
+ # Get the boot loader and kernel ready
+ mkdir -p $(TARGET_DIR)/boot/isolinux
+ cp $(BINARIES_DIR)/isolinux.bin $(TARGET_DIR)/boot/isolinux/
+ cp $(ISO9660_BOOT_MENU) $(TARGET_DIR)/boot/isolinux/isolinux.cfg
+ cp $(LINUX26_IMAGE_PATH) $(TARGET_DIR)/boot/kernel
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_COPY_INITRAMFS),y)
+ cp $(BINARIES_DIR)/initramfs.gz $(TARGET_DIR)/boot/
+endif
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_COMPRESS),y)
+ # create the ZISOFS
+ genisoimage_extraoptions=-z
+ -rm -rf $(ISO9660_SOURCE_DIR)
+ @$(call MESSAGE,"Compressing iso filesystem...")
+ $(HOST_DIR)/usr/bin/mkzftree -z 9 -p $(BR2_JLEVEL) $(TARGET_DIR) $(ISO9660_SOURCE_DIR)
+ # now we need to restore the files which shouldn't be compressed
+ rm -rf $(ISO9660_SOURCE_DIR)/boot
+ cp -fdpR $(TARGET_DIR)/boot $(ISO9660_SOURCE_DIR)/
+endif
+ # Let's create the ISO image
+ $(HOST_DIR)/usr/bin/genisoimage -R -b boot/isolinux/isolinux.bin -c boot/boot.cat -no-emul-boot \
+ -boot-load-size 4 -boot-info-table -o $@ \
+ -J -l -R -iso-level 2 $(genisoimage_extraoptions) \
+ -allow-leading-dots -allow-lowercase -allow-multidot \
+ $(ISO9660_SOURCE_DIR)
+ifeq ($(BR2_TARGET_ROOTFS_ISO9660_COMPRESS),y)
+ rm -rf $(ISO9660_SOURCE_DIR)
+endif
+endif
+
rootfs-iso9660: $(BINARIES_DIR)/rootfs.iso9660
#############################################################
--
1.7.3.2
More information about the buildroot
mailing list