13

I tried to sort (renumber) partitions on /dev/sdb via terminal, using gdisk from the operating system (running on /dev/sda) and none of the sdb partitions mounted but the only option I get is [-l] which lists options the option I'm trying to use.

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 #
don_crissti
  • 79,330
  • 30
  • 216
  • 245
BillV
  • 141
  • 1
  • 1
  • 5

4 Answers4

12

gdisk only has the one command line option (-l), to list the partition table and then quit. All of the other operations are conducted interactively from within gdisk. See Rod Smith's walkthrough for some more context.

Essentially, though, you want to just use the command # gdisk /dev/sdb and then, at the prompt, use the s command to sort the partition entries. From man gdisk:

s
Sort partition entries. GPT partition numbers need not match the order of partitions on the disk. If you want them to match, you can use this option. Note that some partitioning utilities sort partitions whenever they make changes. Such changes will be reflected in your device filenames, so you may need to edit /etc/fstab if you use this option.

You should also, before you begin, read Rod's page on Repairing GPT Disks, just in case things head south during the operation...

jasonwryan
  • 71,734
  • 34
  • 193
  • 226
  • ok, sdb is a backup drive with the partitions listed so its not bootable or written to, i manually mount a partition and then rsync to it when i need to backup sda, so filenames shouldn't be an issue correct? – BillV Jun 10 '14 at 00:45
  • @BillV That depends on what you are trying to do, but it sounds like a separate question. – jasonwryan Jun 10 '14 at 00:55
4

To sort partitions on /dev/sdX:

#sgdisk -s /dev/sdX
Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
r2d2
  • 41
  • 1
2

Here a solution with using fdisk over gdisk, which I just tested:

According to this:

To reorder the Linux drive partition numbers for device sdc, all we need to do is open a terminal…

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

It’s that simple.

Replace /dev/sdc with the name of the device you wish to reorganize partition numbers on.

Now check the drive partition naming order by typing sudo fdisk -l into a terminal.

Cadoiz
  • 268
  • 1
  • 11
1

What about using sfdisk?

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

  • Edit the text file like this:

    • Rearrange the entries as you wish
    • then finally renumber the partitions
  • Restore modified partition data: sfdisk /dev/sdb < disc1.sfdisk

  • Example - Before:

Check the partition name how it is unordered ("... 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"

Now edit the file by shifting the entries up or down and reassign sdb[n] numbers. I chose for booting devices 1x and the corresponding linux partitions with 2x numbers: And do not change the data after after the start=....! After editing:

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"
  • Restore sfdisk /dev/sdb < disc1.sfdisk, refresh devices in GParted and check if the numbering is ok for you
YDZOGODOQ
  • 11
  • 2