Logical Volume Manager (LVM) & File Systems
Please download the following RHEL LVM Administrator Guide for complete reference.
Logical Volume Manager
To list all Volume Groups
# vgscan Reading all physical volumes. This may take a while... Found volume group "vggrd" using metadata type lvm2 Found volume group "rootvg" using metadata type lvm2
To list all physical volumes
# pvscan PV /dev/sdb VG vggrd lvm2 [410.12 GB / 123.12 GB free] PV /dev/sda2 VG rootvg lvm2 [136.00 GB / 76.00 GB free] Total: 2 [546.12 GB] / in use: 2 [546.12 GB] / in no VG: 0 [0 ]
To list all Logical Volumes
# lvscan ACTIVE '/dev/vggrd/sapgrd' [8.00 GB] inherit ACTIVE '/dev/vggrd/sapmntgrd' [4.00 GB] inherit ACTIVE '/dev/vggrd/oracle' [7.00 GB] inherit ACTIVE '/dev/vggrd/oraclnt' [1.00 GB] inherit ACTIVE '/dev/vggrd/archdata' [6.00 GB] inherit
Scan for all disks/multiple devices/partitions usable by LVM.
# lvmdiskscan lvmdiskscan -- reading all disks / partitions (this may take a while...) lvmdiskscan -- /dev/hda1 [ 31.35 MB] Primary LINUX native partition [0x83] lvmdiskscan -- /dev/hda2 [ 5.98 GB] DOS extended partition [0x05] lvmdiskscan -- /dev/hda5 [ 2.50 GB] Extended LINUX native partition [0x83] lvmdiskscan -- /dev/hda6 [517.69 MB] Extended LINUX native partition [0x83] lvmdiskscan -- /dev/hda7 [258.83 MB] Extended LINUX swap partition [0x82] lvmdiskscan -- 1 disk lvmdiskscan -- 0 whole disks lvmdiskscan -- 0 loop devices lvmdiskscan -- 0 multiple devices lvmdiskscan -- 0 network block devices lvmdiskscan -- 5 partitions lvmdiskscan -- 0 LVM physical volume partitions
Cookbook
To list all the disks
# lvmdiskscan
Prepare the disk /dev/sdb for LVM
# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created
Create a Volume group vg01 on /dev/sdb with PE size of 64
# vgcreate -s 64M vg01 /dev/sdb Volume group "vg01" successfully created
Verify the Volume group properties
# vgdisplay vg01 --- Volume group --- VG Name vg01 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.94 GB PE Size 64.00 MB Total PE 159 Alloc PE / Size 0 / 0 Free PE / Size 159 / 9.94 GB VG UUID B1NYxs-wpxk-S4Ug-vS9Y-7x99-kPUp-4HTdjI
Create a Logical volume datalv with the size of 5GB on vg01 volume group
# lvcreate -L 5G -n datalv vg01 Logical volume "dalalv" created
Create the file system on datalv
# mkfs -t ext3 /dev/vg01/datalv
Mount the filesystem
# mount /dev/vg01/datalv /mnt
Creating Snapshot of one volume
# lvcreate -L5G -s -n datalvsnapshot /dev/vg01/datalv
Extending a Logical Volume with LVM
If the kernel version is atleast 2.6 and File sytem type is ext3, then it is possible to extend the size of mounted file systems online without un-mounting using resize2fs. In the older systems, we can ext2online command to extend the file system size online.
# umount /mnt # lvextend -L+6G /dev/volgroup/logicalvol # e2fsck -f /dev/volgroup/logicalvol # resize2fs /dev/volgroup/logicalvol # mount /dev/volgroup/logicalvol /mnt
Extending File system online
[root@dc7700 ~]# lvextend -L+2G /dev/oravg/lv01 Extending logical volume lv01 to 12.00 GB Logical volume lv01 successfully resized [root@dc7700 ~]# resize2fs /dev/oravg/lv01 resize2fs 1.39 (29-May-2006) Filesystem at /dev/oravg/lv01 is mounted on /oracle; on-line resizing required Performing an on-line resize of /dev/oravg/lv01 to 3145728 (4k) blocks. The filesystem on /dev/oravg/lv01 is now 3145728 blocks long.
'Shrinking a Logical Volume With LVM
# umount /mnt # lvmdiskscan # e2fsck -f /dev/volgroup/logicalvol # resize2fs /dev/volgroup/logicalvol 40000 # mount /dev/volgroup/logicalvol /mnt # df # umount /mnt # lvreduce -L -8G /dev/volgroup/logicalvol # mount /dev/volgroup/logicalvol /mnt # vgreduce volgroup /dev/sdg # pvscan
Creating ext3 filesystem
# mkfs -t ext3 /dev/oravg/lv01
http://www.netadmintools.com/art367.html
File Systems
To change the label on ext2/ext3 Filesystems
# e2label /dev/hdc1 /data2
dumpe2fs - dump ext2/ext3 filesystem information
dumpe2fs prints the super block and blocks group information for the filesystem present on device.
The /etc/fstab file
Te /etc/fstab file is segregated into 6 columns. They are as follows :
- Filesystem - This is the device file. It could be your hard disk, cdrom, floppy, or a partition in your hard disk.
- Mount point - This is the place (usually a directory) where you want your data from the device file to be made available.
- Type of filesystem - It could be any filesystem like ext3, ntfs, ufs2 and so on.
- Mount Options - This column decides what permissions are to be given and to whom for accessing the device
- Dump frequency - This is usually always zero which means never dump. Other values being 1 for every day, 2 for every other day and so on.
- fsck order
To backup the root disk in tar
- umount non root filesystems
- cd /
- tar -c --exclude tmp/rootbackup.tar --exclude proc --exclude tmp/log --exclude tmp/.font-unix/fs7100 -f tmp/rootbackup.tar *
- mv tmp/rootbackup.tar to other media or usb disk or etc
swap
swapon, swapoff - enable/disable devices and files for paging and swapping
swapon -a # All devices marked as swap devices in /etc/fstab are made available swapon -s # Display swap usage summary by device swapoff <swapfile> # disables swapping on the specified devices and files swapoff -a # ll devices marked as swap devices in /etc/fstab are disabled
http://www.ideaexcursion.com/2009/02/02/all-about-linux-swap-part-2-management/