27 December 2010

Creating a New LVM Partition (On a New Disk)

1. Add a new hard disk.

2. Create new partitions. Assign the Linux LVM filesystem to one or more of these partitions. This can be easily done with the Linux fdisk utility.

3. Back up /home. Assign the LVM filesystem to that partition.

4. Scan for Linux LVM filesystems with the vgscan utility to create a database for other LVM commands.

5. Create volumes for the set with the pvcreate /dev/partition command.

6. Add the desired volumes to a specific volume group with the vgcreate groupname /dev/partition1 /dev/partition2 … command.

7. Now you can create a logical volume. Use the lvcreate -L xyM -n volname groupname command, where xy is the size of the volume and groupname is the volume group name from the previous step.

8. Finally, you can format the logical volume with the mkfs command for the desired filesystem (usually ext2 or ext3), using the device name returned by the lvcreate command.


Growing the LVM Volume

Say that you are running out of space and you want to add more
space to your LVM volume. To do that, unmount the volume and
use the lvresize command. After that, you must also check the file
system with e2fsck and run resize2fs to resize the ext3 file
system on that volume:

# umount /mnt/u01

# lvresize --size 16M /dev/vgGroup/lvm_u01

# e2fsck -f /dev/vgGroup/lvm_u01

# resize2fs /dev/vgGroup/lvm_u01 16M

# mount -t ext3 /dev/mapper/vgGroup-lvm_u01 /mnt/u01

# df -h

Shrinking an LVM Volume

You can also use the lvresize command if you want to take
unneeded space from an existing LVM volume. As before,
unmount the volume before resizing it and run e2fsck (to
check the file system) and resize2fs (to resize it to the
smaller size):

# umount /mnt/u01

# e2fsck -f /dev/vgGroup/lvm_u01

# resize2fs /dev/vgGroup/lvm_u01 12M

# lvresize --size 12M /dev/vgGroup/lvm_u01

# mount -t ext3 /dev/mapper/vgGroup-lvm_u01 /mnt/u01

See Also:


tldp.org LVM-HOWTO


biOos

No comments: