ネタバレ
# mount -o ro,loop,offset=[offset] /dev/[VG_Name]/[LV_Name] /mnt
なんなの
ごくごくたまにしかこういう作業しないこともあって忘れがちになりがちなので(新年最初の)備忘録的なやつです。
参考リンク
概要
えー。。。仮想環境が飛んじゃいましてね!
ふとした時に KVM のゲストで使っている LVM のボリュームからコンフィグを取り出したいときがあります。
Google 先生に助けをもらいつつ上の参考リンクを見ながらなんとか別の環境でマウントして中身を見られるようにします。
ん? 暗号化 LVM? その時は(ぇ
LVM ボリューム環境
[root@example ~]# fdisk -l /dev/sdc
Disk /dev/sdc: 2.73 TiB, 3000592982016 bytes, 5860533168 sectors
Disk model: EXAM-EXAMPLE
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 9C87A065-6611-1742-AF57-DB048CC40E35
Device Start End Sectors Size Type
/dev/sdc1 2048 5860533134 5860531087 2.7T Linux LVM
[root@example ~]# lvscan
ACTIVE '/dev/vmg_20220425/system' [10.00 GiB] inherit
ACTIVE '/dev/vmg_20220425/data' [<2.72 TiB] inherit
[root@example ~]# fdisk -l -u /dev/vmg_20220425/system
Disk /dev/vmg_20220425/system: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x733feba1
Device Boot Start End Sectors Size Id Type
/dev/vmg_20220425/system1 * 2048 206847 204800 100M 83 Linux
/dev/vmg_20220425/system2 206848 2142207 1935360 945M 82 Linux swap / Solaris
/dev/vmg_20220425/system3 2142208 20971519 18829312 9G 83 Linux
[root@example ~]#
「あれ?どっかで見たやつかな?」と思ったあなた、それ以上の詮索は(ぉぃ
今回「/」である「/dev/vmg_20220425/system3」の中身を見に行きます1。
下準備
[root@ch2base ~]# mount /dev/vmg_20220425/system3 /mnt
mount: /mnt: special device /dev/vmg_20220425/system3 does not exist.
このままマウントさせようとすると「そんなデバイスなんてねぇから!」と怒られます。
[root@example ~]# mount /dev/vmg_20220425/system /mnt
mount: /mnt: wrong fs type, bad option, bad superblock on /dev/mapper/vmg_20220425-vmguest, missing codepage or helper program, or other error.
また上記のようにすると「そんな(マウントに必要な)スーパーブロックなんてねぇから!」と怒られます(アタリマエダ
今回はループバックデバイスとして読ませるので2オフセット値を計算する必要があります。
[root@example ~]# fdisk -l -u /dev/vmg_20220425/system
Units: sectors of 1 * 512 = 512 bytes
・・・
Device Boot Start End Sectors Size Id Type
/dev/vmg_20220425/system3 2142208 20971519 18829312 9G 83 Linux
この LVM で使っているセクタ数は「512[B]」で、開始セクタが「2142208」というのを覚えておきます。
オフセット値は「セクタ数*開始セクタ」で求められます。 今回の場合は「512 * 2142208 = 1096810496」となります。
マウント
マウントする際、マウントオプションに下準備で求めたオフセット値をセットします
[root@example ~]# mount -o ro,loop,offset=1096810496 -t xfs /dev/vmg_20220425/system /mnt
[root@example ~]#
/mnt にループバックデバイスをマウントして何も怒られなければきっと成功しているはず、、、!!! もしも怒られたらオフセット値が間違ってますので再度確認&計算し直しましょう。
試しに /mnt の中身をリストに出してみます。
[root@example ~]# ls -l /mnt
合計 20
lrwxrwxrwx 1 root root 7 7月 19 2022 bin -> usr/bin
drwxr-xr-x 2 root root 6 7月 19 2022 boot
drwxr-xr-x 4 root root 182 7月 19 2022 dev
drwxr-xr-x 98 root root 8192 11月 21 20:09 etc
drwxr-xr-x 2 root root 6 11月 21 20:14 home
lrwxrwxrwx 1 root root 31 5月 27 2025 initrd.img -> boot/initrd.img-5.10.0-35-amd64
lrwxrwxrwx 1 root root 31 4月 23 2025 initrd.img.old -> boot/initrd.img-5.10.0-34-amd64
lrwxrwxrwx 1 root root 7 7月 19 2022 lib -> usr/lib
lrwxrwxrwx 1 root root 9 7月 19 2022 lib32 -> usr/lib32
lrwxrwxrwx 1 root root 9 7月 19 2022 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 7月 19 2022 libx32 -> usr/libx32
drwxr-xr-x 3 root root 33 7月 19 2022 media
drwxr-xr-x 3 root root 18 12月 5 2023 mnt
drwxr-xr-x 2 root root 6 7月 19 2022 opt
drwxr-xr-x 2 root root 6 7月 1 2022 proc
drwx------ 8 root root 4096 10月 18 07:48 root
drwxr-xr-x 2 root root 6 7月 19 2022 run
lrwxrwxrwx 1 root root 8 7月 19 2022 sbin -> usr/sbin
drwxr-xr-x 2 root root 6 7月 19 2022 srv
drwxr-xr-x 2 root root 6 7月 1 2022 sys
drwxrwxrwt 7 root root 93 3月 16 2024 tmp
drwxr-xr-x 14 root root 160 7月 19 2022 usr
drwxr-xr-x 12 root root 150 7月 19 2022 var
lrwxrwxrwx 1 root root 28 5月 27 2025 vmlinuz -> boot/vmlinuz-5.10.0-35-amd64
lrwxrwxrwx 1 root root 28 4月 23 2025 vmlinuz.old -> boot/vmlinuz-5.10.0-34-amd64
[root@example ~]#
ヨシッ!!
まとめ
一番はまず日頃から別の場所にバックアップはとっておこうね!
わけあって仮想環境を飛ばしても別の物理環境にループバックデバイスで読ませることが出来たらある程度なんとかなりそう! という記事でした。
仮想環境から一時的に物理環境に引っ越す場合とかにも使えると思います。
一番はさっさと新しい仮想環境を作った上でそのまま引き継がせるべきなんですけど予算がね!(キレ声