Maximally shrink LVM PV and LUKS container / partition
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I want to remove my swap
LVM LV out of its current LUKS container, and have it unencrypted instead.
I want to avoid something like gparted
to have control of every step in the process.
After doing
lvremove
on theswap
LV andpvmove
to get contiguous PV extents, how do I work out the minimum size to pass topvresize
?Given the now shrunken PV, how do I work out exactly how many sectors or MiB the LUKS container should contain, so I can shrink the LUKS partition to match?
Am I right in thinking that a LUKS container doesn't have a length, and is shrunk by simply shrinking the partition?
Is there a way of checking at the LVM level that the final extents of the PV are still accessible, ie, that they are indeed inside the shrunken partition's addressable sectors?
linux partition lvm
add a comment |Â
up vote
0
down vote
favorite
I want to remove my swap
LVM LV out of its current LUKS container, and have it unencrypted instead.
I want to avoid something like gparted
to have control of every step in the process.
After doing
lvremove
on theswap
LV andpvmove
to get contiguous PV extents, how do I work out the minimum size to pass topvresize
?Given the now shrunken PV, how do I work out exactly how many sectors or MiB the LUKS container should contain, so I can shrink the LUKS partition to match?
Am I right in thinking that a LUKS container doesn't have a length, and is shrunk by simply shrinking the partition?
Is there a way of checking at the LVM level that the final extents of the PV are still accessible, ie, that they are indeed inside the shrunken partition's addressable sectors?
linux partition lvm
Doesn'tpvresize
use the smallest possible size by default?
â ajeh
Aug 3 at 18:30
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to remove my swap
LVM LV out of its current LUKS container, and have it unencrypted instead.
I want to avoid something like gparted
to have control of every step in the process.
After doing
lvremove
on theswap
LV andpvmove
to get contiguous PV extents, how do I work out the minimum size to pass topvresize
?Given the now shrunken PV, how do I work out exactly how many sectors or MiB the LUKS container should contain, so I can shrink the LUKS partition to match?
Am I right in thinking that a LUKS container doesn't have a length, and is shrunk by simply shrinking the partition?
Is there a way of checking at the LVM level that the final extents of the PV are still accessible, ie, that they are indeed inside the shrunken partition's addressable sectors?
linux partition lvm
I want to remove my swap
LVM LV out of its current LUKS container, and have it unencrypted instead.
I want to avoid something like gparted
to have control of every step in the process.
After doing
lvremove
on theswap
LV andpvmove
to get contiguous PV extents, how do I work out the minimum size to pass topvresize
?Given the now shrunken PV, how do I work out exactly how many sectors or MiB the LUKS container should contain, so I can shrink the LUKS partition to match?
Am I right in thinking that a LUKS container doesn't have a length, and is shrunk by simply shrinking the partition?
Is there a way of checking at the LVM level that the final extents of the PV are still accessible, ie, that they are indeed inside the shrunken partition's addressable sectors?
linux partition lvm
edited Aug 3 at 16:22
asked Aug 3 at 16:07
Tom Hale
5,61712370
5,61712370
Doesn'tpvresize
use the smallest possible size by default?
â ajeh
Aug 3 at 18:30
add a comment |Â
Doesn'tpvresize
use the smallest possible size by default?
â ajeh
Aug 3 at 18:30
Doesn't
pvresize
use the smallest possible size by default?â ajeh
Aug 3 at 18:30
Doesn't
pvresize
use the smallest possible size by default?â ajeh
Aug 3 at 18:30
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
1.)
From the man page:
pvresize
will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be.
So you could just do this by trial & error. Actually pvresize
will tell you part of it:
/dev/dm-7: cannot resize to 17564 extents as 18620 are allocated.
To determine the exact size, you need to know the PE size (e.g. 4MiB) and 1st PE offset (e.g. 1MiB). And of course, the number of the last allocated extent.
pvs -o pv_name,pe_start,vg_extent_size,seg_pe_ranges
So the total size could for example be 1MiB (1st PE) + 18620 * 4MiB (PE size).
2.)
You need to know the LUKS header size / data offset. Usually this is 4096 sectors, i.e. 2MiB. Check with cryptsetup luksDump
, Payload offset
.
So your new partition size is the LUKS Payload offset plus whatever size you resized the PV itself to.
3.)
Yes and no. LUKS doesn't keep the size in its metadata, so if you are going to close the LUKS container, or even reboot, then yes, it will just use the size of the block device itself.
But for an online resize, you would need to set it with cryptsetup resize
, to whatever size you used in pvresize
.
4.)
I sometimes do this by passing the offending device in read-only mode to a qemu/KVM instance, running some Linux rescue system. It's hard to check on the host (with, say, a read-only loop device) because LVM doesn't like to see duplicate PV UUIDs, or VG/LV names. LVM will refuse to activate, should the PV turn out to be smaller than expected.
Excellent, thank you. Note for self and others:cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.
â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to usepvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?
â Tom Hale
Aug 4 at 4:10
Always use-v
withcryptsetup
, or be sure to check its exit status.
â Tom Hale
Aug 4 at 4:14
Get PE size from:sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
add a comment |Â
up vote
0
down vote
Consider pvshrink
which does most of the calculations in frostschutz's answer, and has a --test
mode which doesn't make any changes.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
1.)
From the man page:
pvresize
will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be.
So you could just do this by trial & error. Actually pvresize
will tell you part of it:
/dev/dm-7: cannot resize to 17564 extents as 18620 are allocated.
To determine the exact size, you need to know the PE size (e.g. 4MiB) and 1st PE offset (e.g. 1MiB). And of course, the number of the last allocated extent.
pvs -o pv_name,pe_start,vg_extent_size,seg_pe_ranges
So the total size could for example be 1MiB (1st PE) + 18620 * 4MiB (PE size).
2.)
You need to know the LUKS header size / data offset. Usually this is 4096 sectors, i.e. 2MiB. Check with cryptsetup luksDump
, Payload offset
.
So your new partition size is the LUKS Payload offset plus whatever size you resized the PV itself to.
3.)
Yes and no. LUKS doesn't keep the size in its metadata, so if you are going to close the LUKS container, or even reboot, then yes, it will just use the size of the block device itself.
But for an online resize, you would need to set it with cryptsetup resize
, to whatever size you used in pvresize
.
4.)
I sometimes do this by passing the offending device in read-only mode to a qemu/KVM instance, running some Linux rescue system. It's hard to check on the host (with, say, a read-only loop device) because LVM doesn't like to see duplicate PV UUIDs, or VG/LV names. LVM will refuse to activate, should the PV turn out to be smaller than expected.
Excellent, thank you. Note for self and others:cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.
â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to usepvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?
â Tom Hale
Aug 4 at 4:10
Always use-v
withcryptsetup
, or be sure to check its exit status.
â Tom Hale
Aug 4 at 4:14
Get PE size from:sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
add a comment |Â
up vote
1
down vote
accepted
1.)
From the man page:
pvresize
will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be.
So you could just do this by trial & error. Actually pvresize
will tell you part of it:
/dev/dm-7: cannot resize to 17564 extents as 18620 are allocated.
To determine the exact size, you need to know the PE size (e.g. 4MiB) and 1st PE offset (e.g. 1MiB). And of course, the number of the last allocated extent.
pvs -o pv_name,pe_start,vg_extent_size,seg_pe_ranges
So the total size could for example be 1MiB (1st PE) + 18620 * 4MiB (PE size).
2.)
You need to know the LUKS header size / data offset. Usually this is 4096 sectors, i.e. 2MiB. Check with cryptsetup luksDump
, Payload offset
.
So your new partition size is the LUKS Payload offset plus whatever size you resized the PV itself to.
3.)
Yes and no. LUKS doesn't keep the size in its metadata, so if you are going to close the LUKS container, or even reboot, then yes, it will just use the size of the block device itself.
But for an online resize, you would need to set it with cryptsetup resize
, to whatever size you used in pvresize
.
4.)
I sometimes do this by passing the offending device in read-only mode to a qemu/KVM instance, running some Linux rescue system. It's hard to check on the host (with, say, a read-only loop device) because LVM doesn't like to see duplicate PV UUIDs, or VG/LV names. LVM will refuse to activate, should the PV turn out to be smaller than expected.
Excellent, thank you. Note for self and others:cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.
â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to usepvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?
â Tom Hale
Aug 4 at 4:10
Always use-v
withcryptsetup
, or be sure to check its exit status.
â Tom Hale
Aug 4 at 4:14
Get PE size from:sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
1.)
From the man page:
pvresize
will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be.
So you could just do this by trial & error. Actually pvresize
will tell you part of it:
/dev/dm-7: cannot resize to 17564 extents as 18620 are allocated.
To determine the exact size, you need to know the PE size (e.g. 4MiB) and 1st PE offset (e.g. 1MiB). And of course, the number of the last allocated extent.
pvs -o pv_name,pe_start,vg_extent_size,seg_pe_ranges
So the total size could for example be 1MiB (1st PE) + 18620 * 4MiB (PE size).
2.)
You need to know the LUKS header size / data offset. Usually this is 4096 sectors, i.e. 2MiB. Check with cryptsetup luksDump
, Payload offset
.
So your new partition size is the LUKS Payload offset plus whatever size you resized the PV itself to.
3.)
Yes and no. LUKS doesn't keep the size in its metadata, so if you are going to close the LUKS container, or even reboot, then yes, it will just use the size of the block device itself.
But for an online resize, you would need to set it with cryptsetup resize
, to whatever size you used in pvresize
.
4.)
I sometimes do this by passing the offending device in read-only mode to a qemu/KVM instance, running some Linux rescue system. It's hard to check on the host (with, say, a read-only loop device) because LVM doesn't like to see duplicate PV UUIDs, or VG/LV names. LVM will refuse to activate, should the PV turn out to be smaller than expected.
1.)
From the man page:
pvresize
will refuse to shrink PhysicalVolume if it has allocated extents after where its new end would be.
So you could just do this by trial & error. Actually pvresize
will tell you part of it:
/dev/dm-7: cannot resize to 17564 extents as 18620 are allocated.
To determine the exact size, you need to know the PE size (e.g. 4MiB) and 1st PE offset (e.g. 1MiB). And of course, the number of the last allocated extent.
pvs -o pv_name,pe_start,vg_extent_size,seg_pe_ranges
So the total size could for example be 1MiB (1st PE) + 18620 * 4MiB (PE size).
2.)
You need to know the LUKS header size / data offset. Usually this is 4096 sectors, i.e. 2MiB. Check with cryptsetup luksDump
, Payload offset
.
So your new partition size is the LUKS Payload offset plus whatever size you resized the PV itself to.
3.)
Yes and no. LUKS doesn't keep the size in its metadata, so if you are going to close the LUKS container, or even reboot, then yes, it will just use the size of the block device itself.
But for an online resize, you would need to set it with cryptsetup resize
, to whatever size you used in pvresize
.
4.)
I sometimes do this by passing the offending device in read-only mode to a qemu/KVM instance, running some Linux rescue system. It's hard to check on the host (with, say, a read-only loop device) because LVM doesn't like to see duplicate PV UUIDs, or VG/LV names. LVM will refuse to activate, should the PV turn out to be smaller than expected.
edited Aug 3 at 17:20
answered Aug 3 at 17:14
frostschutz
23.6k14370
23.6k14370
Excellent, thank you. Note for self and others:cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.
â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to usepvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?
â Tom Hale
Aug 4 at 4:10
Always use-v
withcryptsetup
, or be sure to check its exit status.
â Tom Hale
Aug 4 at 4:14
Get PE size from:sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
add a comment |Â
Excellent, thank you. Note for self and others:cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.
â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to usepvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?
â Tom Hale
Aug 4 at 4:10
Always use-v
withcryptsetup
, or be sure to check its exit status.
â Tom Hale
Aug 4 at 4:14
Get PE size from:sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
Excellent, thank you. Note for self and others:
cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.â Tom Hale
Aug 4 at 3:43
Excellent, thank you. Note for self and others:
cryptsetup resize --size
takes 512-byte sectors, so multiply PV MBs by 2048.â Tom Hale
Aug 4 at 3:43
Wouldn't it be best practice to use
pvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?â Tom Hale
Aug 4 at 4:10
Wouldn't it be best practice to use
pvresize --setphysicalvolumesize <smaller-partition-size>M
? (The units are always powers of 2, regardless of capitalisation). Would you consider adding this to your answer?â Tom Hale
Aug 4 at 4:10
Always use
-v
with cryptsetup
, or be sure to check its exit status.â Tom Hale
Aug 4 at 4:14
Always use
-v
with cryptsetup
, or be sure to check its exit status.â Tom Hale
Aug 4 at 4:14
Get PE size from:
sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
Get PE size from:
sudo pvdisplay /dev/mapper/<NAME>
â Tom Hale
yesterday
add a comment |Â
up vote
0
down vote
Consider pvshrink
which does most of the calculations in frostschutz's answer, and has a --test
mode which doesn't make any changes.
add a comment |Â
up vote
0
down vote
Consider pvshrink
which does most of the calculations in frostschutz's answer, and has a --test
mode which doesn't make any changes.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Consider pvshrink
which does most of the calculations in frostschutz's answer, and has a --test
mode which doesn't make any changes.
Consider pvshrink
which does most of the calculations in frostschutz's answer, and has a --test
mode which doesn't make any changes.
answered Aug 4 at 4:30
Tom Hale
5,61712370
5,61712370
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460374%2fmaximally-shrink-lvm-pv-and-luks-container-partition%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Doesn't
pvresize
use the smallest possible size by default?â ajeh
Aug 3 at 18:30