安卓启动中的PARTUUID

本文探讨了在安卓启动过程中,PARTUUID如何用于指定rootfs分区。内容解释了PARTUUID与 blkid 中的UUID的区别,指出PARTUUID是GPT分区表的特性,用于标识分区,而blkid显示的是文件系统的UUID。通过sgdisk等工具可以查看PARTUUID,并且在内核中通过devt_from_partuuid函数映射到设备号。最后,文中提到了PARTUUID在bootcmd中的使用和与tune2fs显示的文件系统UUID的一致性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近看安卓启动,在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是一致的

 

参考链接:

https://raspberrypi.stackexchange.com/questions/75027/whats-the-difference-between-uuid-and-partuuid/75030

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值