LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Reply
  Search this Thread
Old 10-06-2011, 02:22 PM   #1
mfons
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Rep: Reputation: 1
LVM question


Hello,
I'm trying to make a script to mount all filesystems that could have a VG.
The /etc/fstab does not have the info about filesystems, I must guest from the info of the VG.
I can run 'lvs' to see what lv's are opened, I can run a 'mount' to see where is it mounted, and so on.
But if the filesystems are not mounted and they have never been in the machine, I can't run 'lsvg -l volume_group' like I can do in AIX, and list the lv's and fs's and mount them.
Do you know any flag or command that could show me that info?

Thank you.
 
Old 10-06-2011, 02:56 PM   #2
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
I'm not entirely sure which distro you are speaking of, but from a Red Hat stand point.

vgdisplay - will list all Volumegroups
lvdisplay - will list all Logical VGs

mount -a will mount all filesystems listed in /etc/fstab

Any Logical Volume must either be listed in /etc/fstab or mounted manually.

Using mount or viewing /etc/mtab file will list currently mounted devices.

Hopefully this is helpful. If not then disregard.
 
Old 10-06-2011, 03:22 PM   #3
mfons
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 1
Yes, I know I can mount filesystems listed in fstab but my question is about moving vg from a machine to another.
Maybe into my vg which I want to move from machine A to machine B, when it was in machine A, maybe I could have create a new lv and fs. In this case, the fstab in machine B will be obsolete. How can I see what new filesystems are there in the VG which I've imported into machine B and create mount point and mount it later?
Again, if someone has worked with AIX, it is very simple to do. When you import a vg into a machine, the /etc/filesystems (the /etc/fstab in AIX OS) is updated and you can list lv's and the filesystems they have associated. And then, mount them, if you want. Or let a script do ir for you. It doesn't mind if the vg has new fs or not, you can list all of them and do whatever you want.
 
Old 10-06-2011, 05:21 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
IIRC, the command vgchange -a y will activate all available logical volumes and volume groups. You can then do a ls /dev/mapper to see what's available.

I no longer use LVM, but my rc.local file includes this code:
Code:
#############################################################################
#
# Activate all inactive LVs
#
#############################################################################
vg_activate() {
  # Make sure the color codes are defined
  [ -z "${csi}" ] && define_colors
  echo
  echo "${bold_blue}Mounting all inactive LVGs and any LVs listed in /etc/fstab.${reset}"
  # Do we have any inactive volume groups?
  inactive=$(sucmd /sbin/lvscan | grep 'inactive' &>/dev/null)
  if [ $? -eq 0 ] && [ -n "${inactive}" ]
  then
  # OK, what are there names?
    vg_list=$(echo "${inactive}" | cut -d \' -f 2 | cut -d / -f 3 | sort -u)
  #  echo Inactive volume groups: "$vg_list"
  # Activate any volume group metioned in a "noauto" line
    for v in "${vg_list}"; do
  # Get any mentions
      in_fstab=$(grep "${v}".*noauto /etc/fstab 2>/dev/null)
      [[ $? -ne 0 ]] && continue
      [[ -z ${in_fstab} ]] && continue
  # Activate the logical volume
      sucmd /sbin/vgchange -a y ${v}
      [[ $? -ne 0 ]] && continue
  # And mount the volume group.
      for x in "${in_fstab}"; do
        mp=$(echo ${x} | cut -d " " -f 2)
        [[ -z "&{mp}" ]] && continue
        sucmd mount ${mp}
        if [[ $? -eq 0 ]]
        then
          echo "${bold_green}${mp} mounted.${reset}"
        else
          echo "${bold_red}Failed to mount ${mp}.${reset}"
        fi
      done
    done
#  else
#    echo "${bold_green}No volume groups are inactive.${reset}"
  fi
}
I wrote that function when I had several USB drives containing different LVs, any one (or more) of which could be plugged into my system. I have "pre-defined" the various LV possibilities in /etc/fstab using a UUID= device and a "noauto" option. With that and the above function, and such USB drive would be automatically mounted whenever I booted, and I had another script that used the same function which I could run after I'd plugged in one of those USB drives.

Note that not all the functions (e.g., define_colors, sucmd) are defined in that snippit, but the function's purpose should be obvious in the context.

Last edited by PTrenholme; 10-06-2011 at 05:45 PM. Reason: Insert omitted phrase
 
Old 10-07-2011, 12:16 AM   #5
mfons
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 1
So, are all of you saying that I can't mount any filesystem if it is not defined in my fstab?
Can't I list the filesystems available in one vg ?
 
Old 10-07-2011, 01:29 AM   #6
cendryon
Member
 
Registered: Aug 2005
Location: France
Distribution: Slackware64 current
Posts: 82

Rep: Reputation: 30
Hi

Quote:
Originally Posted by mfons View Post
So, are all of you saying that I can't mount any filesystem if it is not defined in my fstab?
Of course you can, you have to express the whole mount stanza instead of the short form relying on fstab content:
Code:
mount -t filesystem_type -o mount_options /dev/vgname/lvname /path/to/mount/point
Quote:
Originally Posted by mfons View Post
Can't I list the filesystems available in one vg ?
PTrenholme gave the commands to list LV (logical volumes) from the VG.
LVs from active VGs will show as /dev/mapper/vgname-lvname and as /dev/vgname/lvname

Cheers
 
Old 10-07-2011, 03:44 AM   #7
mfons
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 1
cendryon, I know I can do that.
But, what will you do if you will have to mount every filesystem that contains a vg on a machine that does not have the mount point and that machine have never mount that filesystems? How do you know where to mount a lv with the only information that provides the lvs ?
I'm trying to demonstrate that I can do the same with Linux than with AIX, talking about LVM
 
Old 10-07-2011, 02:46 PM   #8
cendryon
Member
 
Registered: Aug 2005
Location: France
Distribution: Slackware64 current
Posts: 82

Rep: Reputation: 30
Hi

I would write a shell script. Whenever I plug a drive (or several, depending of the physical volume involved) containing a volume group, I'd run that script.

Along the lines of PTrenholme script, I would start with "vgchange -ay" to activate the VG and its LVs.
Then, I'd use vgs and lvs to list all the LVs.
I'll then compare it to the content of /etc/fstab and /etc/mtab to ignore already mounted LVs, and to mount known LVs relying on fstab.
Then, with the remaining unknown LVs, I'd use blkid to have the device (/dev/mapper/vgname-lvname), its UUID, and above all its filesystem type.
With that, I'd create the mount point with "mkdir -p /path/to/mount/point/vgname-lvname/" for instance, and issue the full mount command.

As an alternative, I would auto-add previously unknown LVs to fstab, to be mounted with the short form of the mount command.

That is for starters. I would then look into udev to have it do all that for me a la USB thumbdrive, but I don't known yet if it is possible.

Cheers
 
Old 10-08-2011, 01:13 PM   #9
mfons
LQ Newbie
 
Registered: Mar 2009
Posts: 26

Original Poster
Rep: Reputation: 1
I'm starting to think I can not do what I do with AIX.
So, I think I will compare fstab of machine A with fstab of machine B and I will add (or not) the necessary filesystems entries, and then mount them.

Thank you every one.

I'll post the results
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM Question Devyn Linux - Server 6 09-09-2011 11:41 PM
LVM Question dcellis1950 Linux - General 7 11-12-2009 09:12 AM
LVM question sang_froid Linux - General 2 03-10-2009 10:25 AM
Question about LVM Torr Linux - General 1 05-28-2006 07:36 AM
question about LVM an2ny_18 Linux - Software 3 03-12-2006 04:35 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration