LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-07-2015, 02:58 AM   #1
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Rep: Reputation: Disabled
How to create a persistent volume group


Hi,

I have created a volume group using the following instructions

truncate --size=50G /tmp/netcoolstorage
DEVICE=$(losetup --show -f /tmp/netcoolstorage)
mkfs.ext4 $DEVICE
vgcreate tivolivg /dev/loop0

Volue group gets created succesfully, but when I reboot the system the volume group gets deleted.
Is there any way to make this VG permanent?

Thanks,
Akanksha
 
Old 11-07-2015, 05:49 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 3,888

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Your loopback device is not persistent. Rerun losetup after boot (e.g. in rc.local) and your VG will reappear. Also put the loopback file somewhere else than /tmp - /tmp is the opposite of persistent.

By the way, I wonder why you need to make a filesystem on the loopback device, and why the vgcreate works without a pvcreate.

Last edited by berndbausch; 11-07-2015 at 05:51 AM.
 
Old 11-07-2015, 06:01 AM   #3
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Truncate chops off the physical volume I guess.

I tried "losetup /dev/loop1" and I got
loop: can't get info on device /dev/loop1: No such device or address

How to use this?

BTW as of now I have my Volume group intact. I have not rebooted my server.
How can I make sure that this volume group does not disappear on reboot? Just move the loopback file to some other location will help?

Where can I find my loopback file? My device is /dev/loop0

Thanks much for your help. I am new to this.
 
Old 11-07-2015, 06:45 AM   #4
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 3,888

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Quote:
Originally Posted by akajain View Post
Truncate chops off the physical volume I guess.
only if you created it before running truncate.

Quote:
I tried "losetup /dev/loop1" and I got
loop: can't get info on device /dev/loop1: No such device or address
Since you didn't create a loopback device with /dev/loop1, this is not really surprising.

Quote:
I am new to this.
Let's start at the beginning then.

For a volume group, you need one (or more) physical volumes. Create them as follows:
Code:
pvcreate devicefile
Usually, devicefile is a partition on a disk or a LUN, something like /dev/sdc1. You, however, have opted to put the physical volume on a disk file /tmp/netcoolstorage.

Since pvcreate and vgcreate expect disk devices to work on, rather than files, they can't use /tmp/netcoolstorage directly. You have to make a disk device out of /tmp/netcoolstorage, and that can be done using losetup.

Code:
DEVICE=$(losetup --show -f /tmp/netcoolstorage)
will take the first free loopback device, associate it with /tmp/netcoolstorage, and assign the name of that loopback device to the shell variable DEVICE.

You should now turn this device in a physical volume and create a volume group with it:
Code:
pvcreate $DEVICE
vgcreate volgroupname $DEVICE
The LVM structures are persistent on /tmp/netcoolstorage. When you reboot, however, you have two problems:
  1. the association between /dev/loopsomething and /tmp/netcoolstorage will be broken
  2. /tmp/netcoolstorage might be deleted - there is no guarantee files on /tmp survive a reboot.

To fix #1, recreate the association, perhaps in /etc/rc.local, a shell script that is executed at the end of system initalization on most distros. Add this command:
Code:
losetup /dev/loopsomething /tmp/netcoolstorage
Of course, replace loopsomething with the correct device.

To fix #2, put /tmp/netcoolstorage somewhere else than /tmp.

This was four hours of system administration training in ten minutes.

Last edited by berndbausch; 11-07-2015 at 06:46 AM.
 
2 members found this post helpful.
Old 11-09-2015, 03:19 AM   #5
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks a lot for your help here. This was very helpful. Last few questions on this

1) Adding entry in rc.local saves my vg after reboot. But the file systems on this vg gets deleted. How can save my file systems as well?

2) Now that I have installed an entire product on this volume group if I keep a backup of /tmp/netcoolstorage to /opt/netcoolstorage while restoring how can I restore using /opt/netcoolstorage?

3) If I follow the procedure you mentioned on /opt/netcoolstorage will my vg and fs be safe from reboot? Just wanted to understand if issue is with /tmp selection or the truncate procedure.

Thanks again for your help.
 
Old 11-09-2015, 03:32 AM   #6
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 3,888

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Quote:
Originally Posted by akajain View Post
1) Adding entry in rc.local saves my vg after reboot. But the file systems on this vg gets deleted. How can save my file systems as well?
Strictly speaking it doesn't save it. If you are talking about losetup, it just recreates the structures that allow the system to find the VG. But perhaps this is splitting hairs.

But what is it that you put in /etc/rc.local? The system won't delete filesystems or logical volumes without you telling it.

Quote:
2) Now that I have installed an entire product on this volume group if I keep a backup of /tmp/netcoolstorage to /opt/netcoolstorage while restoring how can I restore using /opt/netcoolstorage?
Well, first of all don't use /tmp for anything that you want to keep.
Second, in case you lose the original file, just copy /opt/netcoolstorage back. You can use the cp or dd commands, and probably others.

