Linux - EnterpriseThis forum is for all items relating to using Linux in the Enterprise.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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
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
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
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
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.