首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何更改PARTUUID?

如何更改PARTUUID?
EN

Ask Ubuntu用户
提问于 2020-06-14 12:14:33
回答 1查看 17.1K关注 0票数 5

我有一个服务器,它有两个大小相同的磁盘:

代码语言:javascript
运行
复制
/dev/sdb1      1922728752 1613465788 211570908  89% /export/home
/dev/sdc1      1922728752  831068620 993968076  46% /store

在重新启动期间,首先它们将其标签和UUID更改为第二个标签和UUID,从而导致数据损坏:

代码语言:javascript
运行
复制
/dev/sdb1: LABEL="store" UUID="9a353d19-b638-4fed-9aa1-9525dd891da4" TYPE="ext4" PARTUUID="00054182-01"
/dev/sdc1: LABEL="store" UUID="9a353d19-b638-4fed-9aa1-9525dd891da4" TYPE="ext4" PARTUUID="00054182-01"

我试图更改第一个磁盘的标签和UUID:

代码语言:javascript
运行
复制
/dev/sdb1: LABEL="home" UUID="688e53c2-8749-43ae-9823-7e8bc290a9b6" TYPE="ext4" PARTUUID="00054182-01"

并运行fsck,但是在下一次重新引导之后,它被重命名为store,并带有错误的UUID,数据再次损坏。然后,我注意到两个磁盘的PARTUUID也是相同的,但我没有找到如何更改PARTUUID的方法。

如果磁盘在引导期间没有挂载,则数据不会损坏。当我稍后手动挂载它(即使使用错误的标签、UUID和PARTUUID)时,数据仍然保持完整。

我有几个问题:

  1. 是什么导致了这个错误?我怀疑是HW的失败。磁盘电缆上的短路?我没有往里面看,但我想这两个磁盘是由一个数据线连接的。
  2. 有办法改变PARTUUID吗?我不知道这是否能解决问题。
EN

回答 1

Ask Ubuntu用户

发布于 2020-06-14 13:02:07

具有GPT分区表的磁盘的

可以用gdisk更改分区的PARTUUID。我建议先读man gdisk。在下面的示例中,我展示了如何在第一个驱动器(Sda)上更改第二个分区的PARTUUID:

代码语言:javascript
运行
复制
$ sudo gdisk /dev/sda
[sudo] password for mook: 
GPT fdisk (gdisk) version 1.0.5

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): x                                       # enter x to change to experts menu

Expert command (? for help): c                                # enter c to change PARTUUID
Partition number (1-2): 2                                     # enter the number of the partition you want to change
Enter the partition's new unique GUID ('R' to randomize): r 
New GUID is 76349364-D66C-4C19-B422-237A0D2DB9F5

Expert command (? for help): m                                # enter m to go back to main menu

Command (? for help): w                                       # enter w to write the change to disk

Command (? for help): q                                       # enter q to exit gdisk
$

具有msdos分区表的磁盘的

对于具有msdos分区表的磁盘,blkid根据Disk Signature(磁盘标识符)和分区号(来源)生成PARTUUID。

不同的磁盘必须始终具有不同的标识符。请参阅/dev/disk/by-partuuid中的文件,这些文件是设备的链接(例如,/dev/sda1)。您的两个磁盘都有相同的标识符,并且只有一个分区,而在两个磁盘上都是第一个分区,理论上这将导致在/dev/disk/by-partuuid中有两个名称相同但目标不同的链接,这是根本不可能的。这可能是您出现问题的原因,您应该明确地更改磁盘标识符之一。

下面是一个如何使用fdisk更改磁盘签名的示例:

首先用fdisk -l检查磁盘标识符:

代码语言:javascript
运行
复制
~$ sudo fdisk -l /dev/sdc
[sudo] password for mook: 
Disk /dev/sdc: 7.25 GiB, 7776239616 bytes, 15187968 sectors
Disk model: USB FLASH DRIVE 
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: 0x60123f75

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1        2048 15187967 15185920  7.2G 83 Linux

现在用fdisk更改磁盘标识符:

代码语言:javascript
运行
复制
~$ sudo fdisk /dev/sdc
[sudo] password for mook: 

Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): x                             # enter x to go to expert menu

Expert command (m for help): i                      # enter i to change identifier

Enter the new disk identifier: 0x60123f76

Disk identifier changed from 0x60123f75 to 0x60123f76.

Expert command (m for help): r                      # enter r to return to main menu

Command (m for help): w                             # enter w to write change to MBR

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

现在,请重新检查fdisk -l

代码语言:javascript
运行
复制
$ sudo fdisk -l /dev/sdc
Disk /dev/sdc: 7.25 GiB, 7776239616 bytes, 15187968 sectors
Disk model: USB FLASH DRIVE 
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: 0x60123f76

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1        2048 15187967 15185920  7.2G 83 Linux
票数 11
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1250224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档