Resizing LUKS+LVM2+ext3 after replacing the harddisk with a larger one.

Setup

  • Aluminium Powerbook 1.25GHz 15" (Powerboook5,2)
  • 80GB HDD (Fujitsu MHT2080AT 4200rpm)
  • /dev/hda14 LUKS partition "cryptroot"
  • LVM2 volume group "vgroot" on "cryptroot"
  • LVM2 logical volumes "lvroot" "lvhome" "lvtmp" "lvusr" "lvvar" on "vgroot"

New hardware

  • 160GB HDD (Seagate ST9160821A 5400rpm)

Partition Maps

To display:

 parted /dev/hda unit s p 

Old

Partitions on old 80GB disk

# name Start End #Sectors Size Comment
1 Apple 1 63 63 31.5K Apple partition map
2 Macintosh 64 119 56 28K Apple_Driver43
3 Macintosh 120 175 56 28K Apple_Driver43
4 Macintosh 176 231 56 28K Apple_Driver_ATA
5 Macintosh 232 287 56 28K Apple_Driver_ATA
6 Macintosh 288 799 512 256K Apple_FWDriver
7 Macintosh 800 1311 512 256K Apple_Driver_IOKit
8 Patch Partition 1312 1823 512 256K Apple patch partition
9 Untitled 1824 41945088 41943265 20G OS X root
10 Shared 41945089 111151104 69206016 33G Shared ext3
11 bootstrap 111151105 111152704 1600 800K NewWorld bootblock
12 boot 111152705 111314943 162239 79.22M /boot
13 swap 111314944 113282623 1967680 960.78M swap
14 linux 113282624 156301487 43018864 20.51G root, LUKS, LVM2

Intermediate

Old partitions on new 160GB disk with gaps for expansion

# name Start End #Sectors Size Comment
1 Apple 1 63 63 31.5K  
2 Macintosh 64 119 56 28K  
3 Macintosh 120 175 56 28K  
4 Macintosh 176 231 56 28K  
5 Macintosh 232 287 56 28K  
6 Macintosh 288 799 512 256K  
7 Macintosh 800 1311 512 256K  
8 Patch Partition 1312 1823 512 256K  
9 OSX 1824 41945088 41943265 20480.11M  
  FREE 41945089 83887903 41942815 20479.89M  
10 Shared 83887904 153093919 69206016 33792M  
  FREE 153093920 209717023 56623104 27648M  
11 bootstrap 209717024 209718623 1600 800K  
12 boot 209718624 209880862 162239 79.22M  
  FREE 209880863 209980767 99905 48.78M  
13 swap 209980768 212077919 2097152 1024.0M new size
14 linux 212077920 255096783 43018864 21005.3M  
  FREE 255096784 312581807 57485024 28068.86M  

New

New expanded partitions on new disk.

# name Start End #Sectors Size Comment
1 Apple 1 63 63 31.5K  
2 Macintosh 64 119 56 28.0K  
3 Macintosh 120 175 56 28.0K  
4 Macintosh 176 231 56 28.0K  
5 Macintosh 232 287 56 28.0K  
6 Macintosh 288 799 512 256.0K  
7 Macintosh 800 1311 512 256.0K  
8 Patch Partition 1312 1823 512 256.0K  
9 OSX 1824 41945088 41943265 20480.1M  
10 OSX-2 41945089 83887903 41942815 20479.9M  
11 Shared 83887904 209717023 125829120 60.0M  
12 bootstrap 209717024 209718623 1600 800.0K  
13 boot 209718624 209980767 262144 128.0M  
14 swap 209980768 212077919 2097152 1024.0M  
15 linux 212077920 312581807 100503888 47.9M  

In moving from 80GB to 160GB:

  • OSX is expanding1 from 20GiB to 40GiB
  • Shared is expanding from 33GiB to 60GiB
  • /boot is expanding from 80MiB to 128MiB
  • swap is expanding from 960MiB to 1024MiB
  • root is expanding from 20GiB to ~50GiB

Process

Overview

Migrate data from dying 80GB disk to new 160GB disk, keeping data intact including LUKS partition with LVM2 inside. Resize partitions to take advantage of the bigger disk.

Download Finnix

http://www.finnix.org/

Burn to CD and boot.

wget http://www.finnix.org/releases/90.0/finnix-ppc-90.0.iso
cdrecord -v dev=/dev/cdrw ./finnix-ppc-90.0.iso

Create partitions

Create partitions of the same size (but not necessarily at the same start sector) on new disk manually with parted.

Creating a new partition:

# parted /dev/hda
(parted) unit s
(parted) mkpart root START_SECTOR END_SECTOR

START_SECTOR and END_SECTOR same as old partition map

"unit s" tells parted to work in sector-sized units

Sectors are 512 bytes

Enlarge shared

Use parted to extend the ext3 partition and fs

parted /dev/hda unit s resize 10 83887904 209717023

Enlarge boot

Use parted to extend the ext3 partition and fs

parted /dev/hda unit s resize 12 209718624 209980767

That was easy.

Enlarge swap

Nothing to do, the encrypted swap gets recreated on each boot. So just resize the partition.

Enlarge root

Decrypt

cryptsetup luksOpen /dev/hda14 cryptroot

Activate volume group and logical volumes

vgchange -a y

Resize the physical volume

pvresize /dev/mapper/cryptroot

Enlarge the logical volumes

lvextend -L +10G vgroot/lvhome

Enlarge OS X

HFS+ can't be enlarged without a third-party utility.

So create a new partition instead. To be used as an encrypted Home partition through FileVault.

parted /dev/hda unit s mkpart 41945089 83887903

Did this last because I wasn't sure if it would shift all the partition numbers off.

It didn't. The new OSX partition became /dev/hda15.