You are not logged in.

#1 2015-03-12 17:47:19

milk
Member
Registered: 2013-02-06
Posts: 42

partitioning issue

hey there,

it seems this has been discussed a lot, but i could not find a satisfying answer after quite some research, so i hope it's okay to ask.

i have a dual boot system with a windows boot partition (sda1), a windows partition (sda2), a linux boot partition (sda3) and a linux partition (sda4), all being primary partitions.

fdisk -l output:

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3af54d93

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048   2459647   2457600  1.2G  7 HPFS/NTFS/exFAT
/dev/sda2         2459648 197773311 195313664 93.1G  7 HPFS/NTFS/exFAT
/dev/sda3  *    197773312 198035455    262144  128M 83 Linux
/dev/sda4       198035456 407750655 209715200  100G 83 Linux

there is about 730 GiB available on the harddrive which i would like to make available now. unfortunately that is not possible due to the 4 primary partitions.
now i'm wondering what's the easiest way to convert a primary partition to a logical one.
since my external harddrive does not have much space left, i can't just backup /dev/sda4 and re-install everything (besides, it would probably take quite some time to do that..).
instead i thought it might work to backup /dev/sda3 (128M, so much smaller), delete it, create an extendet partition with two logical partitions inside: the linux boot partition and a partition for the 730GiB. i'm just not very sure what i would have to change to still make everything work: probably some address in the windows boot process to point to the right place..

to make it short: does anyone have experience with that? are there any other strategies to make that work?

thanks in advance!
milk

Offline

#2 2015-03-12 18:46:43

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: partitioning issue

Disclaimer: this could be dangerous unless you know what you're doing.

There's a way to do this with only backing up sda3, but I'm not sure I'd want to try it without a backup of sda4.

First, backup your current partition table:

# dd if=/dev/sda of=backupfile bs=512 count=1

In short, the process is as follows:
backup sda3 with something like tar, rsync, etc (not dd)
delete sda3 and sda4
re-create sda3 ~ 1M smaller
create an extended partition covering the rest of the space
re-create sda4

For example, I partitioned a scratch 2G thumb drive with four 100M primary partitions and formatted the fourth one:

# fdisk -l /dev/sdf

Disk /dev/sdf: 2 GiB, 2074083328 bytes, 4050944 sectors
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: 0x40e16394

Device     Boot  Start    End Sectors  Size Id Type
/dev/sdf1         2048 206847  204800  100M 83 Linux
/dev/sdf2       206848 411647  204800  100M 83 Linux
/dev/sdf3       411648 616447  204800  100M 83 Linux
/dev/sdf4       616448 821247  204800  100M 83 Linux

# lsblk --fs |grep sdf
sdf                                                                                           
├─sdf1                                                                                        
├─sdf2                                                                                        
├─sdf3                                                                                        
└─sdf4                ext4              primaryfour    c40ba6bd-13d5-42eb-81dc-fd787cc5c86c

Then I deleted partitions 3 and 4 and re-created as follows:

# fdisk -l /dev/sdf

Disk /dev/sdf: 2 GiB, 2074083328 bytes, 4050944 sectors
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: 0x40e16394

Device     Boot  Start     End Sectors  Size Id Type
/dev/sdf1         2048  206847  204800  100M 83 Linux
/dev/sdf2       206848  411647  204800  100M 83 Linux
/dev/sdf3       411648  614399  202752   99M 83 Linux
/dev/sdf4       614400 4050943 3436544  1.7G  5 Extended
/dev/sdf5       616448  821247  204800  100M 83 Linux

# lsblk --fs |grep sdf
sdf                                                                                           
├─sdf1                                                                                        
├─sdf2                                                                                        
├─sdf3                                                                                        
├─sdf4                                                                                        
└─sdf5                ext4              primaryfour    c40ba6bd-13d5-42eb-81dc-fd787cc5c86c

# fsck -f /dev/sdf5
fsck from util-linux 2.25.2
e2fsck 1.42.12 (29-Aug-2014)
primaryfour: 11/25688 files (0.0% non-contiguous), 8896/102400 blocks

Note that the geometry (Start/End in fdisk output) of the original partition 4 and the new partition 5 are identical, which is why the filesystem survives. Now you can restore the backup of the old partition 3 to the new partition 3 and use the remainder of the space in the extended partition as needed.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#3 2015-03-12 18:47:25

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: partitioning issue

Depends on what is in the 128M partition. If its /boot -- looks like from the Boot Flag that is set, it might be foolish to just delete it and expect it to work.

Also not a Sys Admin question. Moving to NC


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#4 2015-03-12 20:59:47

milk
Member
Registered: 2013-02-06
Posts: 42

Re: partitioning issue

@alphaniner: thanks a lot for your reply

@Inxsible: indeed, it is /boot. that is exactly why i'm asking. i'm not too sure, but as long as sda4 does not change and the windows boot loader finds the partition with /boot it should not break anything, or am i wrong here?

Offline

#5 2015-03-12 20:59:58

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,744
Website

Re: partitioning issue

You could try using gdisk to convert the table to a GPT type (it will offer to convert the table as soon as you load it up).

# gdisk /dev/sda

EDIT: You will also have to create a BIOS boot partition and re-install GRUB if you do this -- use sectors 34-2047 and make it type "EF02" then use:

# grub-install --target=i386-pc --recheck /dev/sda

Last edited by Head_on_a_Stick (2015-03-12 21:02:08)

Offline

Board footer

Powered by FluxBB