There might be need some time to mount OVM guest server disk images directly from OVM Server and modify some settings e.g. that prevent the server from booting or change passwords.
Typically doing this is quite straight forward by setting up a loop device and mounting the wanted partition. If the target partition is LVM2 partition, this becomes a bit more complex in OracleVM environment.
The problem is that by default OracleVM server /etc/lvm/lvm.conf has filtering enabled to prevent discovering loop device LVM2 devices.
This article describes the steps to perform to get a LVM2 volume mounted and data there changed off-line.
If you are unsure what you are doing, please make a backup of the virtual disk and lvm.conf you are going to change, before you proceed with following actions.
Instructions below expect that an experience Linux/OVM administrator knows what she/he is doing. I’m not going into details what a root will do after issuing the chroot command. ANY CHANGES ARE AT YOUR OWN RISK. TAKE GOOD BACKUPS ANYWAYS.
Preparation: modify /etc/lvm/lvm.conf
In order for OVM server to able to scan the loop devices /etc/lvm.conf needs to be modified.
# 30.6.2017 Harri Kaukovuo, modify the preferred_names #preferred_names = [ "^/dev/mpath/", "^/dev/mapper/mpath", "^/dev/[hs]d" ] preferred_names = [ ] # 30.6.2017 Harri Kaukovuo, uncomment filter = [ "a|.*/|" ] # 30.6.2017 Harri Kaukovuo, comment out this line #global_filter = [ "r|.*/|" ]
Mount the Virtual LVM2 Disk
Find the next free loop device:
losetup –f
By default OVM Server has max 10 loop devices. You might be running out of loop devices, which you can work around by either shutting down all the guest VM servers or increasing the loop devices by adding following line in /etc/rc.local and rebooting the OVM server:
# 28.6.2017 Harri Kaukovuo
/sbin/MAKEDEV -m 32 /dev/loop
Please note that above step is only needed if you ran out of loop devices.
Anyways, when you have a free loop device, in my example I have /dev/loop9 as the loop device, you can proceed with following step which is setting up the loop device to point to the virtual disk. In the example below I have retrieved the disk image file name from OVM Manager console:
losetup /dev/loop9 /OVS/Repositories/0004fb000003000088c2307002d1b442/VirtualDisks/0004fb0000120000ba5aa22cb02675b7.img
Read partition tables from the loop device and create device maps with kpartx:
kpartx -av /dev/loop9
The output is something like:
[root@myovm01 etc]# kpartx -av /dev/loop9
add map loop9p1 (249:1): 0 401562 linear /dev/loop9 63
add map loop9p2 (249:2): 0 142898175 linear /dev/loop9 401625
Perform volume group scan: by issuing command:
vgscan
Output is like:
[root@myovm01 etc]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2
Activate volume groups by issuing command:
vgchange –ay
Output is like:
[root@myovm01 etc]# vgchange -ay
4 logical volume(s) in volume group "VolGroup00" now active
Show logical volumes:
[root@myovm01 etc]# lvscan
ACTIVE '/dev/VolGroup00/LogVol03' [42.03 GiB] inherit
ACTIVE '/dev/VolGroup00/LogVol02' [6.06 GiB] inherit
ACTIVE '/dev/VolGroup00/LogVol00' [4.00 GiB] inherit
ACTIVE '/dev/VolGroup00/LogVol01' [16.00 GiB] inherit
Mount the wanted logical volume. In this example case I know already that LogVol03 is the root partition and I want to change something there.
[root@myovm01 etc]# mount /dev/VolGroup00/LogVol03 /mnt/virtualdisk
[root@myovm01 etc]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 53G 2.8G 48G 6% /
tmpfs 3.2G 0 3.2G 0% /dev/shm
/dev/sda1 500M 145M 325M 31% /boot
none 3.2G 213k 3.2G 1% /var/lib/xenstored
/dev/mapper/361866da0905943002027220113a0a9c8
8.4T 3.0T 5.5T 36% /OVS/Repositories/0004fb000003000088c2307002d1b442
/dev/mapper/VolGroup00-LogVol03
45G 33G 9.4G 78% /mnt/virtualdisk
Use chroot to change the root directory, if you need to change something there:
chroot /mnt/virtualdisk
(do your stuff here)
Get out of chroot by issuing “exit”
Unmount the disk after use:
umount /mnt/virtualdisk
Deactivate the volume group:
[root@myovm01 ~]# vgchange --activate n VolGroup00
0 logical volume(s) in volume group "VolGroup00" now active
Delete the partition device mappings:
kpartx -dv /dev/loop9
Output is something like:
[root@myovm01 etc]# kpartx -dv /dev/loop9
del devmap : loop9p2
del devmap : loop9p1
Delete the loop device mapping:
losetup -d /dev/loop9
Now there should not be any LVM2 mappings found, also the loop device should be free:
[root@myovm01 ~]# pvscan
No matching physical volumes found
[root@myovm01 ~]# vgscan
Reading all physical volumes. This may take a while...
[root@myovm01 ~]# losetup -f
/dev/loop9
After unmounting the disk, startup the guest linux and enjoy the changes.
No comments:
Post a Comment