如何对已卸载磁盘上的 GPT 分区重新编号?

如何对已卸载磁盘上的 GPT 分区重新编号?

我尝试/dev/sdb通过终端对分区进行排序(重新编号),使用gdisk操作系统(在 上运行/dev/sda),并且没有安装任何分区sdb,但我得到的唯一选项是[-l]列出了我尝试使用的选项。

root@arch-bill /home/bill # lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 931.5G  0 disk 
|-sda1   8:1    0  15.6G  0 part /
|-sda2   8:2    0 915.9G  0 part /home
`-sda3   8:3    0     2M  0 part 
sdb      8:16   0   1.8T  0 disk 
|-sdb1   8:17   0     2M  0 part 
|-sdb2   8:18   0     4G  0 part 
|-sdb3   8:19   0    16G  0 part 
|-sdb4   8:20   0    60G  0 part 
`-sdb6   8:22   0   1.8T  0 part 
sr0     11:0    1  1024M  0 rom  
root@arch-bill /home/bill # blkid
/dev/sdb1: PARTUUID="c1073e4b-fc00-4f02-8b81-6f17b8a188c4" 
/dev/sdb2: LABEL="var" UUID="62921c0a-5d34-464d-8a7a-2ff46ad8f12b" TYPE="ext4" PARTUUID="c350316a-0bd8-4e82-8597-123553977f99" 
/dev/sdb3: LABEL="rootbkp" UUID="c245c20e-d503-4b61-aaaf-060aae1b21d4" TYPE="ext4" PARTUUID="b1f391db-de37-479c-8b44-ff27f3bd6aa5" 
/dev/sdb4: LABEL="snapster" UUID="8fef4e0a-efd4-455b-b484-83bd4500161f" TYPE="ext4" PARTUUID="02801cd9-3fe5-4814-9b92-c4c83b86173d" 
/dev/sdb6: LABEL="homebkp" UUID="51d73ac7-fd96-4ac1-b4f3-4abf6bc4936b" TYPE="ext4" PARTUUID="481ae7d0-228f-4979-8949-befbd498534b" 
/dev/sda1: UUID="91865df2-0841-42f5-80f3-a5133976e70f" TYPE="ext4" PARTUUID="48dc34cb-e791-4838-b9f2-2fe2b2cced33" 
/dev/sda2: UUID="e5743a89-13ed-4c96-b39d-78cb6478fb72" TYPE="ext4" PARTUUID="4156cbf2-2a2d-47ae-87cf-99c14cf8f2c2" 
/dev/sda3: PARTUUID="8669392a-663e-4e15-bc63-a6a5e95c97ad" 

root@arch-bill /home/bill # gdisk -s /dev/sdb
GPT fdisk (gdisk) version 0.8.10

Usage: gdisk [-l] device_file
1 
root@arch-bill /home/bill # gdisk -l /dev/sdb                                                                                                                                                                                          :(
GPT fdisk (gdisk) version 0.8.10

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

