Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Change sda2 to sda1

Writer Matthew Martinez

I had two partitions and I recently deleted sda1 and moved sda2(Ubuntu) to where sda1 was located and made it use the whole disk, sda2 is still sda2 though and I want to make it show as sda1 instead.

I've got a Ubuntu Live USB which is where I installed Ubuntu from.

2 Answers

The partition-number is determined by the partition-table entry. Deleting the first partition, in fact means to delete the first partition-table entry. the remaining second partition is still defined by the second partition-table entry, thus it's number is still 2.

There is not really a need to change that, if your partition is defined by the first or second partition-table entry does not matter, in real life you will rarely see your partition number, there is no impact on performance. Reordering your partition-table entries comes with some risk, you may accidentally enter wrong commands.

There is a chance that grub will be broken (since grub uses UUID to find correct partitions I wouldn't expect that, but be prepared to eventually have to reinstall grub).

If you've made any changes to /etc/fstab and use /dev/sda2 instead of UUID, you'll have to change that as well.

I recommend not to do this change, there is no advantage you could gather.


If you really inist in doing that change, here we go:

Use your installer-USB to Try without installing and perform the action from this session, your partition has to be unmounted!

Recheck the correct drive with lsblk -f to see if /dev/sda is still the correct drive, it may or may not change when booted from installer. You'll have to adapt the devicename in the following commands depending on the output you got from the lsblk-command.

Create a copy of the partition-table:

~$ sudo sfdisk -d /dev/sda > sdatable

The result looks like this:

~$ cat sdatable
label: gpt
label-id: CAEC9287-6E64-48BD-8223-B951EE4C7345
device: /dev/sda
unit: sectors
first-lba: 34
last-lba: 625142414
sector-size: 512
/dev/sda2 : start= 2048, size= 625131520, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=917D415A-7E8F-C74E-8D72-1259A7C02ED6, name="archiv"

Now edit only the start of the last line from /dev/sda2 to /dev/sda1, leave anything else as it is. I used nano to do this. The last line should now look like this:

/dev/sda1 : start= 2048, size= 625131520, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=917D415A-7E8F-C74E-8D72-1259A7C02ED6, name="archiv"

In the next step load the altered copy of the partition-table:

~$ sudo sfdisk --force /dev/sda < sdatable
Checking that no-one is using this disk right now ... OK
Disk /dev/sda: 298.09 GiB, 320072933376 bytes, 625142448 sectors
Disk model: Hitachi HTS54503
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: gpt
Disk identifier: CAEC9287-6E64-48BD-8223-B951EE4C7345
Old situation:
Device Start End Sectors Size Type
/dev/sda2 2048 625133567 625131520 298.1G Linux filesystem
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new GPT disklabel (GUID: CAEC9287-6E64-48BD-8223-B951EE4C7345).
/dev/sda1: Created a new partition 1 of type 'Linux filesystem' and of size 298.1 GiB.
Partition #1 contains a ext4 signature.
/dev/sda2: Done.
New situation:
Disklabel type: gpt
Disk identifier: CAEC9287-6E64-48BD-8223-B951EE4C7345
Device Start End Sectors Size Type
/dev/sda1 2048 625133567 625131520 298.1G Linux filesystem
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Rechecking with lsblk gives as expected

~$ lsblk -f | grep sda
sda
└─sda1 ext4 1.0 archiv 57d76d02-deb6-47cf-bb2d-5da748f1cc38

Done. Do it on your own risk!

7

You can't "change" the number the partition has, as those are assigned when the partition is created. If you really wanted your sda2 to be sda1, then you could delete the sda2 partition, and create a new one which will be called sda1. I would certainly not recommend that however. In the grand scheme of things, the partition's number wouldn't affect anything with your system's performance or functioning, so you should be fine.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy