New image target (x86/x64): raw disk image
cover New image target (x86/x64): raw disk image
These 2 patches allow the building of a new image for x86 and x64. The "raw" image is a disk image, with a valid partition table and MBR, that can directly written to a disk and will boot, or the file is bootable in QEMU. Also cloud providers who use KVM (like Google) should accept this as their VM image format.
Karoly Kasza (2):
util-linux: option to enable fdisk for host build fs/rawimage: new rootfs image
fs/Config.in | 1 + fs/rawimg/Config.in | 17 ++++++++++ fs/rawimg/genrawimg.sh | 35 ++++++++++++++++++++ fs/rawimg/rawimg.mk | 13 ++++++++ package/util-linux/Config.in.host | 9 +++++ .../util-linux/util-linux-004-enable-fdisk.patch | 34 +++++++++++++++++++ package/util-linux/util-linux.mk | 5 +++ 7 files changed, 114 insertions(+) create mode 100644 fs/rawimg/Config.in create mode 100755 fs/rawimg/genrawimg.sh create mode 100644 fs/rawimg/rawimg.mk create mode 100644 package/util-linux/util-linux-004-enable-fdisk.patch
Signature · 1 line
1.7.10.4
PATCH 1/2 util-linux: option to enable fdisk for host build
Enable the building of fdisk utility in util-linux host build.
Signed-off-by Karoly Kasza <[email protected]>
--- package/util-linux/Config.in.host | 9 ++++++ .../util-linux/util-linux-004-enable-fdisk.patch | 34 ++++++++++++++++++++ package/util-linux/util-linux.mk | 5 +++ 3 files changed, 48 insertions(+) create mode 100644 package/util-linux/util-linux-004-enable-fdisk.patch
package/util-linux/Config.in.host +9 -0
@@ -6,3 +6,12 @@ config BR2_PACKAGE_HOST_UTIL_LINUX Things like mkfs, mkswap, swapon, fdisk, mount, dmesg, etc... http://www.kernel.org/pub/linux/utils/util-linux/ + +if BR2_PACKAGE_HOST_UTIL_LINUX + +config BR2_PACKAGE_HOST_UTIL_LINUX_FDISK + bool "enable fdisk" + help + Enable compiling fdisk + +endif
package/util-linux/util-linux-004-enable-fdisk.patch new file +34 -0
@@ -0,0 +1,34 @@ +Add options to enable/disable libfdisk and fdisk + +This is needed to be able to just build an fdisk binary +for the host package. + +Signed-off-by: Karoly Kasza <[email protected]> + +--- util-linux-2.25.1.orig/configure.ac 2014-10-11 13:47:52.000000000 +0200 ++++ util-linux-2.25.1/configure.ac 2014-10-11 13:45:50.065076171 +0200 +@@ -820,12 +820,22 @@ + dnl + dnl libfdisk is enabled at all times if possible + dnl +-UL_BUILD_INIT([libfdisk], [check]) ++# this behaviour changed for buildroot, along with fdisk ++AC_ARG_ENABLE([libfdisk], ++ AS_HELP_STRING([--disable-libfdisk], [do not build libfdisk]), ++ [], [UL_DEFAULT_ENABLE([libfdisk], [check])] ++) ++UL_BUILD_INIT([libfdisk]) + UL_REQUIRES_BUILD([libfdisk], [libuuid]) + UL_REQUIRES_BUILD([libfdisk], [libsmartcols]) + AM_CONDITIONAL([BUILD_LIBFDISK], [test "x$build_libfdisk" = xyes]) + +-UL_BUILD_INIT([fdisk], [check]) ++ ++AC_ARG_ENABLE([fdisk], ++ AS_HELP_STRING([--disable-fdisk], [do not build fdisk]), ++ [], [UL_DEFAULT_ENABLE([fdisk], [check])] ++) ++UL_BUILD_INIT([fdisk]) + UL_REQUIRES_BUILD([fdisk], [libfdisk]) + AM_CONDITIONAL([BUILD_FDISK], [test "x$build_fdisk" = xyes]) +
package/util-linux/util-linux.mk +5 -0
@@ -97,6 +97,11 @@ HOST_UTIL_LINUX_CONF_OPTS += \ --disable-libblkid --disable-libmount \ --disable-all-programs --without-ncurses +# Build host fdisk if selected +ifeq ($(BR2_PACKAGE_HOST_UTIL_LINUX_FDISK),y) +HOST_UTIL_LINUX_CONF_OPTS += --enable-fdisk --enable-libfdisk --enable-libsmartcols +endif + # Avoid building the tools if they are disabled since we can't install on # a per-directory basis. ifeq ($(BR2_PACKAGE_UTIL_LINUX_BINARIES),)
Signature · 1 line
1.7.10.4
PATCH 2/2 fs/rawimage: new rootfs image
In reply to Karoly KaszaCreates a bootable raw disk image as a new rootfs image. Boots in QEMU or on bare metal after written (dd) to disk.
Signed-off-by Karoly Kasza <[email protected]>
--- fs/Config.in | 1 + fs/rawimg/Config.in | 17 +++++++++++++++++ fs/rawimg/genrawimg.sh | 35 +++++++++++++++++++++++++++++++++++ fs/rawimg/rawimg.mk | 13 +++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 fs/rawimg/Config.in create mode 100755 fs/rawimg/genrawimg.sh create mode 100644 fs/rawimg/rawimg.mk
fs/Config.in +1 -0
@@ -8,6 +8,7 @@ source "fs/initramfs/Config.in" source "fs/iso9660/Config.in" source "fs/jffs2/Config.in" source "fs/romfs/Config.in" +source "fs/rawimg/Config.in" source "fs/squashfs/Config.in" source "fs/tar/Config.in" source "fs/ubifs/Config.in"
fs/rawimg/Config.in new file +17 -0
@@ -0,0 +1,17 @@ +config BR2_TARGET_ROOTFS_RAWIMG + bool "raw disk image" + depends on (BR2_i386 || BR2_x86_64) + depends on BR2_LINUX_KERNEL + select BR2_LINUX_KERNEL_INSTALL_TARGET + select BR2_TARGET_ROOTFS_EXT2 + select BR2_TARGET_GRUB + select BR2_TARGET_GRUB_FS_EXT2 + select BR2_PACKAGE_HOST_UTIL_LINUX + select BR2_PACKAGE_HOST_UTIL_LINUX_FDISK + help + Build a bootable raw disk image, that can be booted in a VM (e.g. QEMU), + or directly written to disk. Creates a valid partition table with MBR. + +comment "raw disk image needs a Linux kernel to be built" + depends on BR2_i386 || BR2_x86_64 + depends on !BR2_LINUX_KERNEL
fs/rawimg/genrawimg.sh new file +35 -0
@@ -0,0 +1,35 @@ +#!/bin/sh +set -e + +BINARIES_DIR="$1" +OUTPUT_IMG="$2" +# Size of generated ext2 fs +EXT2SIZE=`ls -l $BINARIES_DIR/rootfs.ext2 | cut -d' ' -f5` +# Size of image with MBR and partition table (512 block size with fdisk image file) +# Add 2048 blocks to beginning & end of file +IMGCOUNT=$(($EXT2SIZE/512+2048+2048)) + +# Create an empty file, final size +dd if=/dev/zero of=$OUTPUT_IMG bs=512 count=$IMGCOUNT 2>/dev/null + +# Create a partition table - call our own fdisk in $PATH from host-util-linux +fdisk $OUTPUT_IMG >/dev/null 2>/dev/null <<EOB +n +p +1 + + +w +EOB + +# Write the ext2 rootfs to the 1st partition +dd if=$BINARIES_DIR/rootfs.ext2 of=$OUTPUT_IMG conv=notrunc bs=512 iflag=fullblock seek=2048 skip=0 2>/dev/null + +# Write MBR, grub is also called from $PATH +grub --no-floppy --batch >/dev/null 2>/dev/null <<EOB +device (hd0) $OUTPUT_IMG +geometry (hd0) +root (hd0,0) +setup (hd0) +quit +EOB
fs/rawimg/rawimg.mk new file +13 -0
@@ -0,0 +1,13 @@ +################################################################################ +# +# Build the raw disk image +# +################################################################################ + +ROOTFS_RAWIMG_DEPENDENCIES = rootfs-ext2 + +define ROOTFS_RAWIMG_CMD + PATH=$(BR_PATH) fs/rawimg/genrawimg.sh $(BINARIES_DIR) $@ +endef + +$(eval $(call ROOTFS_TARGET,rawimg))
Signature · 1 line
1.7.10.4