免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1973 | 回复: 1

LVM on Red Hat Linux (1/2) [复制链接]

论坛徽章:
0
发表于 2010-01-14 16:22 |显示全部楼层
两年前写给同事看的.共享了.

Concepts

“LVM” stands for Logical Volume Manager.
A “volume group” in Red Hat Linux is equal to a “disk group” inVeritas Volume Manager.
A “logical volume” in Red Hat Linux is equal to a “volume” inVeritas Volume Manager.


Major Steps of Creating a File System Based on LVM on RedHat Linux

  • create partitions with system ID “8e” with “fdisk”.
  • create physical volumes(PV) with “pvcreate”.
  • create a volume group(VG) with “vgcreate”.
  • create a logical volume(LV) with “lvcreate”.
  • create a file system with “mkfs”.
  • update the file system table /etc/fstab and “mount” the     file system.

Often-used LVM-related Commands

-
pvcreate - initialize a disk or partition for use by LVM
-
pvdisplay - display attributes of a physical volume

-
vgdisplay - display attributes of volume groups
-
vgextend - add physical volumes to a volume group
-
vgreduce - reduce a volume group
-
vgremove - remove a volume group
-
vgchange - change attributes of a volume group
-
vgrename - rename a volume group
-
vgexport - make volume groups unknown to the system
-
vgimport - make exported volume groups known to the system

-
lvdisplay - display attributes of a logical volume
-
lvextend - extend the size of a logical volume
-
lvreduce - reduce the size of a logical volume (dangerous!)
-
lvresize - resize a logical volume (dangerous when reducing size!)
-
lvrename - rename a logical volume
-
lvchange - change attributes of a logical volume

-
ext2online - online (mounted) ext2 filesystem resizer


An Example of Creating a File System Based on LVM

# fdisk -l

Disk/dev/cciss/c0d0: 146.8 GB, 146807930880 bytes
255heads, 32 sectors/track, 35139 cylinders
Units= cylinders of 8160 * 512 = 4177920 bytes

          Device Boot     Start        End      Blocks   Id  System
/dev/cciss/c0d0p1  *          1         26      106064   83  Linux
/dev/cciss/c0d0p2             27       35139   143261040   8e  Linux LVM

Disk/dev/cciss/c0d1: 899.9 GB, 899985717248 bytes
255heads, 63 sectors/track, 109417 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes

Disk/dev/cciss/c0d1 doesn't contain a validpartition table

#  
# fdisk /dev/cciss/c0d1
Devicecontains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Buildinga new DOS disklabel. Changes will remain in memory only,
untilyou decide to write them. After that, of course, the previous
contentwon't be recoverable.


Thenumber of cylinders for this disk is set to 109417.
Thereis nothing wrong with that, but this is larger than 1024,
andcould in certain setups cause problems with:
1)software that runs at boot time (e.g., old versions of LILO)
2)booting and partitioning software from other OSs
  (e.g., DOS FDISK, OS/2 FDISK)
Warning:invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command(m for help): m
Commandaction
  a   toggle a bootable flag
  b   edit bsd disklabel
  c   toggle the dos compatibility flag
  d   delete a partition
  l   list known partition types
  m   print this menu
  n   add a new partition
  o   create a new empty DOS partition table
  p   print the partition table
  q   quit without saving changes
  s   create a new empty Sun disklabel
  t   change a partition's system id
  u   change display/entry units
  v   verify the partition table
  w   write table to disk and exit
  x   extra functionality (experts only)

Command(m for help): n
Commandaction
  e   extended
  p   primary partition (1-4)
p
Partitionnumber (1-4): 1
Firstcylinder (1-109417, default 1):
Usingdefault value 1
Lastcylinder or +size or +sizeM or +sizeK (1-109417, default 109417):
Usingdefault value 109417

Command(m for help): p

Disk/dev/cciss/c0d1: 899.9 GB, 899985717248 bytes
255heads, 63 sectors/track, 109417 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes

          Device Boot     Start        End      Blocks   Id  System
/dev/cciss/c0d1p1              1      109417   878892021  83  Linux

Command(m for help): t
Selectedpartition 1
Hexcode (type L to list codes): 8e
Changedsystem type of partition 1 to 8e (Linux LVM)

Command(m for help): p

Disk/dev/cciss/c0d1: 899.9 GB, 899985717248 bytes
255heads, 63 sectors/track, 109417 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes

          Device Boot     Start        End      Blocks   Id  System
/dev/cciss/c0d1p1              1      109417   878892021  8e  Linux LVM

Command(m for help): w
Thepartition table has been altered!

Callingioctl() to re-read partition table.
Syncingdisks.
# fdisk -l

Disk/dev/cciss/c0d0: 146.8 GB, 146807930880 bytes
255heads, 32 sectors/track, 35139 cylinders
Units= cylinders of 8160 * 512 = 4177920 bytes

          Device Boot     Start        End      Blocks   Id  System
/dev/cciss/c0d0p1  *          1         26      106064   83  Linux
/dev/cciss/c0d0p2             27       35139   143261040  8e  Linux LVM

Disk/dev/cciss/c0d1: 899.9 GB, 899985717248 bytes
255heads, 63 sectors/track, 109417 cylinders
Units= cylinders of 16065 * 512 = 8225280 bytes

          Device Boot     Start        End      Blocks   Id  System
/dev/cciss/c0d1p1              1      109417   878892021  8e  Linux LVM
[root@omaitfox12~]# pvcreate /dev/cciss/c0d1p1  
Physical volume "/dev/cciss/c0d1p1" successfully created
[root@omaitfox12~]# vgcreate vg01 /dev/cciss/c0d1p1
Volume group "vg01" successfully created
[root@omaitfox12~]# vgdisplay -v vg01
   Using volume group(s) on command line
   Finding volume group "vg01"
