Is there a way to rename the sda5 to sda4?
Yup {and that is why a long answer below this question exists}
Am taking my USB pendrive /dev/sdc as example. Modify for your case accordingy
First know your drive :
{Just to check you are using the desired disk }
sudo fdisk -l /dev/sdc
Disk /dev/sdc: 14.32 GiB, 15376318464 bytes, 30031872 sectors
Disk model: Cruzer Blade
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: 0xba104c33
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 3426303 3424256 1.6G 83 Linux
/dev/sdc2 3426304 12898303 9472000 4.5G 83 Linux
/dev/sdc3 12898304 20127743 7229440 3.4G b W95 FAT32
/dev/sdc4 20127744 27377663 7249920 3.5G 5 Extended
/dev/sdc5 20129792 22233087 2103296 1G 83 Linux
sudo sfdisk -d /dev/sdc
label: dos
label-id: 0xba104c33
device: /dev/sdc
unit: sectors
sector-size: 512
/dev/sdc1 : start= 2048, size= 3424256, type=83
/dev/sdc2 : start= 3426304, size= 9472000, type=83
/dev/sdc3 : start= 12898304, size= 7229440, type=b
/dev/sdc4 : start= 20127744, size= 7249920, type=5
/dev/sdc5 : start= 20129792, size= 2103296, type=83
sudo parted -l /dev/sdc
Model: SanDisk Cruzer Blade (scsi)
Disk /dev/sdc: 15.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1754MB 1753MB primary ext4
2 1754MB 6604MB 4850MB primary btrfs
3 6604MB 10.3GB 3701MB primary fat32
4 10.3GB 14.0GB 3712MB extended
5 10.3GB 11.4GB 1077MB logical ext2
Note
- Make sure all partitions unmounted during the partition table edit process.
- No applications accessing the disk / modifying its contents.
Know your working tool - sfdisk
From manpage
sfdisk is a script-oriented tool for partitioning any block device.
Want more details ??
Run : man sfdisk
Try the tool on the desired drive
sfdisk -d /dev/sdc
If /dev/sdc is the target disk ;
Backup the partition table first sdc.bak
sfdisk -d /dev/sdc > sdc.bak
Get yourself a working copy - sdc.new
cp sdc.bak sdc.new
Get your hands dirty
Open sdc.new in your favorite editor
label: dos
label-id: 0xba104c33
device: /dev/sdc
unit: sectors
sector-size: 512
/dev/sdc1 : start= 2048, size= 3424256, type=83
/dev/sdc2 : start= 3426304, size= 9472000, type=83
/dev/sdc3 : start= 12898304, size= 7229440, type=b
/dev/sdc4 : start= 20127744, size= 7249920, type=5
/dev/sdc5 : start= 20129792, size= 2103296, type=83
Note the partition sequence
/dev/sdc1
/dev/sdc2
/dev/sdc3
/dev/sdc4
/dev/sdc5
Now i want partition sequence to be like this
/dev/sdc3
/dev/sdc4
/dev/sdc1
/dev/sdc2
/dev/sdc5
In short my required changes :
/dev/sdc1 ------------> /dev/sdc3
/dev/sdc2 ------------> /dev/sdc4
/dev/sdc3 ------------> /dev/sdc1
/dev/sdc4 ------------> /dev/sdc2
/dev/sdc5 ------------> /dev/sdc5
Edit sdc.new the accordingly
Note-
- Do not change any numbers except the partition numbers. I am sure you know why.
sdc.new
label: dos
label-id: 0xba104c33
device: /dev/sdc
unit: sectors
sector-size: 512
/dev/sdc3 : start= 2048, size= 3424256, type=83
/dev/sdc4 : start= 3426304, size= 9472000, type=83
/dev/sdc1 : start= 12898304, size= 7229440, type=b
/dev/sdc2 : start= 20127744, size= 7249920, type=5
/dev/sdc5 : start= 20129792, size= 2103296, type=83
Write the partition table back
sfdisk /dev/sdc < sdc.new
Sample Output :
Checking that no-one is using this disk right now ... OK
Disk /dev/sdc: 14.32 GiB, 15376318464 bytes, 30031872 sectors
Disk model: Cruzer Blade
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: 0xba104c33
Old situation:
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 3426303 3424256 1.6G 83 Linux
/dev/sdc2 3426304 12898303 9472000 4.5G 83 Linux
/dev/sdc3 12898304 20127743 7229440 3.4G b W95 FAT32
/dev/sdc4 20127744 27377663 7249920 3.5G 5 Extended
/dev/sdc5 20129792 22233087 2103296 1G 83 Linux
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0xba104c33.
/dev/sdc1: Created a new partition 3 of type 'Linux' and of size 1.6 GiB.
Partition #3 contains a ext4 signature.
/dev/sdc4: Created a new partition 4 of type 'Linux' and of size 4.5 GiB.
Partition #4 contains a btrfs signature.
/dev/sdc5: Created a new partition 1 of type 'W95 FAT32' and of size 3.4 GiB.
Partition #1 contains a vfat signature.
/dev/sdc2: Created a new partition 2 of type 'Extended' and of size 3.5 GiB.
/dev/sdc3: Created a new partition 5 of type 'Linux' and of size 1 GiB.
Partition #5 contains a ext2 signature.
/dev/sdc6: Done.
New situation:
Disklabel type: dos
Disk identifier: 0xba104c33
Device Boot Start End Sectors Size Id Type
/dev/sdc1 12898304 20127743 7229440 3.4G b W95 FAT32
/dev/sdc2 20127744 27377663 7249920 3.5G 5 Extended
/dev/sdc3 2048 3426303 3424256 1.6G 83 Linux
/dev/sdc4 3426304 12898303 9472000 4.5G 83 Linux
/dev/sdc5 20129792 22233087 2103296 1G 83 Linux
Partition table entries are not in disk order.
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
Time to cross-check
sudo fdisk -l /dev/sdc
Disk /dev/sdc: 14.32 GiB, 15376318464 bytes, 30031872 sectors
Disk model: Cruzer Blade
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: 0xba104c33
Device Boot Start End Sectors Size Id Type
/dev/sdc1 12898304 20127743 7229440 3.4G b W95 FAT32
/dev/sdc2 20127744 27377663 7249920 3.5G 5 Extended
/dev/sdc3 2048 3426303 3424256 1.6G 83 Linux
/dev/sdc4 3426304 12898303 9472000 4.5G 83 Linux
/dev/sdc5 20129792 22233087 2103296 1G 83 Linux
Partition table entries are not in disk order.
sudo parted -l /dev/sdc
Model: SanDisk Cruzer Blade (scsi)
Disk /dev/sdc: 15.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
3 1049kB 1754MB 1753MB primary ext4
4 1754MB 6604MB 4850MB primary btrfs
1 6604MB 10.3GB 3701MB primary fat32
2 10.3GB 14.0GB 3712MB extended
5 10.3GB 11.4GB 1077MB logical ext2
In case things get messed up restore from the backup partition table sdc.bak -
sfdisk /dev/sdc < sdc.bak