博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
安卓启动中的PARTUUID
阅读量:4210 次
发布时间:2019-05-26

本文共 2342 字,大约阅读时间需要 7 分钟。

最近看安卓启动,在do mounts dm的时候,发现rootfs分区是通过PARTUUID参数传给内核的

root=/dev/dm-0 dm="system none ro,0 1 android-verity PARTUUID=fbc2c131-6392-4217-b51e-548a6edb03d0 "

 

但是在系统中,通过blkid无法找到对应PARTUUID的分区。简单google了下,发现blkid中的uuid与partuuid不是一个东西

存储设备一般的结构为 :

块设备----分区----文件系统

blkid中的UUID显示的是文件系统的属性,比如ext4系统,可以通过tune2fs -l dev 查看文件系统的uuid。

而PARTUUID是GPT分区表引入的特性,是作为某一个分区的唯一识别符。

这样的好处是操作系统可以在无需知道分区下文件系统的具体信息,同时获得分区的大致类型。

 

The GPT GUIDs (Globally unique identifiers) and our familiar Linux UUIDs (Universally Unique Identifiers) are not the same thing, though they serve the same useful purpose: giving block devices unique names. Linux UUIDs are a function of filesystems, and are created when the filesystem is created. To see Linux UUIDs just fire up the blkid command Note the Partition GUID code, and how it says "Microsoft basic data." Yeah, ole Microsoft always party-crashing, because this an EXT4 partition, so there is no way for Windows to read it, but will see it as an unformatted partition. You won't see this with current releases of gdisk, because until 2011 there were no Linux filesystem GUIDs. Now there are, so if you're not using an old Linux like mine (Mint 13) you'll see a proper Linux GUID instead (0FC63DAF-8483-4772-8E79-3D69D8477DE4).

The Partition unique GUID is what you'll use in fstab, like this:

PARTUUID=8C208C30-4E8F-4096-ACF9-858959BABBAA /data ext4 user,defaults 0 0

读取partuuid,可以通过gdisk/sgdisk工具

 

sgdisk --info=partnum /dev/device

 

再回头看一下bootcmd

root=/dev/dm-0 dm="system none ro,0 1 android-verity PARTUUID=fbc2c131-6392-4217-b51e-548a6edb03d0 "

# sgdisk --info=22 /dev/block/mmcblk0
Partition GUID code: EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 (Microsoft basic data)
Partition unique GUID: FBC2C131-6392-4217-B51E-548A6EDB03D0
First sector: 425984 (at 208.0 MiB)
Last sector: 2523135 (at 1.2 GiB)
Partition size: 2097152 sectors (1024.0 MiB)
Attribute flags: 0000000000000000
Partition name: 'system_a'

bootcmd中的partuuid与sgdisk查看到的Partition unique GUID一致。

内核中通过devt_from_partuuid函数可以查到对应设备的设备号。最终得到rootfs的信息。

static dev_t devt_from_partuuid(const char *uuid_str)

# blkid

/dev/block/mmcblk0p22: LABEL="/" UUID="bbcb9ad2-245d-035f-a549-7d500312efe1" TYPE="ext4" 

# tune2fs -l /dev/block/mmcblk0p22                                               <

tune2fs 1.43.3 (04-Sep-2016)
Filesystem UUID:          bbcb9ad2-245d-035f-a549-7d500312efe1
 

也可以看到是blkid的UUID与ext4的Filesystem UUID是一致的

 

参考链接:

转载地址:http://owrli.baihongyu.com/

你可能感兴趣的文章
c++中的const和define的异同之处
查看>>
c++中的引用
查看>>
c++中复杂类型的引用
查看>>
c++中引用的本质
查看>>
函数返回值是引用的情况。
查看>>
指针的引用
查看>>
c++中的const,即常引用
查看>>
c++中内联函数和宏代码片段的区别
查看>>
c++中函数参数默认值和函数参数占位符
查看>>
c++中的函数重载
查看>>
c++中的函数重载与函数指针相结合
查看>>
c++对c语言扩充和增强的几点具体体现
查看>>
c语言register关键字----最快的关键字
查看>>
c++中的封装和访问控制。
查看>>
c++中,class与struct的区别
查看>>
c++中类的声明和实现
查看>>
c++中构造函数和析构函数的概念
查看>>
c++构造函数的分类和调用
查看>>
c++编译器构造析构方案 PK 对象显示初始化方案
查看>>
拷贝构造函数调用时机第一种和第二种调用场景
查看>>