安卓启动中的PARTUUID

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

你可能感兴趣的:(Android)