How to renumber GPT partitions on an umounted disk?

8,758

Solution 1

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...

Solution 2

To sort partitions on /dev/sdX:

#sgdisk -s /dev/sdX

Solution 3

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.

Share:
8,758

Related videos on Youtube

BillV
Author by

BillV

CEMS specialist. MoBo = Asus M5A88M / CPU = AMD AM3+ FX8350 & Zalman CNPS9900max-r cooler / RAM = 32GB (4x8) ddr3 G.Skill / GFX0 = Asus R7-240 / Disks = (1) 120GB Sandisk SSD, (2) 1TB Seagate HDDs, (1) 2TB WDC HDD / in a Thermaltake Soprano tower along with some other stuff...

Updated on September 18, 2022

Comments

  • BillV
    BillV almost 2 years

    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 #
  • BillV
    BillV about 10 years
    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?
  • jasonwryan
    jasonwryan about 10 years
    @BillV That depends on what you are trying to do, but it sounds like a separate question.
  • Jeremy Boden
    Jeremy Boden about 3 years
    But why would you modify your partition table, just to make things look tidy?
  • Tanishq-Banyal
    Tanishq-Banyal almost 3 years
    @Jeremy Boden Because correctly ordered partitions prevents confusion and makes it easier to remember which partition is which.