无法删除 rootfs 的 LVM2 快照

无法删除 rootfs 的 LVM2 快照

在将我的服务器从 Debian Jessie 升级到 Debian Stretch 之前,我创建了 rootfs 的 LVM2 快照 ( /)。

根据多种工具,我的存储目前的样子如下。/dev/intraid/root是我原来的rootfs,/dev/intraid/root-snapshot是快照:

$ sudo lvdisplay
  --- Logical volume ---
  LV Path                /dev/intraid/root
  LV Name                root
  VG Name                intraid
  LV UUID                0d5hwZ-07Lv-3Yxb-cff3-95za-Rrcx-9y6eQv
  LV Write Access        read/write
  LV Creation host, time newsrv, 2015-05-26 09:32:04 +0800
  LV snapshot status     source of
                         root-snapshot [active]
  LV Status              available
  # open                 1
  LV Size                3.18 TiB
  Current LE             834465
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/intraid/root-snapshot
  LV Name                root-snapshot
  VG Name                intraid
  LV UUID                A9sjTI-gcV8-WTLi-wZ0I-J7O6-4hdc-AQSxZj
  LV Write Access        read/write
  LV Creation host, time newsrv, 2018-05-04 19:25:12 +0800
  LV snapshot status     active destination for root
  LV Status              available
  # open                 1
  LV Size                3.18 TiB
  Current LE             834465
  COW-table size         180.00 GiB
  COW-table LE           46080
  Allocated to snapshot  57.08%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3


$ lsblk -t
sdf                                      0   4096       0    4096     512    1 cfq       128  128    0B
├─sdf1                                   0   4096       0    4096     512    1 cfq       128  128    0B
├─sdf2                                   0   4096       0    4096     512    1 cfq       128  128    0B
│ └─md0                                  0   4096       0    4096     512    1           128  128    0B
│   ├─intraid-root-real                  0   4096       0    4096     512    1           128  128    0B
│   │ ├─intraid-root                     0   4096       0    4096     512    1           128  128    0B
│   │ └─intraid-root--snapshot           0   4096       0    4096     512    1           128  128    0B
│   └─intraid-root--snapshot-cow         0   4096       0    4096     512    1           128  128    0B
│     └─intraid-root--snapshot           0   4096       0    4096     512    1           128  128    0B
└─sdf3                                   0   4096       0    4096     512    1 cfq       128  128    0B
sdg                                      0   4096       0    4096     512    1 cfq       128  128    0B
├─sdg1                                   0   4096       0    4096     512    1 cfq       128  128    0B
├─sdg2                                   0   4096       0    4096     512    1 cfq       128  128    0B
│ └─md0                                  0   4096       0    4096     512    1           128  128    0B
│   ├─intraid-root-real                  0   4096       0    4096     512    1           128  128    0B
│   │ ├─intraid-root                     0   4096       0    4096     512    1           128  128    0B
│   │ └─intraid-root--snapshot           0   4096       0    4096     512    1           128  128    0B
│   └─intraid-root--snapshot-cow         0   4096       0    4096     512    1           128  128    0B
│     └─intraid-root--snapshot           0   4096       0    4096     512    1           128  128    0B
└─sdg3                                   0   4096       0    4096     512    1 cfq       128  128    0B

$ sudo blkid
/dev/sdf1: UUID="C622-1FAD" TYPE="vfat" PARTUUID="3d63a1ce-dd19-4396-9f9c-7894a4e9b256"
/dev/sdf2: UUID="3eb2349d-df83-c9a5-7151-9bdcb40449f8" UUID_SUB="b04a81da-8279-8ade-130d-65478f415085" LABEL="newsrv:0" TYPE="linux_raid_member" PARTUUID="607b2070-1de3-4e58-89f4-401d3144d52c"
/dev/sdf3: UUID="9b8fb3d2-4bb3-4a48-8b26-23af503b9d28" TYPE="swap" PARTUUID="8778cdc1-1fd8-4af0-b7a0-9dbca0d137fa"
/dev/sdg1: UUID="C623-571D" TYPE="vfat" PARTUUID="56f5dc2f-0562-4590-a54d-8c705dfef79f"
/dev/sdg2: UUID="3eb2349d-df83-c9a5-7151-9bdcb40449f8" UUID_SUB="8370e4ce-6b8b-5cdf-1043-60e748758898" LABEL="newsrv:0" TYPE="linux_raid_member" PARTUUID="ee82035a-6e8a-4bb8-9828-336ee85d3afd"
/dev/sdg3: UUID="a3062d00-d91b-490d-b366-7cfbfb42c09d" TYPE="swap" PARTUUID="fb6b3047-bfd4-4502-97ba-1a58197e75f4"
/dev/md0: UUID="44gLpv-engQ-I0KW-VJ0e-2Q6Z-OCeI-m0HSWq" TYPE="LVM2_member"
/dev/mapper/intraid-root: UUID="a96458d1-87d6-4cf6-a004-7b8ceb3ae31f" TYPE="xfs"
/dev/mapper/intraid-root--snapshot: UUID="a96458d1-87d6-4cf6-a004-7b8ceb3ae31f" TYPE="xfs"

