我在LVM LV之上的LUKS上有
一个500GiB ext4
文件系统.我想将LV的大小调整为100GiB.我知道如何在LVM LV之上调整ext4的大小,但我该如何处理LUKS卷呢?
@H_340_16
@mgorven
@moab:~% sudo lvdisplay /dev/moab/
BACkup
--- Logical volume ---
LV Name /dev/moab/
BACkup
VG Name moab
LV UUID nQ3z1J-Pemd-uTEB-fazN-yEux-nOxP-QQair5
LV Write Access read/write
LV Status available
# open 1
LV Size 500.00 GiB
Current LE 128000
Segments 1
Al
LOCATIOn inherit
Read ahead sectors auto
- currently set to 2048
Block device 252:3
mgorven
@moab:~% sudo cryptsetup status
BACkup
/dev/mapper/
BACkup is active and is in use.
type: LUKS1
cipher: aes-cbc-essiv:sha256
keysize: 256 bits
device: /dev/mapper/moab-
BACkup
offset: 3072 sectors
size: 1048572928 sectors
mode: read/write
mgorven
@moab:~% sudo tune2fs -l /dev/mapper/
BACkup
tune2fs 1.42 (29-Nov-2011)
Filesy
stem volume name:
BACkup
Last mounted on: /srv/
BACkup
Filesy
stem UUID: 63877e0e-0549-4c73-8535-b7a81eb363ed
Filesy
stem magic
number: 0xEF53
Filesy
stem revision #: 1 (dynami
C)
Filesy
stem features: has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file unini
T_Bg dir_nlink extra_isize
Filesy
stem flags: signed_directory_hash
Default mount options: (non
E)
Filesy
stem state: clean with errors
Errors behavior: Con
Tinue
Filesy
stem OS type: Linux
Inode count: 32768000
Block count: 131071
616
Reserved block count: 0
Free blocks: 112894078
Free inodes: 32044830
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 992
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
RAID
Stride: 128
RAID
Stripe width: 128
Flex block group size: 16
Filesy
stem created: Sun Mar 11 19:24:53 2012
Last mount time: Sat May 19 13:29:27 2012
Last write time: Fri Jun 1 11:07:22 2012
Mount count: 0
Maximum mount count: 100
Last
checked: Fri Jun 1 11:03:50 2012
check interval: 31104000 (12 months)
Next
check after: Mon May 27 11:03:50 2013
Lifetime writes: 118 GB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 383bcbc5-fde9-4720-b98e-2d6224713ecf
Journal
BACkup: inode blocks
LUKS实际上并不存储设备的大小 – 它只是在打开卷时发现它.因此,只有
在此过程中未
关闭并重新打开音量(例如,进行在线增长)时才会发挥作用.
在这种情况下,需要重新发现开放卷的大小.
要缩小音量,请使用以下过程:
>使用umount卸载文件系统
>使用resize2fs调整文件系统的大小
>使用cryptsetup luksClose关闭LUKS卷
>使用lvreduce或lvresize调整LV的大小
>使用cryptsetup luksOpen打开LUKS卷
>使用mount挂载文件系统
您还可以省略luksClose和luksOpen步骤,并在调整LV大小后使用cryptsetup resize.还要记住,LUKS使用一些额外的空间来存储元数据,因此LV需要比文件系统略大.我通常会将文件系统的大小调整得更小,然后在调整LV大小后再次增大它.
如果您正在扩展文件系统并希望在线进行,则可以使用以下过程:
>使用lvextend或lvresize调整LV的大小>使用cryptsetup resize更新打开的LUKS卷的大小>使用resize2fs扩展文件系统