Subject: Resizing a LUKS partition?



To follow up my original question (since nobody else said anything), I
ran a test case and it does appear that using LUKS doesn't change how
cryptsetup can be used to change the size of the cryptographic volume
---although the manpage for cryptsetup appears to be incorrect: the
manpage claims that "cryptsetup resize" requires --size, but in my
case, omitting it worked correctly and filled the underlying (LVM2)
partition. (The manpage also doesn't say what a "sector" is supposed
to be, so if I -had- had to say --size, I'd have had to guess.)

I'm going to do this to my -real- partition tomorrow, so if there's
some subtle thing I've missed, speak up... :)

[Note, by the way, that my cryptsetup is the version provided by
1:1.0.1-0ubuntu4 in Ubuntu Breezy 5.10; this version of cryptsetup
doesn't have a --version switch, but Clemens told me about three
months ago that the next one will.]

I'll probably put the skeleton below (which omits tests like copying
files into the encrypted volume & comparing them before & after the
resize---yeah, I'm paranoid and the fsck would probably have blown
up if this hadn't worked) into the wiki so others have a worked-out
example, just in case.

~# pvcreate /dev/hdd
Physical volume "/dev/hdd" successfully created

~# lvcreate -l10 -ntestlv testvg
Logical volume "testlv" created

~# cryptsetup --verbose --verify-passphrase luksFormat /dev/testvg/testlv

WARNING!
========
This will overwrite data on /dev/testvg/testlv irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase: testing

Verify passphrase: testing

~# cryptsetup luksOpen /dev/testvg/testlv testfs
Enter LUKS passphrase: testing

key slot 0 unlocked.

~# mke2fs -v -j -m 1 -T largefile /dev/mapper/testfs
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
64 inodes, 10111 blocks
101 blocks (1.00%) reserved for the super user
First data block=0
1 block group
32768 blocks per group, 32768 fragments per group
64 inodes per group

Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

~# tune2fs -c -1 -i 0 /dev/mapper/testfs
tune2fs 1.38 (30-Jun-2005)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds

~# mkdir /testfs

~# mount -v /dev/mapper/testfs /testfs
mount: you didn't specify a filesystem type for /dev/mapper/testfs
I will try type ext3
/dev/mapper/testfs on /testfs type ext3 (rw)

~# umount /testfs

~# fsck.ext2 -f /dev/mapper/testfs
e2fsck 1.38 (30-Jun-2005)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/testfs: 11/64 files (0.0% non-contiguous), 1037/10111 blocks

~# cryptsetup luksClose testfs

~# lvextend -l+10 /dev/testvg/testlv
Extending logical volume testlv to 80.00 MB
Logical volume testlv successfully resized

~# cryptsetup luksOpen /dev/testvg/testlv testfs
Enter LUKS passphrase: testing

key slot 0 unlocked.

~# cryptsetup --verbose resize testfs

~# mount -v /dev/mapper/testfs /testfs
mount: you didn't specify a filesystem type for /dev/mapper/testfs
I will try type ext3
/dev/mapper/testfs on /testfs type ext3 (rw)

~# umount /testfs

~# fsck.ext2 -f /dev/mapper/testfs
e2fsck 1.38 (30-Jun-2005)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/testfs: 15/64 files (0.0% non-contiguous), 9905/10111 blocks

~# resize2fs /dev/mapper/testfs
resize2fs 1.38 (30-Jun-2005)
Resizing the filesystem on /dev/mapper/testfs to 20351 (4k) blocks.
The filesystem on /dev/mapper/testfs is now 20351 blocks long.

~# fsck.ext2 -f /dev/mapper/testfs
e2fsck 1.38 (30-Jun-2005)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/testfs: 15/64 files (0.0% non-contiguous), 9905/20351 blocks

~# mount -v /dev/mapper/testfs /testfs
mount: you didn't specify a filesystem type for /dev/mapper/testfs
I will try type ext3
/dev/mapper/testfs on /testfs type ext3 (rw)





Programming list archiving by: Enterprise Git Hosting