Found valid GPT with protective MBR; using GPT.
Disk /dev/sdb: 3907029168 sectors, 1.8 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): 0645408C-0374-4357-8663-D2A3512E07BD
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 3907029134
Partitions will be aligned on 2048-sector boundaries
Total free space is 4204653 sectors (2.0 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048            6143   2.0 MiB     EF02  
   2            8192         8396799   4.0 GiB     0700  
   3         8398848        41953279   16.0 GiB    0700  
   4        41955328       167786495   60.0 GiB    0700  
   6       167788544      3902834687   1.7 TiB     0700  
1 root@arch-bill /home/bill #

答案1

gdisk只有一个命令行选项 ( -l),用于列出分区表然后退出。所有其他操作都是从内部交互进行的gdisk。看罗德·史密斯的演练了解更多背景信息。

但本质上,您只想使用该命令# gdisk /dev/sdb,然后在提示符下使用该s命令对分区条目进行排序。从man gdisk


分区条目进行排序。 GPT 分区号不需要与磁盘上分区的顺序匹配。如果您希望它们匹配,可以使用此选项。请注意,某些分区实用程序在进行更改时会对分区进行排序。此类更改将反映在您的设备文件名中,因此如果使用此选项,您可能需要编辑 /etc/fstab。

在开始之前,您还应该阅读 Rod 的页面:修复 GPT 磁盘,以防万一在行动过程中事情进展不顺利……

答案2

对分区进行排序/dev/sdX

#sgdisk -s /dev/sdX

答案3

这是我刚刚测试过的使用fdiskover 的解决方案:gdisk

根据这个:

要重新排序设备 sdc 的 Linux 驱动器分区号,我们需要做的就是打开一个终端......

type

sudo fdisk /dev/sdc

then
    press “x” to enter Expert Mode
    press “f” to fix the drive order
    press “i” to ignore the warning (if it shows)
    press “w” to write changes to the disk
    press “r” to leave expert mode *(forgotten by the author)*
    press “q” to  quit fdisk

就这么简单。

替换/dev/sdc为您要在其上重新组织分区号的设备的名称。

sudo fdisk -l 现在,通过在终端中键入内容来检查驱动器分区命名顺序。

答案4

使用 sfdisk 怎么样?

  • 备份: sfdisk -d /dev/sdb > disc1.sfdisk # Create also a backup file too

  • 像这样编辑文本文件:

    • 根据需要重新排列条目
    • 然后最后重新编号分区
  • 恢复修改的分区数据: sfdisk /dev/sdb < disc1.sfdisk

  • 示例 - 之前:

检查分区名称是否无序 ( "... name=...")。

label: gpt
label-id: DBBC346B-516E-4EAF-BB5B-61810EF2E682
device: /dev/sdb
unit: sectors
first-lba: 34
last-lba: 4000797326

/dev/sdb1 : start=        2048, size=      204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=7528D784-12C1-48D3-B94B-9CEF6D12E0A3, name="EFI system partition"
/dev/sdb2 : start=      206848, size=       32768, type=E3C9E316-0B5C-4DB8-817D-F92DF00215AE, uuid=13D17776-9E43-42E2-ADD4-26D34E27B010, name="Microsoft reserved partition"
/dev/sdb3 : start=      239616, size=   203537112, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=CE13B309-40B7-44AF-A239-3129259BB2B2, name="Basic data partition"
/dev/sdb4 : start=   203778048, size=     1021952, type=DE94BBA4-06D1-4D40-A16A-BFD50179D6AC, uuid=8B6DA26A-8A07-4523-B2EE-46797EF42E40, attrs="RequiredPartition"
/dev/sdb5 : start=   204800000, size=   204800000, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=4F9359C9-34E9-4A8E-858A-058095DC63C1, name="Basic data partition"
/dev/sdb6 : start=   417988608, size=     4194304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=3B752CBD-A0A9-4081-8939-E5B1921E2FFA, name="boot3"
/dev/sdb8 : start=   422182912, size=     8093696, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=9FA26BDA-4D93-455B-9D14-538DD27AF1CB, name="boot4"
/dev/sdb9 : start=   430276608, size=    70041600, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=1958F11E-1EE3-48F0-854F-B338072709FD, name="ubuntu1"
/dev/sdb10 : start=   500318208, size=    81162240, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=F7A0CFE8-1C81-4C23-8888-B8A6E3B63140, name="ubuntu2"
/dev/sdb11 : start=   409600000, size=     4193360, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=162818DD-E6DB-45AE-8A92-C8477F337AC0, name="boot1"
/dev/sdb12 : start=   581480449, size=    61439999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A8539116-B7DF-4282-9D31-5B87E1ADF41A, name="ubuntu3"
/dev/sdb13 : start=   642920448, size=    61440000, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DD154362-1D49-464A-A17F-9077D42A5A6B, name="ubuntu4"
/dev/sdb15 : start=   413794304, size=     4194304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=59BF449B-AB9A-487E-AA55-B47D6446E1FB, name="boot2"

现在通过向上或向下移动条目来编辑文件并重新分配 sdb[n] 编号。我选择了引导设备 1x 和相应的带有 2x 编号的 linux 分区: 并且在 start=.... 后不要更改数据!编辑后:

label: gpt
label-id: DBBC346B-516E-4EAF-BB5B-61810EF2E682
device: /dev/sdb
unit: sectors
first-lba: 34
last-lba: 4000797326

/dev/sdb1 : start=        2048, size=      204800, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=7528D784-12C1-48D3-B94B-9CEF6D12E0A3, name="EFI system partition"
/dev/sdb2 : start=      206848, size=       32768, type=E3C9E316-0B5C-4DB8-817D-F92DF00215AE, uuid=13D17776-9E43-42E2-ADD4-26D34E27B010, name="Microsoft reserved partition"
/dev/sdb3 : start=      239616, size=   203537112, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=CE13B309-40B7-44AF-A239-3129259BB2B2, name="Basic data partition"
/dev/sdb4 : start=   203778048, size=     1021952, type=DE94BBA4-06D1-4D40-A16A-BFD50179D6AC, uuid=8B6DA26A-8A07-4523-B2EE-46797EF42E40, attrs="RequiredPartition"
/dev/sdb5 : start=   204800000, size=   204800000, type=EBD0A0A2-B9E5-4433-87C0-68B6B72699C7, uuid=4F9359C9-34E9-4A8E-858A-058095DC63C1, name="Basic data partition"
/dev/sdb11 : start=   409600000, size=     4193360, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=162818DD-E6DB-45AE-8A92-C8477F337AC0, name="boot1"
/dev/sdb12 : start=   413794304, size=     4194304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=59BF449B-AB9A-487E-AA55-B47D6446E1FB, name="boot2"
/dev/sdb13 : start=   417988608, size=     4194304, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=3B752CBD-A0A9-4081-8939-E5B1921E2FFA, name="boot3"
/dev/sdb14 : start=   422182912, size=     8093696, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=9FA26BDA-4D93-455B-9D14-538DD27AF1CB, name="boot4"
/dev/sdb21 : start=   430276608, size=    70041600, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=1958F11E-1EE3-48F0-854F-B338072709FD, name="ubuntu1"
/dev/sdb22 : start=   500318208, size=    81162240, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=F7A0CFE8-1C81-4C23-8888-B8A6E3B63140, name="ubuntu2"
/dev/sdb23 : start=   581480449, size=    61439999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=A8539116-B7DF-4282-9D31-5B87E1ADF41A, name="ubuntu3"
/dev/sdb24 : start=   642920448, size=    61440000, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=DD154362-1D49-464A-A17F-9077D42A5A6B, name="ubuntu4"
  • 恢复sfdisk /dev/sdb < disc1.sfdisk、刷新 GParted 中的设备并检查编号是否适合您

相关内容