GNU/Linux - wic文件的使用

news/2024/7/8 1:34:18 标签: linux

Yocto/OpenEmbedded使用的磁盘镜像格式是 wic。为嵌入式系统提供 bootable images。

The disk image format used in the Yocto Project is wic.

.wic 文件显然只是一个带有分区表和分区的磁盘镜像,就像下载 Linux 发行版时获得的所有 .img 文件一样。这就是为什么你可以使用 dd 命令烧写 .wic 文件,就像使用 .img 文件一样。

A .wic file is apparently just a disk image with a partition table and partitions, just like all the .img files you get when downloading e.g Linux distros. That's why you can flash a .wic file using dd just like you would with a .img file.

之所以使用 .wic 文件扩展名,是因为它是由 wic 工具创建的,该工具读取 .wks 文件中描述的分区布局,并生成带有相应分区的映像。有关 wic 工具的更多信息,请参阅: 19 Creating Partitioned Images Using Wic — The Yocto Project ® 5.0.1 documentation

The reason for the .wic file extension is simply that it's created by the wic tool, which reads a partition layout described in a .wks file and generates an image with the corresponding partitions. For more info on the wic tool, see:  19 Creating Partitioned Images Using Wic — The Yocto Project ® 5.0.1 documentation 

如何读取wic文件中的内容呢?

1,Mount the .wic File

将wic文件加载为loop device。

Automatically find an available loop device and associate it with a file.

$ sudo losetup -Pf --show my-image.wic

/dev/loop17

$ losetup --help

-a, --all                     list all used devices

-P, --partscan                create a partitioned loop device

-f, --find                    find first unused device

--show                    print device name after setup (with -f)

-d, --detach <loopdev>...     detach one or more devices

-D, --detach-all              detach all used devices

$ losetup -a

上面结果显示加载为/dev/loop17设备。

将设备名赋值给变量:

LOOP_DEVICE=$(sudo losetup -Pf --show my-image.wic)

2, List Partitions

使用fdisk命令,查看加载设备的分区信息

$ sudo fdisk -l /dev/loop17

Disk /dev/loop17: 7.11 GiB, 7638816768 bytes, 14919564 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x076c4a2a

Device        Boot  Start      End  Sectors  Size Id Type

/dev/loop17p1 *     16384   186775   170392 83.2M  c W95 FAT32 (LBA)

/dev/loop17p2      196608 14919563 14722956    7G 83 Linux

3,Mount Partitions

sudo mount  /dev/loop17p1 mnt

4,Access Files

cd mnt

ls

5, Cleaning up

Unmount partitions:

sudo umount mnt

6, Detach the loop device

sudo losetup -d /dev/loop17


使用kpartx命令操作:

$ kpartx --help

-a add partition devmappings

-d del partition devmappings

-v verbose

-l list partitions devmappings that would be added by -a

$ sudo kpartx -av my-image.wic

[sudo] password for dev:

add map loop17p1 (252:0): 0 170392 linear 7:17 16384

add map loop17p2 (252:1): 0 14722956 linear 7:17 196608

$ sudo kpartx -l my-image.wic

loop17p1 : 0 170392 /dev/loop17 16384

loop17p2 : 0 14722956 /dev/loop17 196608

$ sudo kpartx -l /dev/loop17

loop17p1 : 0 170392 /dev/loop17 16384

loop17p2 : 0 14722956 /dev/loop17 196608

$ sudo fdisk -l /dev/loop17

Disk /dev/loop17: 7.11 GiB, 7638816768 bytes, 14919564 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x076c4a2a

Device        Boot  Start      End  Sectors  Size Id Type

/dev/loop17p1 *     16384   186775   170392 83.2M  c W95 FAT32 (LBA)

/dev/loop17p2      196608 14919563 14722956    7G 83 Linux

$ ls /dev/mapper/

control  loop17p1  loop17p2

$ sudo mount /dev/mapper/loop17p2 mnt

$ sudo umount mnt

$ sudo kpartx -dv my-image.wic

del devmap : loop17p1

del devmap : loop17p2

loop deleted : /dev/loop17

$ sudo kpartx -dv /dev/loop17

del devmap : loop17p1

del devmap : loop17p2

参考:

linux - Difference between wic and hddimg format in yocto - Stack Overflow


http://www.niftyadmin.cn/n/5536026.html

相关文章

使用Spring Boot实现博客管理系统

文章目录 引言第一章 Spring Boot概述1.1 什么是Spring Boot1.2 Spring Boot的主要特性 第二章 项目初始化第三章 用户管理模块3.1 创建用户实体类3.2 创建用户Repository接口3.3 实现用户Service类3.4 创建用户Controller类 第四章 博客文章管理模块4.1 创建博客文章实体类4.2…

航空数据管控系统-②项目分析与设计:任务1:需求分析-项目场景引入

任务描述 知识点&#xff1a;需求分析 重 点&#xff1a;原型设计工具&#xff0c;用例图&#xff0c;流程图绘制工具 难 点&#xff1a;功能点的梳理 内 容&#xff1a;完成本次实训项目的需求分析 先共同讨论处本项目的主要功能模块&#xff0c;并确定每个模块的负责…

7 动态规划

下面的例子不错&#xff1a; 对于动态规划&#xff0c;能学到不少东西&#xff1b; 你要清楚每一步都在做什么&#xff0c;划分细致就能够拆解清楚&#xff01; xk. - 力扣&#xff08;LeetCode&#xff09; labuladong的算法笔记-动态规划-CSDN博客 动态规划是一种强大的算法…

WRF学习——使用CMIP6数据驱动WRF/基于ncl与vdo的CMIP6数据处理

动力降尺度 国际耦合模式比较计划&#xff08;CMIP&#xff09;为研究不同情景下的气候变化提供了大量的模拟数据&#xff0c;而在实际研究中&#xff0c;全球气候模式输出的数据空间分辨率往往较低&#xff08;>100Km&#xff0c;缺乏区域气候特征&#xff0c;为了更好地研…

c# 的 goto

搞循环感觉没什么必要 int number 0; Console.WriteLine("请输入一个数字&#xff08;输入-1结束&#xff09;:"); start: // 标签 number int.Parse(Console.ReadLine()); if (number -1) { Console.WriteLine("程序结束。"); } else { Cons…

数据结构(期末)

目录 逻辑结构 存储结构 算法有以下五个特性 算法数据结构 程序 时间复杂度 空间复杂度 数据元素是数据的基本单位 数据项是数据的最小单位 数据结构是带有结构的各数据元素的集合 时间复杂度例题 线性表 关于带头节点的单链表及不带头节点的单链表 栈和队列 栈…

阿里模型调用体验

引言 随着人工智能技术的飞速发展&#xff0c;大型模型已成为推动技术进步的关键因素之一。阿里大模型作为国内领先的人工智能技术之一&#xff0c;其在多个领域的应用展示了强大的潜力。本文将通过调用案例&#xff0c;简单解析阿里大模型在特定场景中的应用及其效果。 1.导…

如何更改 Python pip 源为国内源

在使用 Python 安装包工具 pip 时&#xff0c;经常会遇到下载速度慢的问题。这通常是因为默认使用的官方源 https://pypi.org/simple 在国内访问速度较慢。为了提高下载速度&#xff0c;我们可以将 pip 源更改为国内的镜像源。本文将介绍如何临时和永久地更改 pip 源为国内源。…