LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Mirroring in LVM (https://www.linuxquestions.org/questions/linux-server-73/mirroring-in-lvm-934015/)

devUnix 03-12-2012 05:55 AM

Mirroring in LVM
 
I have got a book "RHEL 5 Administration Unleashed By Tammy Fox".

The author describes "Taking a Snapshot of a Logical Volume". I was once asked in an interview: "How do we do mirroring of an Logical Volume?", and I was not sure of it.

Is Mirroring of an LV is the same thing as Taking a Snapshot of it? If not, then, how to?

TenTenths 03-12-2012 07:04 AM

Normally "mirroring" would refer to setting up a RAID 1 either through software or hardware, normally with interview questions I'd ask for a clarification as to whether they mean raid mirror or some kind of time based snapshot. If it's a time-based snapshot to a different/remote volume you could look at DIRVISH as an option.

devUnix 03-12-2012 11:05 AM

Quote:

Originally Posted by TenTenths (Post 4624668)
Normally "mirroring" would refer to setting up a RAID 1 either through software or hardware, normally with interview questions I'd ask for a clarification as to whether they mean raid mirror or some kind of time based snapshot.

That's exactly what I asked him! But he said: "RAID Controller is not there on the system. We are not concerned about implementing RAID. We want mirroring out of LVM only. Is it possible or not?" I said: "Mirroring is RAID 1. That's it. Not sure how to achieve it using LVM". He was disappointed.

TenTenths 03-12-2012 11:10 AM

Quote:

Originally Posted by devUnix (Post 4624859)
That's exactly what I asked him! But he said: "RAID Controller is not there on the system. We are not concerned about implementing RAID. We want mirroring out of LVM only. Is it possible or not?" I said: "Mirroring is RAID 1. That's it. Not sure how to achieve it using LVM". He was disappointed.

pretty much would have been my answer too, although you could have said that it may have been possible to implement a linux software RAID for mirroring but that hardware raid is much more reliable.

devUnix 03-12-2012 05:20 PM

I created a Logical Volume "/dev/myVolGrp00/scripts" and wrote some files in the mount point "/scripts" and created another snapshot LV "/dev/myVolGrp00/scripts-snapshot" for it and added some more files but I see nothing in the snapshot "":

Code:

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/myVolGrp00/scripts
  VG Name                myVolGrp00
  LV UUID                NPRoIf-QEx1-aSv1-PF4V-Lyc1-ibIY-9PRsS3
  LV Write Access        read/write
  LV snapshot status    source of
                        /dev/myVolGrp00/scripts-snapshot [active]
  LV Status              available
  # open                1
  LV Size                8.00 MiB
  Current LE            2
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:1

  --- Logical volume ---
  LV Name                /dev/myVolGrp00/scripts-snapshot
  VG Name                myVolGrp00
  LV UUID                yv1h3Y-0mjm-uM2P-vu3b-qZWZ-W4ta-DsmYKX
  LV Write Access        read/write
  LV snapshot status    active destination for /dev/myVolGrp00/scripts
  LV Status              available
  # open                0
  LV Size                8.00 MiB
  Current LE            2
  COW-table size        4.00 MiB
  COW-table LE          1
  Allocated to snapshot  0.29%
  Snapshot chunk size    4.00 KiB
  Segments              1
  Allocation            inherit
  Read ahead sectors    auto
  - currently set to    256
  Block device          253:0


[root@localhost ~]# ls -ltr /snap-scripts/
total 12
drwx------. 2 root root 12288 Mar 13 03:38 lost+found

Of course, before mounting them I had formatted them, for example:

Code:

[root@localhost ~]# mke2fs -t ext4 /dev/myVolGrp00/scripts-snapshot
I have added them to "/etc/fstab":

Code:


/dev/myVolGrp00/scripts /scripts                ext4    defaults        1 2
/dev/myVolGrp00/scripts /snap-scripts          ext4    defaults        1 2


Note: I created the snapshot in this way:

Code:

[root@localhost ~]# lvcreate --size 4M -s --name scripts-snapshot /dev/myVolGrp00/scripts
  Logical volume "scripts-snapshot" created

I simply followed the System Admin book. It does not say anything about how snapshot is going show the files/directories as well as how to reduce the Logical Volume's size. I have successfully extended its size but reducing did not work with the "lvextend -r" command.

devUnix 03-13-2012 01:12 AM

I see the same files in the snapshot now:

Code:

[root@localhost ~]# ls -l /snap-scripts/
total 19
-rw-rw-r--. 1 hello hello    0 Mar 13 03:41 feel
...

I made no changes. I just started the machine (after some hours) and the snapshot looks okay.

makyo 03-13-2012 05:08 AM

Hi.

Mirroring and snapshots are two different features.

With LVM, one can set up mirrors:
Code:

      -m, --mirrors Mirrors
              Creates  a  mirrored  logical  volume  with Mirrors copies.  For
              example, specifying "-m 1" would result in a  mirror  with  two-
              sides; that is, a linear volume plus one copy.
-- excerpt from man 8 lvcreate

I have usually used LVM on top of RAID1, but using LVM mirrors might be one less piece of complexity.

For the snapshot:
Quote:

A full backup of a large data set may take a long time to complete. On multi-tasking or multi-user systems, there may be writes to that data while it is being backed up. This prevents the backup from being atomic and introduces a version skew that may result in data corruption. For example, if a user moves a file into a directory that has already been backed up, then that file would be completely missing on the backup media, since the backup operation had already taken place before the addition of the file. Version skew may also cause corruption with files which change their size or contents underfoot while being read.

To avoid downtime, high-availability systems may instead perform the backup on a snapshot—a read-only copy of the data set frozen at a point in time—and allow applications to continue writing to their data. Most snapshot implementations are efficient and can create snapshots in O(1). In other words, the time and I/O needed to create the snapshot does not increase with the size of the data set, whereas the same for a direct backup is proportional to the size of the data set. In some systems once the initial snapshot is taken of a data set, subsequent snapshots copy the changed data only, and use a system of pointers to reference the initial snapshot. This method of pointer-based snapshots consumes less disk capacity than if the data set was repeatedly cloned.

-- http://en.wikipedia.org/wiki/Snapshot_(computer_storage)
In LVM, the snapshots are done with copy-on-write http://en.wikipedia.org/wiki/Copy-on-write

I use snapshots indirectly by telling rsnapshot to use snapshots for data on LVM volumes. It creates the snapshot for the duration of the backup, then removes it.

Best wishes ... makyo

devUnix 03-14-2012 01:24 PM

Quote:

Originally Posted by makyo (Post 4625554)
Hi.

Mirroring and snapshots are two different features.

With LVM, one can set up mirrors:
Code:

      -m, --mirrors Mirrors
              Creates  a  mirrored  logical  volume  with Mirrors copies.  For
              example, specifying "-m 1" would result in a  mirror  with  two-
              sides; that is, a linear volume plus one copy.
-- excerpt from man 8 lvcreate



Makyo:


Thanks for the command option!


Rated you for your contribution to the post and for adding interesting stuffs as well.

Have a nice time!


All times are GMT -5. The time now is 09:13 PM.