Initialise mount LVM (Logical Volume Manager)

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
darkcity
Posts: 2534
Joined: Sun 23 May 2010, 19:16
Location: near here
Contact:

Initialise mount LVM (Logical Volume Manager)

#1 Post by darkcity »

LVM (Logical Volume Manager) is a layer between a filesystem and the physical disk partitions. More information on Wikipedia.

It is useful for resizing partitions and moving data in live situations. If Puppy is used to inspect what is on PC its useful to be able to mount Logical Volumes (LV).

Slacko 6.3.2 already has lvm present, but entering lvdisplay in the terminal reveals any LVs present are 'not active'. A couple of steps resolves this:

1. Initialise

The couple of commands in the script initialises the LVM system.

Code: Select all

#!/bin/sh
#### plvm-initialise v0.000 experimental
#script to initialise lvm2 logical volumes (lv)
#place in ~/Startup to run on boot, use separate script to mount eg. pmount-lvm-all.pl
dmsetup mknodes
vgscan --ignorelockingfailure
vgchange -ay --ignorelockingfailure
download

If the script is placed in ~/Startup the LVM system will be active on boot. The devices are listed in /dev/ as dm-0, dm-1 etc. (this is what you will see listed on shutdown make savefile).

The devices are mapped to their names at /dev/mapper/.

2.Mount LVs

The LVs can be mounted using:

mount /dev/mapper/<vg_name>-<lv_name> <mount directory>

This script mounts all LVs found at /mnt/<vg_name>-<lv_name>. Its a bit crude, but does the job for inspecting what's on a PC.

Code: Select all

#!/usr/bin/perl
#### pmount-lvm-all v0.001 experimental
#### script to all mount lv (logical volumes) at /mnt/<vg_name>-<lv_name> (after they have been initialised)
## script fails if not root user

use strict;
use warnings;

###initialise variables
my $cnt;
my $str;

###initialise lv
#put plvm-initialise in ~/Startup - it executes:
#dmsetup mknodes, vgscan --ignorelockingfailure and vgchange -ay --ignorelockingfailure
#that activates lv at /dev/mapper/<vg_name>-<lv_name>

###mkdir and mount for each lv
#get lv lists from `lvs`, with the format <vg_name>-<lv_name>
my @lvpara = `lvs --noheadings --separator '-' -o vg_name,lv_name`;    
chomp @lvpara;

#process each lv ($#lvpara is position of last entry (starting 0) -1 is empty
#might clash if something else is already mounted at /mnt/<vg_name>-<lv_name> (perhaps unlikely)
for $cnt (0 .. $#lvpara) {
	$lvpara[$cnt] =~ s/^\s+//; #next lv str, left trim white space
	$str = $lvpara[$cnt]; #next lv str -> str
	mkdir("/mnt/".$str) unless (-d "/mnt/".$str); #mkdir unless it exists, (works with space in name)
	`mount '/dev/mapper/$str' '/mnt/$str'`; #mount lv from /dev/mapper
}

exit;

download

----

Fatdog64 is LVM ready 'out of the box' I believe.

More infos:
LVM (Puppy Wiki)

8)

Post Reply