Hi All,

I've created a patch to fix this issue.
It can be enabled by setting  SEPARATE_ROOTFS = "1"  in local.conf.
Rootfs.img is then put into a separate ext3 partition.

In hope it will be useful.

---
Petr

On Thu, Dec 4, 2014 at 11:25 PM, Gary Robertson <[email protected]>
wrote:
>
> AFAIK, the reasons for using FAT are:
> (1) it is the most universally accepted filesystem format for devices and
> OS environments,
> (2) it is usable with almost all boot loaders produced anywhere by anyone,
> and
> (3) it is the de facto standard format for flash-based devices of all types
>
> Your solution of creating a small FAT partition for booting and ext3 for
> the root filesystem is probably
> the cleanest way of implementing large filesystem images for a Linux
> environment.
>
>
> On Thu, Dec 4, 2014 at 2:10 PM, Petr Nechaev <
> [email protected]> wrote:
>
>> Hi All,
>>
>>  I'm using oe-core for building images and have a problem. Rootfs.img is
>> over 5GB and cannot be copied to FAT32 partition because of file size
>> limit. This happens during do_bootimg task for core-image-sato-sdk. No
>> warning is given by bitbake.
>>  The problem occurs in build_fat_img() function in bootimg.bbclass.
>>
>>  I have temporarily fixed the problem in my build by extending
>> bootimg.bbclass. I added new function which first splits *.hddimg into two
>> partitions: FAT + ext3 and then puts rootfs.img to ext3 partition.
>>
>>  But, what is the right way of building core-image-sato-sdk with large
>> rootfs? And what is the technical reason behind putting rootfs.img into a
>> FAT partition?
>>
>> ---
>> Petr
>>
>> --
>> _______________________________________________
>> Openembedded-core mailing list
>> [email protected]
>> http://lists.openembedded.org/mailman/listinfo/openembedded-core
>>
>>
>
From 388389b353dcfe4315a14ce58a72e30abf961a00 Mon Sep 17 00:00:00 2001
From: Petr Nechaev <[email protected]>
Date: Fri, 12 Dec 2014 14:03:25 +0300
Subject: [PATCH] Modified bootimg.bbclass to support rootfs over 4GB

Fixed a problem when rootfs.img is over 4GB and cannot be copied to a
FAT32 partition. Added build_two_partitions() which first splits
*.hddimg into two partitions: FAT + ext3 and then puts rootfs.img to
ext3 partition.
---
 meta/classes/bootimg.bbclass | 102 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 97 insertions(+), 5 deletions(-)

diff --git a/meta/classes/bootimg.bbclass b/meta/classes/bootimg.bbclass
index 859d517..2ced8c3 100644
--- a/meta/classes/bootimg.bbclass
+++ b/meta/classes/bootimg.bbclass
@@ -36,6 +36,7 @@ EXCLUDE_FROM_WORLD = "1"
 HDDDIR = "${S}/hddimg"
 ISODIR = "${S}/iso"
 EFIIMGDIR = "${S}/efi_img"
+ROOTFSDIR = "${S}/rootfs_img"
 COMPACT_ISODIR = "${S}/iso.z"
 COMPRESSISO ?= "0"
 
@@ -57,12 +58,16 @@ def pcbios(d):
 
 PCBIOS = "${@pcbios(d)}"
 