Quote:
3) If I follow the procedure you mentioned on /opt/netcoolstorage will my vg and fs be safe from reboot? Just wanted to understand if issue is with /tmp selection or the truncate procedure.
If you want to use truncate after creating data on /opt/netcoolstorage, I have to say
  1. Why?
  2. If by chance you truncate the file to a smaller size, you will lose the contents
If on the other hand you just want to run truncate once, before creating your VG, no problem.

And as I said, anything residing on /tmp is up for deletion. Depending on how your system is configured. This is a standard documented here: http://www.pathname.com/fhs/pub/fhs-...TEMPORARYFILES.
 
2 members found this post helpful.
Old 11-09-2015, 04:15 AM   #7
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
Strictly speaking it doesn't save it. If you are talking about losetup, it just recreates the structures that allow the system to find the VG. But perhaps this is splitting hairs.

But what is it that you put in /etc/rc.local? The system won't delete filesystems or logical volumes without you telling it.
I have put "losetup /dev/loop0 /tmp/netcoolstorage" in rc.local file. The directory structure of file system is retained but looks like mounting is removed. df -h does not show me any file system which were there before reboot.

Well, first of all don't use /tmp for anything that you want to keep.
Second, in case you lose the original file, just copy /opt/netcoolstorage back. You can use the cp or dd commands, and probably others.
Ok so I can copy /opt/netcoolstorage to /tmp/netcoolstorage and all my data would be retrieved?

If you want to use truncate after creating data on /opt/netcoolstorage, I have to say
  1. Why?
  2. If by chance you truncate the file to a smaller size, you will lose the contents
If on the other hand you just want to run truncate once, before creating your VG, no problem.
Yes I was asking about truncate before creating vg.

And as I said, anything residing on /tmp is up for deletion. Depending on how your system is configured. This is a standard documented here: http://www.pathname.com/fhs/pub/fhs-...TEMPORARYFILES.
Yes I get this very clearly now. So instead of /tmp/netcoolstorage I should have used /opt/netcoolstorage.

SO to save my setup here are the steps I can take , please correct me if I am wrong

1) Copy /tmp/netcoolstorage to /opt/netcoolstorage
2) edit rc.local to save the vg

If my system reboots and I lose my filesystem and data
1) Copy /opt/netcoolstorage to /tmp/netcoolstorage
2) May be mount the unmounted file systems again.

Thank you!
 
Old 11-09-2015, 06:43 AM   #8
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 16.04 LTS
Posts: 236

Rep: Reputation: 65
Quote:
Originally Posted by akajain View Post
Yes I get this very clearly now. So instead of /tmp/netcoolstorage I should have used /opt/netcoolstorage.

SO to save my setup here are the steps I can take , please correct me if I am wrong

1) Copy /tmp/netcoolstorage to /opt/netcoolstorage
2) edit rc.local to save the vg

If my system reboots and I lose my filesystem and data
1) Copy /opt/netcoolstorage to /tmp/netcoolstorage
2) May be mount the unmounted file systems again.

Thank you!
Why do you stubbornly want to use /tmp? Just setup everything in /opt or wherever you like, but NOT IN /TMP!!!

In most (all?) distros /tmp gets deleted on every reboot.
 
Old 11-09-2015, 06:48 AM   #9
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Yes I get this point very clearly now. But since installation of product is complete I cannot move now

Next time onwards I will definitely not use /tmp

I was looking for ways to clean up the mess which I have already done!
 
Old 11-09-2015, 06:50 AM   #10
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
In short I dont want to use /tmp at all.
I used it since I did not know /tmp gets flushed on reboot , else I would have not used it.
 
Old 11-09-2015, 06:57 AM   #11
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 3,888

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Quote:
Originally Posted by akajain View Post
Yes I get this very clearly now. So instead of /tmp/netcoolstorage I should have used /opt/netcoolstorage.

SO to save my setup here are the steps I can take , please correct me if I am wrong

1) Copy /tmp/netcoolstorage to /opt/netcoolstorage
2) edit rc.local to save the vg
By point 2 you mean adding a losetup command to rc.local, right?

Quote:
If my system reboots and I lose my filesystem and data
1) Copy /opt/netcoolstorage to /tmp/netcoolstorage
2) May be mount the unmounted file systems again.
I still don't know how you can lose your data. If you really do, investigate how it happens. I continue to believe that you lost your data because you kept it on /tmp. Repeat after me: Don't put data on /tmp that you want to keep. Or you didn't really lose it, instead the losetup wasn't executed after the reboot.

If your data is lost, it would also mean that /opt/netcoolstorage is broken, so point 1 will be fairly useless, and point 2 will fail.

