Logical volume with LVM
- Use Fdisk to create four new partition of type Linux LVM (ox8e) in unpartitioned space on your hard disk. These partitions should have the same size; to speed up the lab, do not make them larger than 1 GB in size. Make sure to write the changes to disk when you quit by using the w command to exit fdisk. Reboot the system. Once the system has booted up, log in as root.
- Initialize your Linux LVM partitions as physical volumes with pvcreate. Assuming the LVM partitions are /dev/hda4, /dev/hda5, /dev/hda6 and /dev/hda7, the command would be;
- pvcreate /dev/hda4 /dev/hda5 /dev/hda6 /dev/hda7
you can use the pvdisplay command (for example,
pvdisplay /dev/hda4) to verify that the partitions have been registered as physical volumes;
- Next, create a volume groupp called test0, using the default 5MB extent size, which initially contains only one of your physical volumes;
- vgcreate test0 /dev/hda4
you can use the vgdisplay command to list information
on all the volume groups active on the system.
on all the volume groups active on the system.
- Create a small logical volume that does not use up all the space in the volume group. Look for VG size adn Free PE/Size in the output of the vgdisplay command to assist you with his.
For example, to create a logical volume about 40MB in
size;
size;
- lvcreate -L 40M -n data test0
The command lvdisplay /dev/test0/data can be used to
verify that this command worked.
verify that this command worked.
- Now create an ext3 file system on your new logical volume;
mke2fs -j /dev/test0/data
Make a new directory /data and then mount
/dev/test0/data /data copy some files into /data.
Try creating a large file;
/dev/test0/data /data copy some files into /data.
Try creating a large file;
- dd if=/dev/zero of=/data/bigfile bs=1024 count=20000
Run df and check disk usage and space free on /data.
Verify that everything works like a normal ext3 file
system. Edit /etc/fstab, adding the following line;
Verify that everything works like a normal ext3 file
system. Edit /etc/fstab, adding the following line;
- /dev/vg0/data /data ext3 defaults 1 2
- Reboot the system to verify that the logical volume
is still available.
Working with Logical Volumes
- First, enlarge the logical volume /dev/test0/data. Then, use ext2online to enlarge the file system.
For example, to enlarge it by about 50MB;
- lvextend -L +50M /dev/test0/data
- ext2online /dev/test0/data
- Verify that your files are still intact. Run df and check to verify that more free disk space is now available on /data.
- Use the remaining extends in test0 to create a second logical volume.Run the vgdiskplay command, and look at at the line Free PE / Size. If it says something like 166/664 MB, this means the volume group has 166 extents (or 664MB of space) free. So, to make a second logical volume, /dev/test0/scratch,which is exactly 166 extents in size, the command would be;
- lvcreate -l 166 -n scratch test0
- Rerun vgdisplay. There should be no free extents left.
- Format the new logical volume; mke2fs -j /dev/test0/scratch
- Add one of the unused physical volumes to the volume group;
- vgextend test0 /dev/hda5
- If you run vgdisplay again, there should be free extents (provided by the new physical volume). Mount /dev/test0/scratch on mount point. Extend the new logical volume by 20MB.
use lvdisplay and vgdisplay to verify this command worked.
0 comments:
Post a Comment