Showing posts with label LVM. Show all posts
Showing posts with label LVM. Show all posts

Monday, September 7, 2009

Disk Partitioning

To list the current partitions:
# fdisk -l

To list the partitions on a disk:
# fdisk -l /dev/sdb

To create partition on a disk:
# fdisk /dev/sdb
-> type n
-> type 'e' for extended or
'p' for primary partition
-> Enter the first cylinder number
-> Enter the last cylinder or size in KB,MB or GB
-> Enter 'p' to verify the partition table
-> Finally save the partition table by entering 'w'

Command used to inform the kernel of partition table changes:
# partprobe

Filesystems

Redhat Enterprise Linux supports the below type of filesystems.

1. Local or Disk based Filesystems such as ext2, ext3, ext4, xfs.
2. Memory based filesystems such as tmpfs, proc, ramfs.
2. Network based Filesystem such as nfs, cifs.
3. Shared Storage based Filesystem such asgfs1, gfs2.

Disk Based Filesystems:

Ext2 Filesystem :

The ext2 or second extended filesystem was used long back and now-a-days we don't create these type of filesystem because of size restrictions and slow performance.
A strange limitation of Ext2 is it supports only upto the date January 18, 2038.
Some limitations of ext2 are
Max File Size = 16GB-2TB
Max Filesystem Size = 2-32 TB

Ext3 Filesystem :

Ext3 filesystem has been the most commonly used filesystem. It is actually an journalled Ext2 filesystem.
Ext3 filesystems can be remounted as Ext2 filesystems without any conversion.
On high-end storage devices, Ext3 has some limitations in that it can only scale to a maximum of 16TB. On a 1TB S-ATA drive, the performance of the Ext3 filesystem repair utility (fsck), which
is used to verify and repair the filesystem after a crash, is extremely long. For many users that require high availability, the Ext3 filesystem typically supports close to 2-4TB of storage.

Ext4 Filesystem :

Ext4 is the fourth generation of the Ext filesystem family and is the default filesystem in Red Hat Enterprise Linux 6. Ext4 has been offered in test previews since Red Hat Enterprise Linux 5.4, giving customers confidence in its maturity. Some features of Ext4 are extent-based metadata, delayed allocation, large storage support, journal check-summing. Filesystem repair time (fsck) in Ext4 is much faster than in Ext2 and Ext3. Currently, Red Hat’s maximum supported size for Ext4 is 16TB in both Red Hat Enterprise Linux 5 and Red Hat Enterprise Linux 6

XFS Filesystem:

XFS is a robust and mature 64-bit journaling filesystem that supports very large files and filesystems on a single host. Red Hat’s maximum supported XFS filesystem image is 100TB. XFS is one of the highest performing filesystems on large systems with enterprise workloads.

Some features of XFS are

• delayed allocation
• dynamically allocated inodes
• b-tree indexing for scalability of free space management
• ability to support a large number of concurrent operations
• extensive run-time metadata consistency checking
• sophisticated metadata read-ahead algorithms
• tightly integrated backup and restore utilities
• online defragmentation
• online filesystem growing
• comprehensive diagnostics capabilities
• scalable and fast repair utilities

And also the other OS based filesystems (given below) are also supported in Redhat linux such as

UFS: Used in Solaris and early BSD operating systems. Linux provides read and write support is experimental.

FAT: Windows based filesystem.

NTFS: Windows NT based filesystem. Unlike FAT, it is a b-tree file system, meaning it has a performance and reliability advantage over FAT.

Which filesystem should I use ?
For large server/storage device, you can go for XFS.
Generally Ext3/Ext4 should be fine for most of the filesystems.
If your existing workload has performed well with Ext3, staying with Ext3 on Red Hat Enterprise Linux 5 or migrating to Ext4 on Red Hat Enterprise Linux 6 should provide you and your applications with a very familiar environment. Two key advantages of Ext4 over Ext3 on the same storage include faster filesystem check and repair times and higher streaming read and write performance on high-speed devices.

In general Ext3 or Ext4 is better if an application uses a single read/write thread and small files, while XFS shines when an application uses multiple read/write threads and bigger files.


Configuration Files:
1. /etx/fstab - You need to edit this file to automate the file system mounts:

2. /etc/mtab - An entry will be added/removed to this file every time a filesystem gets mounted/unmounted.


Now let us look at the commands to manage the filesystems.


Q. How to list current mounts:
A.
# mount
# cat /etc/mtab

Q. How to create an Ext4 filesystem on a disk/partition/LV :
A.
# mkfs -t ext4 /dev/sdb
# mkfs -t ext4 /dev/sdb1
# mkfs -t ext4 /dev/vg00/lvol1

Here mention the file system type after the flag 't'.

Above command can be used to create any type of file system
Whereas below commands are restricted to specific types only.

EXT2 : mke2fs or mkfs.ext2
EXT3 : mkfs.ext3
Reiserfs: mkfs.reiserfs
vfat : mkfs.vfat
xfs : mkfs.xfs
MSDos : mkdosfs or mkfs.msdos
minix : mkfs.minix
xiafs : mkfs.xiafs
NTFS : mkntfs

Q. How to run file system check ( you need unmount a filesystem before proceeding with fsck command) :
A. fsck -t ext2 /dev/sdb1

