.png)
몇 년 전에 나는 더 큰 하드 드라이브로 넷북을 업그레이드했습니다. 아직 원하는 것이 있을 경우를 대비해 기존 하드 드라이브의 내용을 유지하고 싶었습니다.
그래서 기존 하드 드라이브를 새 하드 드라이브의 파일에 복사했습니다.
dd if=/dev/sdd5 of=~/fw-disk-image/fw-sdd5-linux-lvm-partition.raw
그리고 해당 파티션에 lvms를 읽기 전용 파일 시스템으로 마운트하기 위한 스크립트를 작성/복사했습니다.
losetup -r /dev/loop1 ~/fw-disk-image/fw-sdd5-linux-lvm-partition.raw
pvscan
vgscan
vgchange -a y fw
cd /mnt/fw
for i in root tmp usr var home
do
mount -o ro /dev/fw/$i $i
done
이제 이것은 오랫동안 작동했지만 갑자기 다음 vgchange -a y fw
명령에서 실패합니다.
# vgchange -a y fw
Error writing device /dev/loop1 at 4096 length 512.
bcache_invalidate: block (4, 0) still dirty
Failed to write mda header to /dev/loop1 fd -1
Failed to update old PV extension headers in VG fw.
Volume group "fw" not found
Cannot process volume group fw
나는 읽기 전용 루프백 장치를 만들었기 때문에 vgchange가 여기에 쓸 수 없다는 사실에 만족하지 않는 것 같습니다. 마지막으로 디스크를 사용했을 때 파일 시스템이 더러워진 것 같지만 무시하고 싶습니다.
현재 시스템이 현재 실행 중입니다.
Linux fw 4.19.0-8-686-pae #1 SMP Debian 4.19.98-1 (2020-01-26) i686 GNU/Linux
$ vgchange --version
vgchange --version
LVM version: 2.03.02(2) (2018-12-18)
Library version: 1.02.155 (2018-12-18)
Driver version: 4.39.0
Configuration: ./configure --build=i686-linux-gnu --prefix=/usr --includedir=${prefix}/include --mandir=${prefix}/share/man --infodir=${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir=${prefix}/lib/i386-linux-gnu --libexecdir=${prefix}/lib/i386-linux-gnu --runstatedir=/run --disable-maintainer-mode --disable-dependency-tracking --exec-prefix= --bindir=/bin --libdir=/lib/i386-linux-gnu --sbindir=/sbin --with-usrlibdir=/usr/lib/i386-linux-gnu --with-optimisation=-O2 --with-cache=internal --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --with-default-pid-dir=/run --with-default-run-dir=/run/lvm --with-default-locking-dir=/run/lock/lvm --with-thin=internal --with-thin-check=/usr/sbin/thin_check --with-thin-dump=/usr/sbin/thin_dump --with-thin-repair=/usr/sbin/thin_repair --enable-applib --enable-blkid_wiping --enable-cmdlib --enable-dmeventd --enable-dbus-service --enable-lvmlockd-dlm --enable-lvmlockd-sanlock --enable-lvmpolld --enable-notify-dbus --enable-pkgconfig --enable-readline --enable-udev_rules --enable-udev_sync
엄격하게 읽기 전용으로 유지하면서 이 파티션에 LV를 (다시) 마운트할 수 있는 방법이 있습니까?
답변1
해결 방법은 다음과 같습니다. LVM이 읽기/쓰기 블록 장치를 원할 경우 읽기 전용 블록 장치를 기반으로 하는 오버레이 블록 장치를 사용하여 장치를 생성합니다(이 다른 질문을 참조하세요).
루트로서:
- 읽기 전용 블록 장치와 동일한 크기의 스파스 파일 생성
(현재 파일 시스템보다 큰 경우라도)truncate -s`blockdev --getsize64 /dev/loop1` '/tmp/overlay.bin'
- 오버레이 블록 장치 생성
loop=`losetup -f --show -- '/tmp/overlay.bin'` size=`blockdev --getsz /dev/loop1` printf '%s\n' "0 $size snapshot /dev/loop1 $loop P 8" | dmsetup create 'overlayloop1'
- LVM이 동일한 UUID를 가진 중복 PV에 대해 불평하지 않도록 하려면 /etc/lvm/lvm.conf를 편집하여 원래 /dev/loop1을 제외하십시오
devices { scan = [ "/dev/mapper" ] }
.devices { filter = [ "r|/dev/loop1|" ] }
하십시오LVM 위키에 대한 FAQ) - 이제
vgchange -a y fw
작동합니다.
사용 중에 /tmp/overlay.bin 파일을 모니터링해야 하지만 LV의 파일 시스템이 읽기 전용으로 마운트된 경우 특별히 증가해서는 안 됩니다.
루프 장치를 닫으려면:
vgchange -a n fw
dmsetup remove /dev/mapper/overlayloop1
rm /tmp/overlay.bin
losetup -d /dev/loop1
답변2
파일 시스템이 더러운 것이 아니라(그럴 수도 있지만 여기서는 문제가 아닙니다) LVM bcache 구조입니다. 일부 기본 설정이 변경되어 더 이상 작동하지 않는 것 같습니다.
제안:
루프 장치를 rw 모드로 한 번 설정하십시오. 그러면 문제가 해결될 것입니다. 성공한 후에
vgchange
는 루프 장치를 파괴하고 다시 설정할 수 있습니다. 파일 시스템을 마운트하지 않고.
loopdev rw를 만들지 않고도 문제가 해결되는지 시도해 볼 수도 있습니다. 100M 파일이 넘는 또 다른 loopdev를 만들고 스냅샷을 만들 수 있습니다. 안타깝게도dmsetup
. 그런 다음 LVM 도구가 스냅샷을 스캔하도록 할 수 있습니다. 모든 변경 사항은 스냅샷에 기록됩니다.노력하다
vgchange -a y --readonly fw