$ mount
/dev/mapper/intraid-root on / type xfs (rw,relatime,attr2,inode64,noquota)
/dev/mapper/intraid-root on /srv/matlab_chroot/usr/local/MATLAB type xfs (rw,relatime,attr2,inode64,noquota)
/dev/mapper/intraid-root on /srv/matlab_chroot/shared_home type xfs (rw,relatime,attr2,inode64,noquota)
/dev/sdf1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)
/dev/mapper/intraid-root on /srv/matlab_chroot/mnt/nethome-new type xfs (rw,relatime,attr2,inode64,noquota)

$ sudo lsof /dev/mapper/intraid-root--snapshot
COMMAND      PID USER   FD   TYPE DEVICE      SIZE/OFF NODE NAME
grub-moun 218357 root    3r   BLK  253,3 0x32ee7fe0000 2115 /dev/mapper/../dm-3

$ sudo lsof /dev/intraid/root-snapshot
COMMAND      PID USER   FD   TYPE DEVICE      SIZE/OFF NODE NAME
grub-moun 218357 root    3r   BLK  253,3 0x32ee7fe0000 2115 /dev/intraid/../dm-3

$ sudo lsof /dev/mapper/intraid-root--snapshot-cow

$ sudo lsof /dev/mapper/intraid-root-real

$ findmnt
TARGET                                SOURCE                           FSTYPE          OPTIONS
/                                     /dev/mapper/intraid-root         xfs             rw,relatime,attr2,inode64,noquota
├─/srv/matlab_chroot/usr/local/MATLAB /dev/mapper/intraid-root[/usr/local/MATLAB]
│                                                                      xfs             rw,relatime,attr2,inode64,noquota
├─/srv/matlab_chroot/shared_home      /dev/mapper/intraid-root[/home]  xfs             rw,relatime,attr2,inode64,noquota
├─/srv/matlab_chroot/mnt/nethome-new  /dev/mapper/intraid-root[/mnt/nethome-new]

请注意,快照不是根据 的输出安装的mount

但是,当我尝试删除快照时,我收到以下消息:

$ sudo lvremove -f intraid/root-snapshot
  Logical volume intraid/root-snapshot in use.

我该怎么做才能放弃它?

答案1

您的mount命令输出显然已被修剪。不幸的是,您似乎切断了与问题相关的内容。

看起来进程 218357 可能仍在访问快照。从部分命令名称来看,它似乎是grub-mount.由于它使用FUSE和GRUB的驱动程序来访问文件系统,因此它直接将LV设备作为“原始磁盘设备”进行访问。

出于同样的原因,它不像常规安装座那样可见。我刚刚安装了我的/dev/sda1grub-mount它看起来像这样:

# grub-mount /dev/sda1 /mnt
# mount
[...other mount points omitted...]
grub-mount on /mnt type fuse.grub-mount (rw,nosuid,nodev,relatime,user_id=0,group_id=0)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)

请注意,grub-mounted 文件系统显示为类型fuse.grub-mount,并且该行并不指示实际安装了哪个磁盘设备。fusectl on /sys/fs/fuse/connections当使用基于 FUSE 的挂载条目时,总是出现第二个挂载条目:它是 FUSE 接口的一部分。

因此,首先找到并卸载它,grub-mount因为它似乎使快照设备保持打开状态。卸载后,您应该能够使用最初尝试的命令正常删除快照。

相关内容