Friday, May 3, 2024
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 3657  / 3 Years ago, tue, august 10, 2021, 8:03:28

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.


More From » partitioning

 Answers
1

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!


[#1863] Wednesday, August 11, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ampolinhad

Total Points: 88
Total Questions: 100
Total Answers: 116

Location: South Georgia
Member since Tue, Feb 1, 2022
2 Years ago
ampolinhad questions
Thu, Sep 8, 22, 15:45, 2 Years ago
Sat, Oct 16, 21, 22:44, 3 Years ago
Sat, Oct 23, 21, 03:11, 3 Years ago
Thu, Nov 17, 22, 15:34, 1 Year ago
Mon, Nov 14, 22, 22:15, 2 Years ago
;