专栏首页hank【分享】优化rootfs的大小

【分享】优化rootfs的大小

1. 介绍

Xilinx VCU TRD 集成了图像和视频编解码功能,生成的根文件系统比较大,2020.1的rootfs.cpio.gz大约有114MB。工程师可以根据自己需要裁剪,减少根文件系统大小。 在Ubuntu下,解压rootfs.cpio.gz,得到rootfs.cpio,再解压,得到就是文件了。

2. 检查目录大小

使用du命令,可以检查各个文件夹的大小。

rootfs@rootfs$ du --max-depth=1 -h
4.0K	./run
8.5M	./lib
20K	./home
4.0K	./boot
4.0K	./tmp
4.0K	./sys
2.9M	./bin
4.0K	./mnt
312M	./usr
112K	./var
2.8M	./opt
2.0M	./etc
8.0K	./media
4.0K	./dev
4.0K	./proc
2.0M	./sbin
330M	

也可以看更深的目录,排除占用空间小的目录。

rootfs@rootfs$ du --max-depth=2 -h | grep [0-9]M
3.1M	./lib/modules
8.5M	./lib
2.9M	./bin
206M	./usr/lib
22M	./usr/bin
1.3M	./usr/libexec
80M	./usr/share
3.8M	./usr/sbin
312M	./usr
2.8M	./opt/vcu_qt
2.8M	./opt
2.0M	./etc
2.0M	./sbin
330M	.
rootfs$ du --max-depth=2 -h | grep [0-9]M
5.9M	./lib
2.9M	./bin
18M	./usr/lib
5.1M	./usr/bin
6.2M	./usr/share
3.3M	./usr/sbin
33M	./usr
2.0M	./sbin
45M	.

3. 检查文件大小

目录大小有助于粗略的分析根文件系统大小。要找到真正的原因,并找到减小根文件系统大小,需要分析文件大小。 使用find命令,找到文件,再使用ls命令,查看文件大小;最后使用grep命令过滤出大文件。

