LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to create a persistent volume group (https://www.linuxquestions.org/questions/linux-software-2/how-to-create-a-persistent-volume-group-4175558222/)

akajain 11-07-2015 01:58 AM

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

berndbausch 11-07-2015 04:49 AM

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.

akajain 11-07-2015 05:01 AM

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.

berndbausch 11-07-2015 05:45 AM

Quote:

Originally Posted by akajain (Post 5445941)
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.

akajain 11-09-2015 02:19 AM

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.

berndbausch 11-09-2015 02:32 AM

Quote:

Originally Posted by akajain (Post 5446774)
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.

akajain 11-09-2015 03:15 AM

Quote:

Originally Posted by berndbausch (Post 5446782)
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!

hortageno 11-09-2015 05:43 AM

Quote:

Originally Posted by akajain (Post 5446806)
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.

akajain 11-09-2015 05:48 AM

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!

akajain 11-09-2015 05:50 AM

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.

berndbausch 11-09-2015 05:57 AM

Quote:

Originally Posted by akajain (Post 5446806)
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?

akajain 11-09-2015 06:02 AM

Hmmm I guess I am losing data because of /tmp
I repeat "I WILL NOT USE /TMP EVER" ! :)

hortageno 11-09-2015 06:37 AM

Quote:

Originally Posted by akajain (Post 5446857)
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.

akajain 11-17-2015 12:23 AM

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

berndbausch 11-17-2015 03:16 AM

Quote:

Originally Posted by akajain (Post 5450764)
mkfs.ext4 $DEVICE

This filesystem will be overwritten by the pvcreate command.

Quote:

Originally Posted by akajain (Post 5450764)
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 (Post 5450764)
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 (Post 5450764)
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 (Post 5450764)
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)


All times are GMT -5. The time now is 12:53 PM.