One thing I have failed to ask: Why do you want to put a physical volume on a file? Why not keep the data in a normal subtree of your filesystem, such as /home/akajain/netcoolstorage?
 
Old 11-09-2015, 07:02 AM   #12
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
Hmmm I guess I am losing data because of /tmp
I repeat "I WILL NOT USE /TMP EVER" !
 
Old 11-09-2015, 07:37 AM   #13
hortageno
Member
 
Registered: Aug 2015
Distribution: Ubuntu 16.04 LTS
Posts: 236

Rep: Reputation: 65
Quote:
Originally Posted by akajain View Post
Yes I get this point very clearly now. But since installation of product is complete I cannot move now

Next time onwards I will definitely not use /tmp

I was looking for ways to clean up the mess which I have already done!
As far as I can see you only created a volume group without a logical volume. Then you just deactivate the volume group and delete the loopback device with

Code:
vgchange -an /dev/tivolivg
losetup -d /dev/loop0
Edit: Reading your previous posts again you will need to stop all services which access this logical volume and unmount it before running the above commands.

and copy netcoolstorage to from /tmp to /opt and run

Code:
losetup --show -f /opt/netcoolstorage
Finally adjust the commands in rc.local to reflect the new path.

Last edited by hortageno; 11-09-2015 at 08:08 AM.
 
1 members found this post helpful.
Old 11-17-2015, 01:23 AM   #14
akajain
LQ Newbie
 
Registered: Nov 2015
Posts: 9

Original Poster
Rep: Reputation: Disabled
I just created a volume again using /opt this time using the following steps

truncate --size=50G /opt/netcoolstorage
DEVICE=$(losetup --show -f /opt/netcoolstorage)
mkfs.ext4 $DEVICE
pvcreate $DEVICE
vgcreate tivolivg /dev/loop0

added ""losetup /dev/loop0 /opt/netcoolstorage in /etc/rc.local

After reboot -
volume group is intact. But the file systems on tivolivg are lost

How to add entries in /etc/fstab to make the FS persistent even after system reboot?

For eg: One of the mount points I want is /backup on tivolivg volume group

I tried adding
/dev/mapper/tivolivg-backup /backup ext4 defaults 0 0
to fstab but on reboot I coudn't find the FS mounted.

fdisk -l shows
Disk /dev/mapper/tivolivg-backup: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Last edited by akajain; 11-17-2015 at 02:06 AM.
 
Old 11-17-2015, 04:16 AM   #15
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 3,888

Rep: Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092Reputation: 1092
Quote:
Originally Posted by akajain View Post
mkfs.ext4 $DEVICE
This filesystem will be overwritten by the pvcreate command.

Quote:
Originally Posted by akajain View Post
vgcreate tivolivg /dev/loop0
This is only possible if there was no tivolivg. If tivolivg existed before this command, the command must fail. If it didn't fail, tivolivg didn't exist.
Quote:
Originally Posted by akajain View Post
How to add entries in /etc/fstab to make the FS persistent even after system reboot?
First, you must create logical volumes in tivolivg. The command is lvcreate.
Then make filesystems on those logical volumes. The command is mkfs.
Then add a line for each new filesystem to fstab. It's easiest to copy an existing line and adapt it.
Quote:
Originally Posted by akajain View Post
I tried adding
/dev/mapper/tivolivg-backup /backup ext4 defaults 0 0
to fstab but on reboot I coudn't find the FS mounted.
You didn't make a filesystem on tivolivg-backup.
Perhaps you didn't even create the logical volume tivolivg-backup.
Quote:
Originally Posted by akajain View Post
fdisk -l shows
Disk /dev/mapper/tivolivg-backup: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Well it looks like you created the logical volume. But is there a filesystem on it? If not, run mkfs /dev/mapper/tivolivg-backup.

Actually I would start from zero.
Remove tivolivg.
Run losetup.
Create the PV
Create the VG
Create the LVol
Make the filesystem
Ensure /backup exists
Test everything by mounting the LVol and copying a file to it
Unmount it again.
Test fstab with mount -a
If you are convinced that everything works, send me a check
(the last point is optional)

Last edited by berndbausch; 11-17-2015 at 04:21 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Mount Physical Volume/Logical Volume without a working Volume Group mpivintis Linux - Newbie 10 01-11-2014 08:02 AM
how to shrink Volume Group and get some space to create new volume Farah_s Linux - Newbie 1 03-14-2012 08:34 AM
[SOLVED] Redhat volume group,logical volume group dhairysheel Red Hat 3 08-02-2011 06:07 AM
Newbie -How to create shared volume group using native LVM and VCS 5.1 with Red Hat 5 michaelp_777 Linux - Software 3 08-06-2010 03:19 PM
Fedora LVM volume group & Physical Volume resize problem gabeyg Fedora 1 05-14-2008 12:26 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:22 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration