Bug 4391 - Remove the obsolote images
Summary: Remove the obsolote images
Status: VERIFIED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: core (show other bugs)
Version: 1.5
Hardware: x86 Multiple
: Medium enhancement
Target Milestone: 1.5 M1
Assignee: Robert Yang
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2013-04-23 03:33 UTC by Robert Yang
Modified: 2013-06-05 05:31 UTC (History)
6 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Yang 2013-04-23 03:33:59 UTC
There would be many obsolote images under the deploy/images if we build the project many times, e.g.:

1.5G core-image-sato-sdk-qemumips-20130308094505.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130308094505.rootfs.tar.bz2
1.5G core-image-sato-sdk-qemumips-20130320102143.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130320102143.rootfs.tar.bz2
1.5G core-image-sato-sdk-qemumips-20130321070044.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130321070044.rootfs.tar.bz2
1.5G core-image-sato-sdk-qemumips-20130322111701.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130322111701.rootfs.tar.bz2
1.5G core-image-sato-sdk-qemumips-20130402095142.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130402095142.rootfs.tar.bz2
1.5G core-image-sato-sdk-qemumips-20130402123337.rootfs.ext3
248M core-image-sato-sdk-qemumips-20130402123337.rootfs.tar.bz2

They would use much disk space when time goes on.

I think that we can add a configure variable to remove them, e.g.:
RM_OLD_IMAGE = "1" (defult "0")

We have a symlink links to the previous current image, we can use "read link -f symlink" to remove the *old* image before we symlink the new image.

The affected files might be: (from a rough investigation)
bootimg.bbclass
image.bbclass
image_types.bbclass
image-vmdk.bbclass
boot-directdisk.bbclass
Comment 1 Saul Wold 2013-04-25 14:39:42 UTC
This should be part of the cleanup-workdir instead and not part of the bbclass files.
Comment 2 Robert Yang 2013-05-06 14:12:47 UTC
(In reply to comment #1)
> This should be part of the cleanup-workdir instead and not part of the
> bbclass files.

Hi Saul, thanks for your suggestion, but it seems that it is easy to use and implement if we do it in image_types.bbclass, here is the draft patch:

diff --git a/meta-yocto/conf/local.conf.sample.extended b/meta-yocto/conf/local.conf.sample.extended
index d0dff80..a7979e1 100644
--- a/meta-yocto/conf/local.conf.sample.extended
+++ b/meta-yocto/conf/local.conf.sample.extended
@@ -211,3 +211,6 @@
 # Put the following two lines in the conf file with intact.
 #ARCHIVER_CLASS = "${@'archive-${ARCHIVER_MODE}-source' if ARCHIVER_MODE != 'none' else ''}"
 #INHERIT += "${ARCHIVER_CLASS}"
+
+# Remove the obsolete image before the new one generated to save disk sapce
+#RM_OBSOLETE_IMAGE = "1"
diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass
index 94837ae..27f232e 100644
--- a/meta/classes/image_types.bbclass
+++ b/meta/classes/image_types.bbclass
@@ -51,7 +51,11 @@ def get_imagecmds(d):
         types.remove("live")
 
     if d.getVar('IMAGE_LINK_NAME', True):
-        cmds += "\trm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.*"
+        if d.getVar('RM_OBSOLETE_IMAGE', True) == "1":
+            # Remove the obsolete image
+            cmds += "\trm -f `find ${DEPLOY_DIR_IMAGE} -maxdepth 1 -type l -name ${IMAGE_LINK_NAME}'.*' -exec readlink -f {} \;`"
+        # Remove the symlink
+        cmds += "\n\trm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.*"
 
     for type in types:
         ccmd = []

If we do it in the cleanup-workdir script, we need consider which files should be kept when different archs and image recipes have been built, and we need to add an option for it to cleanup the DEPLOY_DIR_IMAGE directory rather than the work dir.
Comment 4 Robert Yang 2013-05-08 02:04:40 UTC
No, not merged, it is in review.
Comment 6 Ke Zou 2013-06-05 05:31:48 UTC
verified in yocto 1.5 
master git rev: 676fd3f394a0c0576b63c77ed2184bf5f42c29b6

Test step:
1.build any type of image in poky
2.change ${POKY}/build/conf/local.conf
  add line:  RM_OLD_IMAGE = 1
3.re-build image again
4.Last build in ${POKY}/build/tmp/deploy/images/  should be deleted