--- Volume group ---
VGName              vg01
SystemID            
Format               lvm2
Metadata Areas        1
Metadata Sequence No  1
VGAccess            read/write
VG Status            resizable
MAX LV               0
Cur LV               0
Open LV              0
MaxPV               0
CurPV               1
ActPV               1
VGSize              838.18 GB
PESize              4.00 MB
Total PE             214573
Alloc PE/ Size       0 / 0   
Free  PE / Size       214573 / 838.18 GB
VGUUID              0ZGRjJ-nU4z-IMgL-50Rb-TbMg-QeAc-TKaWIF
  
--- Physical volumes ---
PVName              /dev/cciss/c0d1p1     
PVUUID              LTvA0g-jX6n-sUPf-3oiC-IfcU-D0KA-QhSx7k
PVStatus            allocatable
Total PE / Free PE    214573 / 214573
  
[root@omaitfox12~]# lvcreate -l 214573 -n lvol1 vg01
Logical volume "lvol1" created
[root@omaitfox12~]# vgdisplay -v vg01
   Using volume group(s) on command line
   Finding volume group "vg01"
--- Volume group ---
VGName              vg01
SystemID            
Format               lvm2
Metadata Areas        1
Metadata Sequence No  2
VG Access            read/write
VGStatus            resizable
MAX LV               0
Cur LV               1
Open LV              0
MaxPV               0
CurPV               1
ActPV               1
VGSize              838.18 GB
PESize              4.00 MB
TotalPE             214573
Alloc PE/ Size       214573 / 838.18 GB
Free  PE / Size       0 / 0   
VGUUID              0ZGRjJ-nU4z-IMgL-50Rb-TbMg-QeAc-TKaWIF
  
--- Logical volume ---
LVName               /dev/vg01/lvol1
VG Name               vg01
LVUUID               vvF0lL-KzEG-l4PF-1mLY-rPP1-awMa-tBNh9v
LV Write Access        read/write
LVStatus             available
#open                0
LVSize               838.18 GB
Current LE            214573
Segments              1
Allocation            inherit
Read ahead sectors     0
Block device           253:2
  
--- Physical volumes ---
PVName              /dev/cciss/c0d1p1     
PVUUID              LTvA0g-jX6n-sUPf-3oiC-IfcU-D0KA-QhSx7k
PVStatus            allocatable
Total PE / Free PE    214573 / 0
  
#

论坛徽章:
0
发表于 2010-01-14 16:28 |显示全部楼层

LVM on Red Hat Linux (2/2)

# mkfs -t ext3 /dev/vg01/lvol1
mke2fs1.35 (28-Feb-2004)
Filesystemlabel=
OStype: Linux
Blocksize=4096 (log=2)
Fragmentsize=4096 (log=2)
109871104inodes, 219722752 blocks
10986137blocks (5.00%) reserved for the super user
Firstdata block=0
Maximumfilesystem blocks=222298112
6706block groups
32768blocks per group, 32768 fragments per group
16384inodes per group
Superblockbackups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
       4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
       102400000, 214990848

Writinginode tables: done                           
Creatingjournal (8192 blocks): done
Writingsuperblocks and filesystem accounting information: done

Thisfilesystem will be automatically checked every 22 mounts or
180days, whichever comes first.  Use tune2fs -c or -i to override.
# tune2fs -i 0 /dev/vg01/lvol1
tune2fs1.35 (28-Feb-2004)
Settinginterval between check 0 seconds
# mkdir /data01
mkdir:cannot create directory `/data01': File exists
# df -k
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                    138949632   2288716 129602692   2% /
/dev/cciss/c0d0p1      102710     10890     86517  12%/boot
none                  2511984         0  2511984   0% /dev/shm
abc:/data01   865095296 444284672 376866304  55% /den
xyz:/vol/logs/Click_Fox
                    4026531840 2545154400 1481377440  64% /ClickFox
# vi /etc/fstab

#This file is edited by fstab-sync - see 'man fstab-sync' for details
#
/dev/VolGroup00/LogVol00/                      ext3    defaults        1 1
LABEL=/boot            /boot                  ext3    defaults        1 2
none                   /dev/pts               devpts  gid=5,mode=620  0 0
none                   /dev/shm               tmpfs   defaults        0 0
none                   /proc                  proc    defaults        0 0
none                   /sys                   sysfs   defaults        0 0
/dev/VolGroup00/LogVol01swap                   swap    defaults        0 0
/dev/vg01/lvol1        /data01                ext3    defaults        1 1
#/dev/VolGroup01/LogVol00/data01             ext3    defaults        1 1
#
abc:/data01      /den                   nfs    proto=tcp,rw,hard,intr
xyz:/vol/logs/Click_Fox      /ClickFox       nfs    proto=tcp,rw,hard,intr
/dev/hda               /media/cdrom           auto    pamconsole,exec,noauto,managed 0 0
~
~
"/etc/fstab"15L, 923Cwritten                                                                                 
# mount /data01
# df -k
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                    138949632   2288716 129602692   2% /
/dev/cciss/c0d0p1      102710     10890     86517  12%/boot
none                  2511984         0  2511984   0% /dev/shm
abc:/data01    865095296 444284672376866304  55% /den
xyz:/vol/logs/Click_Fox
                    4026531840 2545154368 1481377472  64% /ClickFox
/dev/mapper/vg01-lvol1
                    865099368    110656 821044164   1% /data01
#  
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP