You are not logged in.

#1 2014-11-07 12:32:07

strix
Member
From: Switzerland
Registered: 2013-04-29
Posts: 13

Resizing luks partition "in front"

Hello

I have currently the following partitioning scheme:

.-(~)----------------------------------------------------------------------------------------------------(root@tirion)-
`--# fdisk -l /dev/sda

Disk /dev/sda: 107.1 GiB, 115033153536 bytes, 224674128 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: 0x4488c4dc

Device     Boot  Start       End   Sectors  Size Id Type
/dev/sda1  *        63    192779    192717 94.1M 83 Linux
/dev/sda2       192780 224674127 224481348  107G 83 Linux

sda1 is a normal ext4 partition, sda2 LUKS with ext4

I found out, how I can grow a LUKS partition on the "end", but how can I get rid of sda1 and resize the luks partition to take all of the space?

Offline

#2 2014-11-07 13:39:34

clfarron4
Member
From: London, UK
Registered: 2013-06-28
Posts: 2,163
Website

Re: Resizing luks partition "in front"

Two questions first:

1) Is /dev/sda1 mounted as /boot
2) Is /dev/sda2 (i) a LUKS container with an LVM inside, (ii) an LVM with a LUKS container inside OR (iii) something else?

Last edited by clfarron4 (2014-11-07 13:46:04)


Claire is fine.
Problems? I have dysgraphia, so clear and concise please.
My public GPG key for package signing
My x86_64 package repository

Offline

#3 2014-11-07 13:41:38

jjacky
Member
Registered: 2011-11-09
Posts: 347
Website

Re: Resizing luks partition "in front"

Growing, or resizing in general, only happens on the end. So the way to do that would be to delete sda1 & sda2 (in the partition table that is) and create a new partition sda1 over the entire disk. Then you'd need to move the data from the old sda2 to be located where they outta be, so say for example your new partition would be like e.g.

Device     Boot  Start       End   Sectors  Size Id Type
/dev/sda1         2048 224674127 224672080  107G 83 Linux

That would mean sda2 used to start at 192780*512=98703360 and the new one would now start at 2048*512=1048576 -- So I guess you could move data e.g. with dd:

dd bs=4M if=/dev/sda skip=98703360 iflag=skip_bytes of=/dev/sda seek=1048576 oflag=seek_bytes

It should put the data of the old sda2 right in the new sda1 location, so you can use it as expected. Then you can then grow your filesystem as usual (on the end) to take all the space/partition.

Assuming sda2 has a LUKS header, a simply way to make sure your at the right place would be:

dd if=/dev/sda bs=4 count=1 skip=98703360 iflag=skip_bytes

If it's right, it should read/show "LUKS"

Of course you should have a backup of your data before doing any of that. (Also some tools like maybe gparted or something might be able to do the whole thing "automatically" for you, I don't know.)

Offline

#4 2014-11-07 13:45:31

strix
Member
From: Switzerland
Registered: 2013-04-29
Posts: 13

Re: Resizing luks partition "in front"

@clfarron4:

1) Yes it is:

.-(~)----------------------------------------------------------------------------------------------------(root@tirion)-
`--# mount
/dev/mapper/root on / type ext4 (rw,relatime,discard,commit=360,data=ordered)
/dev/sda1 on /boot type ext4 (rw,nosuid,nodev,noexec,relatime,discard,commit=360,data=ordered i)

2) /dev/sda2 is just a LUKS partition with ext4 inside, no LVM at all...


@jjacky:

Thanks, I hoped there might be a simpler (more direct) approach. But I'll try this one.

Last edited by strix (2014-11-07 13:47:11)

Offline

#5 2014-11-07 13:48:58

clfarron4
Member
From: London, UK
Registered: 2013-06-28
Posts: 2,163
Website

Re: Resizing luks partition "in front"

strix wrote:

@clfarron4:

1) Yes it is:

.-(~)----------------------------------------------------------------------------------------------------(root@tirion)-
`--# mount
/dev/mapper/root on / type ext4 (rw,relatime,discard,commit=360,data=ordered)
/dev/sda1 on /boot type ext4 (rw,nosuid,nodev,noexec,relatime,discard,commit=360,data=ordered i)

2) /dev/sda2 is just a LUKS partition with ext4 inside, no LVM at all...

If that's the case, how are you going to boot this? You need an un-encrypted partition (be it on the same disk, or on a USB disk) so you can boot the system and decrypt the LUKS partition...

Last edited by clfarron4 (2014-11-07 13:49:23)


Claire is fine.
Problems? I have dysgraphia, so clear and concise please.
My public GPG key for package signing
My x86_64 package repository

Offline

#6 2014-11-07 13:54:05

strix
Member
From: Switzerland
Registered: 2013-04-29
Posts: 13

Re: Resizing luks partition "in front"

I'm already not booting from there anymore for half a year. My question was how to get rid of this "stub partition".

My unencrypted boot partition resides on a usb stick in my pocket wink

Offline

#7 2014-11-07 14:01:13

clfarron4
Member
From: London, UK
Registered: 2013-06-28
Posts: 2,163
Website

Re: Resizing luks partition "in front"

strix wrote:

I'm already not booting from there anymore for half a year. My question was how to get rid of this "stub partition".

My unencrypted boot partition resides on a usb stick in my pocket wink

OK. I'll leave that be then smile

As for the problem in hand, I can't think of anything better than @jjacky suggested. There are guides out there for Ubuntu and resizing LUKS partitions, but I'd say it's safer if you backup the system, redo the disk entirely and restore from backup smile


Claire is fine.
Problems? I have dysgraphia, so clear and concise please.
My public GPG key for package signing
My x86_64 package repository

Offline

Board footer

Powered by FluxBB