rootfs$ find | xargs -n 1 ls -l -h | grep [0-9]M
total 4.3M
-rwxr-xr-x 1 hankf hankf 1.4M May 27 13:58 libc-2.30.so
-rwxr-xr-x 1 hankf hankf 1.4M May 27 13:58 ./lib/libc-2.30.so
total 2.9M
-rwxr-xr-x 1 hankf hankf 1.2M May 27 14:07 bash.bash
-rwsr-xr-x 1 hankf hankf 1.6M May 27 14:09 busybox
-rwsr-xr-x 1 hankf hankf 1.6M May 27 14:09 ./bin/busybox
-rwxr-xr-x 1 hankf hankf 1.2M May 27 14:07 ./bin/bash.bash
total 105M
-rwxr-xr-x  1 hankf hankf 1.1M May 27 14:07 libasound.so.2.0.0
-rwxr-xr-x  1 hankf hankf 1.2M May 27 05:01 libcairo.so.2.11600.0
-rwxr-xr-x  1 hankf hankf 2.5M May 27 14:04 libcrypto.so.1.1
-rwxr-xr-x  1 hankf hankf 1.3M May 27 05:00 libepoxy.so.0.0.0
-rwxr-xr-x  1 hankf hankf 1.9M May 27 14:11 libgio-2.0.so.0.6000.7
-rwxr-xr-x  1 hankf hankf 1.2M May 27 14:11 libglib-2.0.so.0.6000.7
-rwxr-xr-x  1 hankf hankf 1.8M May 27 14:13 libgnutls.so.30.24.0
-rwxr-xr-x  1 hankf hankf 1.3M May 27 14:20 libgstreamer-1.0.so.0.1601.0
-rwxr-xr-x  1 hankf hankf 7.2M May 27 05:06 libgtk-3.so.0.2404.4
-r-xr-xr-x  1 hankf hankf 3.0M May 27 14:11 libpython3.7m.so.1.0
-rwxr-xr-x  1 hankf hankf 1.9M May 27 05:27 libQt5Charts.so.5.13.2
-rwxr-xr-x  1 hankf hankf 6.3M May 27 05:18 libQt5Core.so.5.13.2
-rwxr-xr-x  1 hankf hankf 5.8M May 27 05:18 libQt5Gui.so.5.13.2
-rwxr-xr-x  1 hankf hankf 1.9M May 27 05:18 libQt5Network.so.5.13.2
-rwxr-xr-x  1 hankf hankf 4.9M May 27 05:23 libQt5Qml.so.5.13.2
-rwxr-xr-x  1 hankf hankf 4.9M May 27 05:23 libQt5Quick.so.5.13.2
-rwxr-xr-x  1 hankf hankf 1.1M May 27 05:26 libQt5WaylandClient.so.5.13.2
-rwxr-xr-x  1 hankf hankf 1.6M May 27 05:26 libQt5WaylandCompositor.so.5.13.2
-rwxr-xr-x  1 hankf hankf 6.8M May 27 05:18 libQt5Widgets.so.5.13.2
-rwxr-xr-x  1 hankf hankf 1.3M May 27 05:18 libQt5XcbQpa.so.5.13.2
-rwxr-xr-x  1 hankf hankf 1.5M May 27 14:10 libsamplerate.so.0.1.8
-rwxr-xr-x  1 hankf hankf 1.1M May 27 14:05 libsqlite3.so.0.8.6
-rwxr-xr-x  1 hankf hankf 1.8M May 27 14:02 libstdc++.so.6.0.27
-rwxr-xr-x  1 hankf hankf 1.5M May 27 14:08 libunistring.so.2.1.0
-rwxr-xr-x  1 hankf hankf 1.5M May 27 14:03 libvpx.so.6.1.0
-rwxr-xr-x  1 hankf hankf 1.3M May 27 14:07 libX11.so.6.3.0
-rwxr-xr-x  1 hankf hankf 1.4M May 27 14:14 libxml2.so.2.9.9
-r-xr-xr-x 1 hankf hankf 3.0M May 27 14:11 ./usr/lib/libpython3.7m.so.1.0
-rwxr-xr-x 1 hankf hankf 1.9M May 27 05:18 ./usr/lib/libQt5Network.so.5.13.2
-rwxr-xr-x 1 hankf hankf 1.5M May 27 14:10 ./usr/lib/libsamplerate.so.0.1.8
-rwxr-xr-x 1 hankf hankf 6.3M May 27 05:18 ./usr/lib/libQt5Core.so.5.13.2
-rwxr-xr-x 1 hankf hankf 1.5M May 27 14:08 ./usr/lib/libunistring.so.2.1.0
-rwxr-xr-x 1 hankf hankf 4.9M May 27 05:23 ./usr/lib/libQt5Quick.so.5.13.2
total 1.7M
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 libMali.so.9.0
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 ./usr/lib/x11/libMali.so.9.0
-rwxr-xr-x 1 hankf hankf 1.1M May 27 05:26 ./usr/lib/libQt5WaylandClient.so.5.13.2
-rwxr-xr-x 1 hankf hankf 6.8M May 27 05:18 ./usr/lib/libQt5Widgets.so.5.13.2
-rwxr-xr-x 1 hankf hankf 1.2M May 27 05:01 ./usr/lib/libcairo.so.2.11600.0
total 1.7M
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 libMali.so.9.0
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 ./usr/lib/headless/libMali.so.9.0
-rwxr-xr-x 1 hankf hankf 1.8M May 27 14:13 ./usr/lib/libgnutls.so.30.24.0
-rwxr-xr-x 1 hankf hankf 1.9M May 27 05:27 ./usr/lib/libQt5Charts.so.5.13.2
total 4.7M
total 4.6M
-rwxr-xr-x 1 hankf hankf 1.1M May 27 14:11 unicodedata.cpython-37m-aarch64-linux-gnu.so
-rwxr-xr-x 1 hankf hankf 1.1M May 27 14:11 ./usr/lib/python3.7/lib-dynload/unicodedata.cpython-37m-aarch64-linux-gnu.so
total 1.2M
total 2.0M
total 2.0M
-rw-r--r-- 1 hankf hankf 1.4M May 27 14:11 pip-19.2.3-py2.py3-none-any.whl
-rw-r--r-- 1 hankf hankf 1.4M May 27 14:11 ./usr/lib/python3.7/ensurepip/_bundled/pip-19.2.3-py2.py3-none-any.whl
total 1.8M
total 1.8M
total 1.3M
total 9.6M
ls: cannot access './usr/lib/python3.7/site-packages/setuptools/script': No such file or directory
ls: cannot access '(dev).tmpl': No such file or directory
ls: cannot access './usr/lib/python3.7/site-packages/setuptools/command/launcher': No such file or directory
ls: cannot access 'manifest.xml': No such file or directory
total 2.3M
total 1.1M
total 1.1M
-rwxr-xr-x 1 hankf hankf 1.3M May 27 05:18 ./usr/lib/libQt5XcbQpa.so.5.13.2
-rwxr-xr-x 1 hankf hankf 1.2M May 27 14:11 ./usr/lib/libglib-2.0.so.0.6000.7
-rwxr-xr-x 1 hankf hankf 1.9M May 27 14:11 ./usr/lib/libgio-2.0.so.0.6000.7
total 2.9M
-rw-r--r-- 1 hankf hankf 2.9M Jul 15 17:38 locale-archive
-rw-r--r-- 1 hankf hankf 2.9M Jul 15 17:38 ./usr/lib/locale/locale-archive
-rwxr-xr-x 1 hankf hankf 4.9M May 27 05:23 ./usr/lib/libQt5Qml.so.5.13.2
total 1.4M
total 1.1M
-rwxr-xr-x 1 hankf hankf 1.1M May 27 14:05 ./usr/lib/libsqlite3.so.0.8.6
-rwxr-xr-x 1 hankf hankf 1.5M May 27 14:03 ./usr/lib/libvpx.so.6.1.0
-rwxr-xr-x 1 hankf hankf 1.8M May 27 14:02 ./usr/lib/libstdc++.so.6.0.27
-rwxr-xr-x 1 hankf hankf 2.5M May 27 14:04 ./usr/lib/libcrypto.so.1.1
-rwxr-xr-x 1 hankf hankf 1.6M May 27 05:26 ./usr/lib/libQt5WaylandCompositor.so.5.13.2
-rwxr-xr-x 1 hankf hankf 1.3M May 27 14:07 ./usr/lib/libX11.so.6.3.0
-rwxr-xr-x 1 hankf hankf 1.1M May 27 14:07 ./usr/lib/libasound.so.2.0.0
-rwxr-xr-x 1 hankf hankf 1.4M May 27 14:14 ./usr/lib/libxml2.so.2.9.9
-rwxr-xr-x 1 hankf hankf 1.3M May 27 05:00 ./usr/lib/libepoxy.so.0.0.0
-rwxr-xr-x 1 hankf hankf 1.3M May 27 14:20 ./usr/lib/libgstreamer-1.0.so.0.1601.0
total 1.7M
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 libMali.so.9.0
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 ./usr/lib/fbdev/libMali.so.9.0
total 1.5M
total 1.7M
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 libMali.so.9.0
-rw-r--r-- 1 hankf hankf 1.7M Jul 15 17:32 ./usr/lib/wayland/libMali.so.9.0
-rwxr-xr-x 1 hankf hankf 7.2M May 27 05:06 ./usr/lib/libgtk-3.so.0.2404.4
-rwxr-xr-x 1 hankf hankf 5.8M May 27 05:18 ./usr/lib/libQt5Gui.so.5.13.2
total 13M
total 1.2M
total 2.2M
total 22M
-rwxr-xr-x 1 hankf hankf 1.1M Jul 15 17:32 ctrlsw_encoder
-rwxr-xr-x 1 hankf hankf 7.7M May 27 14:28 gdb
-rwxr-xr-x 1 hankf hankf 2.2M May 27 05:03 Xorg
-rwxr-xr-x 1 hankf hankf 2.2M May 27 05:03 ./usr/bin/Xorg
-rwxr-xr-x 1 hankf hankf 1.1M Jul 15 17:32 ./usr/bin/ctrlsw_encoder
-rwxr-xr-x 1 hankf hankf 7.7M May 27 14:28 ./usr/bin/gdb
total 1.8M
total 1.2M
total 4.0M
total 1.3M
total 1.2M
total 1.3M
total 1.3M
total 1.4M
total 5.4M
-rw-r--r-- 1 hankf hankf 5.4M May 27 14:08 magic.mgc
-rw-r--r-- 1 hankf hankf 5.4M May 27 14:08 ./usr/share/misc/magic.mgc
total 1.9M
total 2.2M
-rw-r--r-- 1 hankf hankf 2.2M May 27 05:17 libpnp_basictools.a
-rw-r--r-- 1 hankf hankf 2.2M May 27 05:17 ./usr/share/examples/widgets/tools/plugandpaint/plugins/libpnp_basictools.a
total 3.8M
total 2.8M
-rwxr-xr-x 1 hankf hankf 2.7M Jul 15 17:34 vcu_qt
-rwxr-xr-x 1 hankf hankf 2.7M Jul 15 17:34 ./opt/vcu_qt/bin/vcu_qt
total 2.0M