+# set this enable creation of large images with separate rootfs partition
+SEPARATE_ROOTFS ?= "0"
+
 # The syslinux is required for the isohybrid command and boot catalog
 inherit syslinux
 inherit ${EFI_CLASS}
 
 populate() {
 	DEST=$1
+	DO_NOT_MAKE_ROOTFS=$2
 	install -d ${DEST}
 
 	# Install bzImage, initrd, and rootfs.img in DEST for all loaders to use.
@@ -82,7 +87,7 @@ populate() {
 		chmod 0644 ${DEST}/initrd
 	fi
 
-	if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ]; then
+	if [ -n "${ROOTFS}" ] && [ -s "${ROOTFS}" ] && [ ! "${DO_NOT_MAKE_ROOTFS}" = "1" ]; then
 		install -m 0644 ${ROOTFS} ${DEST}/rootfs.img
 	fi
 
@@ -104,7 +109,7 @@ build_iso() {
 	done
 
 
-	populate ${ISODIR}
+	populate ${ISODIR} 1
 
 	if [ "${PCBIOS}" = "1" ]; then
 		syslinux_iso_populate ${ISODIR}
@@ -225,10 +230,83 @@ build_fat_img() {
 	mcopy -i ${FATIMG} -s ${FATSOURCEDIR}/* ::/
 }
 
+
+build_two_partitions() {
+	FAT_IMG=$1
+	ROOT_FS=$2
+	HDDIMG=$3
+	# combine two partitions into single image file
+	
+	# calculate partition sizes
+	ROOTFS_SIZE=$(stat -Lc%s ${ROOT_FS})
+	FATIMG_SIZE=$(stat -Lc%s ${FAT_IMG})
+	ROOTFS_SIZE_M=$(expr $ROOTFS_SIZE /  1024 / 1024  + 1 + 100)
+	FATIMG_SIZE_M=$(expr $FATIMG_SIZE /  1024 / 1024  + 1)
+	DISK_SIZE_M=$(expr $ROOTFS_SIZE_M + $FATIMG_SIZE_M  + 50 )
+	# overhead isn't so important because we'll use this approach only for large images
+
+	# create sparse image
+	dd if=/dev/zero of="${HDDIMG}" seek="${DISK_SIZE_M}"M bs=1 count=0 
+	
+	# create two partitions
+	# TODO: setup proper geometry first
+	cmd="p\no\n"
+	# create first partition for FAT
+	cmd="${cmd}n\np\n1\n\n+${FATIMG_SIZE_M}M\n"
+	# change type to FAT
+	cmd="${cmd}t\nb\n"
+	# create second partition for rootfs
+	cmd="${cmd}n\np\n2\n\n+${ROOTFS_SIZE_M}M\n"
+	# make the first partition bootable
+	cmd="${cmd}a\n1\n"
+	# print and write changes to disk
+	cmd="${cmd}p\nw\n"
+	echo -e "${cmd}" | fdisk "${HDDIMG}"
+
+	# mount these partitions
+	devices=$(sudo kpartx -asv "${HDDIMG}")
+	fat_loop=$(echo "${devices}" | sed -n '1 s/.*\(loop[0-9]*p[0-9]*\).*/\1/p')
+	rootfs_loop=$(echo "${devices}" | sed -n '2 s/.*\(loop[0-9]*p[0-9]*\).*/\1/p')
+
+	#echo -e "echo=$fat_loop \n echo=$rootfs_loop \n"
+
+	# check that we have two partitions
+	if [ -z "${fat_loop}" ] || [ -z "${rootfs_loop}" ]; then
+		# cleanup
+		sudo kpartx -dsv "${HDDIMG}"
+
+		# and fail
+		bbfatal "Creation of the disk failed."
+	fi
+
+	# dd fat image 
+	sudo dd if="${FAT_IMG}" of="/dev/mapper/${fat_loop}" bs=1M
+
+	# Create ext3 fs
+	sudo mkfs -t ext3 "/dev/mapper/${rootfs_loop}"
+	sync
+	mkdir -p "${ROOTFSDIR}"
+	sudo mount "/dev/mapper/${rootfs_loop}" "${ROOTFSDIR}"
+	
+	# copy the file
+	sudo install -m 0644 ${ROOT_FS} "${ROOTFSDIR}"/rootfs.img
+
+	# sync to be safe
+	sync
+
+	# unmount 
+	sudo umount "${ROOTFSDIR}"
+
+	# unmont these partitions
+	sudo kpartx -dsv "${HDDIMG}"
+
+	# we're ready
+}
+
 build_hddimg() {
 	# Create an HDD image
 	if [ "${NOHDD}" != "1" ] ; then
-		populate ${HDDDIR}
+		populate ${HDDDIR} ${SEPARATE_ROOTFS}
 
 		if [ "${PCBIOS}" = "1" ]; then
 			syslinux_hddimg_populate ${HDDDIR}
@@ -237,14 +315,28 @@ build_hddimg() {
 			efi_hddimg_populate ${HDDDIR}
 		fi
 
-		build_fat_img ${HDDDIR} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
+		# create FAT in a separate image file when building two partitions
+		if [ "${SEPARATE_ROOTFS}" = "1" ]; then
+			FAT_IMAGE="${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.fatimg"
+		else
+			FAT_IMAGE="${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg"
+		fi
+
+		# build FAT qith a bootloader first
+		build_fat_img ${HDDDIR} ${FAT_IMAGE}
 
 		if [ "${PCBIOS}" = "1" ]; then
-			syslinux_hddimg_install
+			syslinux_hdddirect_install ${FAT_IMAGE} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
+		fi
+
+		# combine two images if needed
+		if [ "${SEPARATE_ROOTFS}" = "1" ]; then
+			build_two_partitions ${FAT_IMAGE} ${ROOTFS} ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
 		fi
 
 		chmod 644 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.hddimg
 
+		# link generic name to the lastest image
 		cd ${DEPLOY_DIR_IMAGE}
 		rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hddimg
 		ln -s ${IMAGE_NAME}.hddimg ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.hddimg
-- 
1.9.3

-- 
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core

Reply via email to