调整LUKS加密卷的大小


14

我在LVM LV顶部的LUKS顶部有一个500GiB ext4文件系统。我想将LV的大小调整为100GiB。我知道如何在LVM LV上调整ext4的大小,但是如何处理LUKS卷?

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
  Allocation             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)
Filesystem volume name:   backup
Last mounted on:          /srv/backup
Filesystem UUID:          63877e0e-0549-4c73-8535-b7a81eb363ed
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    (none)
Filesystem state:         clean with errors
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              32768000
Block count:              131071616
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
Filesystem 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

Answers:


21

LUKS实际上并不存储设备的大小,它只是在打开卷时发现它。因此,只有在该过程中未关闭并重新打开卷(例如进行在线扩展)的情况下,它才起作用。在这种情况下,需要重新发现打开卷的大小。

要缩小音量,请使用以下过程:

  1. 使用以下命令卸载文件系统 umount
  2. 使用以下命令调整文件系统的大小 resize2fs
  3. 使用以下命令关闭LUKS卷 cryptsetup luksClose
  4. 使用lvreduce或调整LV的大小lvresize
  5. 使用以下命令打开LUKS卷 cryptsetup luksOpen
  6. 用以下命令挂载文件系统 mount

您还可以省略luksCloseluksOpen步骤,并cryptsetup resize在调整LV大小后使用。还请记住,LUKS使用一些额外的空间来存储元数据,因此LV需要比文件系统稍大。我通常将文件系统的大小显着减小,然后在调整LV的大小后再次增大它的大小。

如果您正在扩展文件系统并希望在线进行操作,则可以使用以下过程:

  1. 使用lvextend或调整LV的大小lvresize
  2. 使用以下命令更新打开的LUKS卷的大小 cryptsetup resize
  3. 使用以下方式扩展文件系统 resize2fs
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.