4. 去掉不必要文件。

根据上述找到的大文件,禁止不使用的软件包,就能减小根文件系统大小。

比如,在petalinux工程中,禁止下列软件包后,rootfs.cpio.gz从114MB,减小到16.4MB。下列内容是从project-spec/configs/rootfs_config提取的。

# CONFIG_gdb is not set
# CONFIG_gdbserver is not set
# CONFIG_kernel-module-hdmi is not set
# CONFIG_packagegroup-core-x11 is not set
# CONFIG_packagegroup-petalinux-audio is not set
# CONFIG_packagegroup-petalinux-gstreamer is not set
# CONFIG_packagegroup-petalinux-matchbox is not set
# CONFIG_packagegroup-petalinux-qt is not set
# packagegroup-petalinux-v4lutils 
# CONFIG_packagegroup-petalinux-v4lutils is not set
# CONFIG_packagegroup-petalinux-x11 is not set
# CONFIG_trd-init is not set
# CONFIG_vcu-gst-app is not set
# CONFIG_custom-edid is not set
# CONFIG_gst-shark is not set
# CONFIG_gstreamer-vcu-examples is not set
# CONFIG_vcu-qt is not set

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 【分享】在PetaLinux里为模块创建补丁

    PetaLinux(Yocto)里包含很多软件模块。大部分模块可以直接使用。如果有特殊需求,需要修改某些模块时,可以按下列办法先修改,测试成功后,再创建补丁,集...

    hankfu
  • 【分享】MPSoC R5引导4个A53和两个R5的应用程序的例子

    有工程师反馈R5引导A53和R5的应用程序后,A53和R5的应用程序没有正确执行。因此做了一个MPSoC R5引导4个A53和两个R5的应用程序的例子。

    hankfu
  • 【分享】 在Vivado里关闭R5/GPU,降低Xilinx MPSoC的功耗

    有些应用中,需要降低Xilinx MPSoC的功耗。缺省设置中,R5/GPU都被使能。如果需要省电,可以在Vivado里关闭R5/GPU。步骤如下:

    hankfu
  • 面试题:我现在上传图片的时候提前预览到图片怎么办?

    今天我也来标题党一会,用“面试题”蹭一蹭热度,主要还行想深度剖析一下,文件上传,里面的门道。

    用户7413032
  • SpringBoot【整合Listener】

     &esmp;创建一个自定义的Listener,监听ServletContext的初始化和销毁的行为,具体如下:

    用户4919348
  • 【php设计模式】组合模式

      是用于把一组相似的对象当作一个单一的对象。组合模式依据树形结构来组合对象,用来表示部分以及整体层次。这种类型的设计模式属于结构型模式,它创建了对象组的树形结...

    码缘
  • mysql使用基础 sql语句与数据完整性(二)

    二、DML:Data Manipulation Language 数据操作语言   作用:操作表中的数据的。   关键:INSERT UPDATE DELE...

    欠扁的小篮子
  • 续 | CFS三层靶机中的Flag位置及其获取

    最近写了一篇《CFS三层靶机搭建及其内网渗透》的文章,里面满满的干货,本篇文章需要结合《CFS三层靶机搭建及其内网渗透》一起看,这篇文章可以点击阅读原文或者到我...

    TeamsSix
  • Go语言库系列之aurora

    平也
  • Tendermint: 共识概览

    Tendermint 是一个易于理解,大部分操作为异步的 BFT 共识协议。下图是一个简单的状态机,它展示了协议遵循的规则:

    用户1558438

扫码关注云+社区

领取腾讯云代金券