如何更改 PARTUUID?

如何更改 PARTUUID?

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

/dev/sdb1      1922728752 1613465788 211570908  89% /export/home
/dev/sdc1      1922728752  831068620 993968076  46% /store

在重启期间,第一个将其 LABEL 和 UUID 更改为第二个的 LABEL 和 UUID,从而导致数据损坏:

/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"

我尝试更改第一个磁盘的 LABEL 和 UUID:

/dev/sdb1: LABEL="home" UUID="688e53c2-8749-43ae-9823-7e8bc290a9b6" TYPE="ext4" PARTUUID="00054182-01"

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

如果在启动期间未安装磁盘,数据不会损坏。当我稍后手动安装它时(即使使用错误的 LABEL、UUID 和 PARTUUID),数据仍然完好无损。

我有几个问题:

  1. 什么原因导致此错误?我怀疑是硬件故障。磁盘电缆短路?我没有查看内部,但我猜测两个磁盘通过一根数据线连接。
  2. 有没有办法更改 PARTUUID?我想知道这是否可以解决问题。

答案1

对于具有 GPT 分区表的磁盘:

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

$ 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-partition-table 的磁盘,blkid根据Disk Signature(磁盘标识符)和分区号生成 PARTUUID(来源)。

/dev/disk/by-partuuid不同的磁盘必须始终具有不同的标识符。查看包含设备链接的文件(例如/dev/sda1)。您的两个磁盘/dev/sdb/dev/sdc具有相同的标识符,这导致两个不同分区具有相同的 PARTUUID。理论上,这会导致两个链接具有相同的名称但不同的目标,这/dev/disk/by-partuuid根本不可能。这可能是您遇到问题的原因,您一定要更改其中一个磁盘标识符。

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

首先使用以下命令检查磁盘标识符fdisk -l

~$ 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

~$ 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

$ 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

相关内容