# dmsetup 으로 확인하는 Major, minor 넘버 # dmsetup ls VG0-data (253, 0)
]# dmsetup info Name: VG0-data State: ACTIVE Read Ahead: 512 Tables present: LIVE Open count: 1 Event number: 0 Major, minor: 253, 0 Number of targets: 1 UUID: LVM-qAMVWfCgbM1GlkyJnpue3hj156CjTWXknlknh3KpTQUfToVgnfQRj3hyVysJrolL
Following on from the previous example we now want to use the extra
space in the "ops" volume group to make a database backup every
evening. To ensure that the data that goes onto the tape is
consistent we use an LVM snapshot logical volume.
A snapshot volume is a special type of volume that presents
all the data that was in the volume at the time the snapshot
was created. For a more detailed description, see Section 3.8, Snapshots.
This means we
can back up that volume without having to worry about data
being changed while the backup is going on, and we don't have
to take the database volume offline while the backup is taking
place.
In LVM1, this type of volume was read-only, but
LVM2 creates read/write snapshots by default.
13.4.1. Create the snapshot volume
There is a little over 500 Megabytes of free space in the "ops"
volume group, so we will use all of it to allocate space for the
snapshot logical volume. A snapshot volume can be as large or a
small as you like but it must be large enough to hold all the
changes that are likely to happen to the original volume during
the lifetime of the snapshot. So here, allowing 500 megabytes of
changes to the database volume which should be plenty.
# lvcreate -L592M -s -n dbbackup /dev/ops/databases lvcreate -- WARNING: the snapshot must be disabled if it gets full lvcreate -- INFO: using default snapshot chunk size of 64 KB for "/dev/ops/dbbackup" lvcreate -- doing automatic backup of "ops" lvcreate -- logical volume "/dev/ops/dbbackup" successfully created
Full snapshot are automatically disabled
If the snapshot logical volume becomes full it will be dropped
(become unusable) so it is vitally important to allocate enough space.
The amount of space necessary is dependent on the usage of the
snapshot, so there is no set recipe to follow for this. If the
snapshot size equals the origin size, it will never overflow.
13.4.2. Mount the snapshot volume
We can now create a mount-point and mount the volume
# mkdir /mnt/ops/dbbackup # mount /dev/ops/dbbackup /mnt/ops/dbbackup mount: block device /dev/ops/dbbackup is write-protected, mounting read-only
If you are using XFS as the filesystem you will need to add the nouuid option
to the mount command:
# mount /dev/ops/dbbackup /mnt/ops/dbbackup -onouuid,ro
13.4.3. Do the backup
I assume you will have a more sophisticated backup strategy than
this!
# tar -cf /dev/rmt0 /mnt/ops/dbbackup tar: Removing leading `/' from member names
13.4.4. Remove the snapshot
When the backup has finished you can now unmount the volume and
remove it from the system. You should remove snapshot volume
when you have finished with them because they take a copy of all
data written to the original volume and this can hurt
performance.
# umount /mnt/ops/dbbackup # lvremove /dev/ops/dbbackup lvremove -- do you really want to remove "/dev/ops/dbbackup"? [y/n]: y lvremove -- doing automatic backup of volume group "ops" lvremove -- logical volume "/dev/ops/dbbackup" successfully removed
When you create a mirrored volume, you specify the number of copies of the data to make with the -m argument of the lvcreate command. Specifying -m1 creates one mirror, which yields two copies of the file system: a linear logical volume plus one copy. Similarly, specifying -m2 creates two mirrors, yielding three copies of the file system.
The following command creates a mirrored logical volume with a single mirror. The volume is 50 gigabytes in size, is named mirrorlv, and is carved out of volume group vg0:
lvcreate -L 50G -m1 -n gfslv vg0
An LVM mirror divides the device being copied into regions that, by default, are 512KB in size. You can use the -R argument to specify the region size in MB. LVM maintains a small log which it uses to keep track of which regions are in sync with the mirror or mirrors. By default, this log is kept on disk, which keeps it persistent across reboots. You can specify instead that this log be kept in memory with the --corelog argument; this eliminates the need for an extra log device, but it requires that the entire mirror be resynchronized at every reboot.
The following command creates a mirrored logical volume from the volume group bigvg. The logical is named ondiskmirvol and has a single mirror. The volume is 12MB in size and keeps the mirror log in memory.
When a mirror is created, the mirror regions are synchronized. For large mirror components, the sync process may take a long time. When you are creating a new mirror that does not need to be revived, you can specify the nosync argument to indicate that an initial synchronization from the first device is not required.
You can specify which devices to use for the mirror logs and log, and which extents of the devices to use. To force the log onto a particular disk, specify exactly one extent on the disk on which it will be placed. LVM does not necessary respect the order in which devices are listed in the command line. If any physical volumes are listed that is the only space on which allocation will take place. Any physical extents included in the list that are already allocated will get ignored.
The following command creates a mirrored logical volume with a single mirror. The volume is 500 megabytes in size, it is named mirrorlv, and it is carved out of volume group vg0. The first leg of the mirror is on device /dev/sda1, the second leg of the mirror is on device /dev/sdb1, and the mirror log is on /dev/sdc1.
The following command creates a mirrored logical volume with a single mirror. The volume is 500 megabytes in size, it is named mirrorlv, and it is carved out of volume group vg0. The first leg of the mirror is on extents 0 through 499 of device /dev/sda1, the second leg of the mirror is on extents 0 through 499 of device /dev/sdb1, and the mirror log starts on extent 0 of device /dev/sdc1. These are 1MB extents. If any of the specified extents have already been allocated, they will be ignored.