Q. How to check all file systems except the mounted ones:
A.
# fsck -m -A

File system specific fsck commands:
EXT2 : fsck.ext2 or e2fsck
Reiserfs: reiserfsck
JFS : fsck.jfs
xfs : fsck.xfs
xiafs : fsck.xiafs
minix : fsck.minix

Q. How to mount a ext2 file system:
A.
#mount -t ext2 /dev/sdb1 /mnt/usb

Q. How to mount all filesystems:
A.
# mount -a

Q. To mount all ext2 file systems:
A.
# mount -a -t ext2

Q. Unmount a file system:
A.
# umount /mnt/usb

Q. To unmount all the mounted filesystems (except / and currently used ones):
A. 
# umount -a

Q. To list open files on a mounted file system:
A.
# /usr/bin/lsof +D /mnt/usb

Q. To adjust tunable filesystem paramets on ext2/ext3 filesystems:
A.
# tune2fs /dev/sdb1

Q. To list the contents of the filesystem superblock:
A.  You can use any of the below commands.

# tune2fs -l /dev/sdb1
# dumpe2fs -b /dev/sdb1

Q. To extend /data filesystem (without unmounting) :
A.

# ext2online -v /data

Q. How to display the filesystem size, usage, free space, mount points, etc..
A:
# df -h 

Q. How to shrink a filesystem
A.  You can not do an online filesystem shrink. 
You need to unmount a filesystem before reducing its size.
Perform the following steps (1 to 7) to reduce a filesystem size.

1. Unmount the filesystem
# umount /mntpoint

2. Do filesystem check
# e2fsck -f /dev/mapper/vgname-lvname

3. Reduce the filesystem to 25GB
# resize2fs /dev/mapper/vgname-lvname 25G

4. Reduce the logical volume 
# lvresize -L 25G /dev/mapper/vgname-lvname

5. Verify the LV Size
# lvdisplay /dev/vgname/lvname

6. Mount the filesystem
# mntpoint

7. Verify the filesystem size
# df -h /mntpoint

Volume Group

Create a VG:
# vgcreate vg00 /dev/hda1 /dev/hdb1

Create a VG by mentioning the PE size:
# vgcreate -s 10M vg01 /dev/hda1 /dev/hdb1

To display all the VGs:
# vgdisplay

To display more info on a particular VG:
# vgdisplay -v vgname

To display only active VGs:
# vgdisplay -A

Activate a VG :
# vgchange -a y vgname

De-activate a VG:
# vgchange -a n vgname

Extend a VG:
# vgextend vgname /dev/hdb1 /dev/hdc2

Reduce a VG:
# vgreduce vgname /dev/hdc2

Remove a VG:
# vgremove vgname

Import a VG into a system:
# vgimport vgname

Export a VG from a system:
# vgexport vgname

To learn new VGs:
# vgscan

To backup VGDA to /etc/lvm/backup/vg_name:
# vgcfgbackup vgname

To restore VG meta data from /etc/lvm/backup/vg_name or a file to the disk
# vgcfgrestore -f filename -n vgname vgname

To recreate VG directory and logical volume special files:
# vgmknodes vgname

Logical volume

To report information about logical volumes:
# lvs

To create a logical volume in an existing volume group:

Method 1 - By mentioning the size:
# lvcreate -L 1G -n lv01 vg01 /dev/sdb1

Method 2 - By mentioning the # of LEs:
# lvcreate -l 32 -n lv01 vg01

You can now use /dev/vg01/lv01 as a block device111111

To scan all disks for Logical volumes:
# lvscan

To change the minor number of a LV:
# lvchange --minor 98 lv_name

To change the permission:

Read-Only:
# lvchange -p r lv_name

Read/Write:
# lvchange --permission r/w lv_name

To expand a LV:
# lvresize -L +1G lv_name

To reduce the size of a LV:
# lvresize -L -512M lv_name

To display the attributes of a LV:
# lvdisplay -v /dev/datavg/loglv

To remove a LV:
# lvremove /dev/vg01/lv01

Physical Volume

Physical Volume:

You can create PV on a hard disk or partiiosn (of type '8e' / Linux LVM)

To initialize a PV on a partition:
# pvcreate /dev/sdb1

To initialize multiple PVs:
# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3

To forcibly initialize a PV on a disk :
# pvcreate -f /dev/sdb

Above command initializes a PV by putting a volume group descriptor area a.k.a VGDA at the start of the PV

To show the information about a PV:
# pvdisplay /dev/sdb1

To report information about PVs:
# pvs

To scan all disks for Physical volumes:
# pvscan

To scan/show PVs only for exported VGs:
# pvscan -e

To scan/show PVs not belonging to any VG:
# pvscan -n

To expand a PV after enlarging the partition with fdisk:
# pvresize /dev/sdb1

To shrink a PV on a partition prior to shrinking the partition with fdisk:
# pvresize --setphysicalvolumesize 40G /dev/sdb1

To view PEs:
# pvdata -E /dev/vg1/lv1

To move PEs between PVs :
# pvmove -n lv1 /dev/sdd1 /dev/sdd2

LVM Limits

Max # of VG - 99
Max # of LV - 256
Max size of a LV - 512MB - 2TB (32bit)
Max size of a LV - 512MB - 1PB (64bit)
Max # of LE - 65534
Max # of PE - 65534