Linux:在基于LUKS(dm-crypt)的LVM物理卷上运行fsck
时间:2020-01-09 10:40:02 来源:igfitidea点击:
我在Linux中使用基于dm-crypt的透明磁盘加密子系统。
cryptsetup命令用于处理磁盘上的Linux统一密钥设置(LUKS)格式并安装分区。
我的设置包括具有LVM物理卷的RAID-10。
在Linux操作系统下,如何在基于dm-crypt/LUKS的LVM物理卷上运行fsck(文件系统检查)?
首先,您需要打开LUKS分区设备并使用cryptsetup命令设置映射。
不要在已安装的分区上运行fsck命令。
以超级用户身份执行以下命令:
# cryptsetup luksOpen /dev/md3 securebackup
输出示例:
Enter passphrase for /dev/md3:
其中:
/dev/md3
我的RAID设备。设备名称将根据您的设置而改变。securebackup
在成功验证后设置到安全备份的映射。此名称将根据您的设置而更改。
要读取所有物理卷,请执行:
# vgscan --mknodes
输出示例:
Reading all physical volumes. This may take a while... Found volume group "cryptvg" using metadata type lvm2
其中:
cryptvg
组卷名。它是使用lvm2安装程序创建的。此名称将根据您的设置而更改。
要激活逻辑卷并创建/dev/cryptvg/DEVICE名称,请执行:
# vgchange -ay
输出示例:
1 logical volume(s) in volume group "cryptvg" now active
您可以在以下位置看到您的设备名称
# ls -l /dev/cryptvg # ls -l /dev/mapper/
输出示例:
total 0 crw------- 1 root root 10, 59 Dec 6 12:27 control lrwxrwxrwx 1 root root 7 Dec 6 12:54 cryptvg-mybackup -> ../dm-1 lrwxrwxrwx 1 root root 7 Dec 6 12:50 securebackup -> ../dm-0
您可以执行以下命令以查看有关正在使用的VG的信息:
# vgdisplay
输出示例:
--- Volume group -- VG Name cryptvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 600.01 GiB PE Size 4.00 MiB Total PE 153602 Alloc PE / Size 153602 / 600.01 GiB Free PE / Size 0 / 0 VG UUID W0IDJ0-Yjt9-093X-qAzH-tbCJ-9NYH-BV1RYd
要显示物理卷的属性,请执行:
# pvdisplay
输出示例:
--- Physical volume -- PV Name /dev/dm-0 VG Name cryptvg PV Size 600.01 GiB / not usable 2.50 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 153602 Free PE 0 Allocated PE 153602 PV UUID swS5Nw-suTe-N0io-72LY-CBG5-6FhU-Tq8kYZ
或者
# pvdisplay /dev/dm-0
输出示例:
--- Physical volume -- PV Name /dev/dm-0 VG Name cryptvg PV Size 600.01 GiB / not usable 2.50 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 153602 Free PE 0 Allocated PE 153602 PV UUID swS5Nw-suTe-N0io-72LY-CBG5-6FhU-Tq8kYZ
要显示逻辑卷的属性,请执行:
# lvdisplay
输出示例:
--- Logical volume -- LV Name /dev/cryptvg/mybackup VG Name cryptvg LV UUID g0AghZ-bcv5-n6pP-AQUA-5c32-fQa1-OteSlg LV Write Access read/write LV Status available # open 0 LV Size 600.01 GiB Current LE 153602 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 6144 Block device 253:1
要检查并可能修复基于LVM2 + LUKS的Linux文件系统,请执行:
# fsck -C -V /dev/cryptvg/mybackup
或者
# fsck -C -V -y /dev/cryptvg/mybackup
输出示例:
在LVM2(基于LUKS)卷上运行fsck
完成fsck可能需要一些时间:
fsck from util-linux-ng 2.17.2 [/sbin/fsck.ext3 (1) -- /dev/mapper/cryptvg-mybackup] fsck.ext3 -C0 /dev/mapper/cryptvg-mybackup e2fsck 1.41.12 (17-May-2010) /dev/mapper/cryptvg-mybackup has been mounted 63 times without being checked, check forced. 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/cryptvg-mybackup: 483163/39329792 files (0.2% non-contiguous), 16626195/157288448 blocks
您现在可以使用mount命令挂载设备:
# mount /dev/cryptvg/mybackup /securebackup/ # df -H
输出示例:
Filesystem Size Used Avail Use% Mounted on /dev/md0 127G 930M 120G 1% / tmpfs 1.1G 0 1.1G 0% /lib/init/rw udev 1.1G 267k 1.1G 1% /dev tmpfs 1.1G 0 1.1G 0% /dev/shm /dev/md2 1.6T 88G 1.5T 6% /data /dev/mapper/cryptvg-mybackup 635G 58G 544G 10% /securebackup