linux AS4下LVM的使用手册

1:创建PV(物理分区)假设我的磁盘有一部分没有划分的分区:fdisk /dev/sda查看现在的分区Command (m for help): pDisk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 143 1044225 82 Linux swap/dev/sda3 144 2055 15358140 83 Linux创建一个新分区:Command (m for help): nCommand action e extended p primary partition (1-4)e(选择创建扩展分区)Selected partition 4First cylinder (2056-2610, default 2056): Using default value 2056Last cylinder or +size or +sizeM or +sizeK (2056-2610, default 2610): Using default value 2610前面的分区还没有用完磁盘,继续创建另一个分区:Command (m for help): nFirst cylinder (2056-2610, default 2056): Using default value 2056Last cylinder or +size or +sizeM or +sizeK (2056-2610, default 2610): 2300Command (m for help): nFirst cylinder (2301-2610, default 2301): Using default value 2301Last cylinder or +size or +sizeM or +sizeK (2301-2610, default 2610): Using default value 2610查看已经划分好的分区:Command (m for help): pDisk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 143 1044225 82 Linux swap/dev/sda3 144 2055 15358140 83 Linux/dev/sda4 2056 2610 4458037+ 5 Extended/dev/sda5 2056 2300 1967931 83 Linux/dev/sda6 2301 2610 2490043+ 83 Linuxw(存盘,退出)从上面看,sda5和sda6是新创建的分区,ID号为8e(也就是 linux LVM)现在将新创建的分区修改他们的系统ID[root@oracle ~]# fdisk /dev/sdaThe number of cylinders for this disk is set to 2610.There is nothing wrong with that, but this is larger than 1024,and could 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)Command (m for help): tPartition number (1-6): 5Hex code (type L to list codes): L0 Empty 1e Hidden W95 FAT1 75 PC/IX be Solaris boot 1 FAT12 24 NEC DOS 80 Old Minix bf Solaris 2 XENIX root 39 Plan 9 81 Minix / old Lin c1 DRDOS/sec (FAT-3 XENIX usr 3c PartitionMagic 82 Linux swap c4 DRDOS/sec (FAT-4 FAT16 <32M 40 Venix 80286 83 Linux c6 DRDOS/sec (FAT-5 Extended 41 PPC PReP Boot 84 OS/2 hidden C: c7 Syrinx 6 FAT16 42 SFS 85 Linux extended da Non-FS data 7 HPFS/NTFS 4d QNX4.x 86 NTFS volume set db CP/M / CTOS / .8 AIX 4e QNX4.x 2nd part 87 NTFS volume set de Dell Utility 9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM df BootIt a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e1 DOS access b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS e4 SpeedStor e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs f W95 Ext’d (LBA) 54 OnTrackDM6 a5 FreeBSD ee EFI GPT 10 OPUS 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fd Linux raid auto18 AST SmartSleep 65 Novell Netware b8 BSDI swap fe LANstep 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid ff BBT 1c Hidden W95 FAT3Hex code (type L to list codes): 8eChanged system type of partition 5 to 8e (Linux LVM)Command (m for help): tPartition number (1-6): 6Hex code (type L to list codes): 8eChanged system type of partition 6 to 8e (Linux LVM)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table.The new table will be used at the next reboot.Syncing disks.使分区信息生效:[root@oracle ~]# partprobe [root@oracle ~]# reboot创建PV(物理卷)[root@oracle ~]# pvcreate /dev/sda5 /dev/sda6 Physical volume “/dev/sda5” successfully created Physical volume “/dev/sda6” successfully created创建物理卷组rootvg,并把/dev/sda5 /dev/sda6加入其中:[root@oracle ~]# vgcreate rootvg /dev/sda5 /dev/sda6 Volume group “rootvg” successfully created在物理卷组上创建一个100MB的逻辑卷lv1:[root@oracle ~]# lvcreate -L 100M -n lv1 rootvg Logical volume “lv1” created格式化分区:[root@oracle ~]# mkfs.ext3 /dev/rootvg/lv1 mke2fs 1.35 (28-Feb-2004)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)25688 inodes, 102400 blocks5120 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6737100813 block groups8192 blocks per group, 8192 fragments per group1976 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.将lv1挂载到/mnt/lvm下[root@oracle ~]# mkdir /mnt/lvm[root@oracle ~]# mount /dev/rootvg/lv1 /mnt/lvm/[root@oracle ~]# [root@oracle lvm]# df -lhFilesystem Size Used Avail Use% Mounted on/dev/sda3 15G 2.4G 12G 18% //dev/sda1 99M 8.6M 86M 10% /bootnone 125M 0 125M 0% /dev/shm/dev/mapper/VolGroup00-LogVol02 9.1G 53M 8.6G 1% /home/dev/mapper/VolGroup00-LogVol00 9.7G 55M 9.1G 1% /opt/dev/mapper/VolGroup00-LogVol01 1008M 34M 924M 4% /tmp/dev/mapper/rootvg-lv1 97M 5.6M 87M 7% /mnt/lvm动态增加逻辑卷的大小:[root@oracle lvm]# lvextend -L+200M /dev/rootvg/lv1 Extending logical volume lv1 to 300.00 MB Logical volume lv1 successfully resized[root@oracle lvm]# ext2online /dev/rootvg/lv1 ext2online v1.1.18 – 2001/03/18 for EXT2FS 0.5b[root@oracle lvm]# cd /mnt/lvm/[root@oracle lvm]# lslost+found[root@oracle lvm]# mkdir aa[root@oracle lvm]# lsaa lost+found[root@oracle lvm]# 减少逻辑卷的大小:[root@oracle lvm]# umount /mnt/lvm/[root@oracle /]# umount /mnt/lvm/[root@oracle /]# cd /mnt/lvm/[root@oracle lvm]# ls[root@oracle lvm]# mke2fs -n /dev/rootvg/lv1 mke2fs 1.35 (28-Feb-2004)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)76912 inodes, 307200 blocks15360 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6763315238 block groups8192 blocks per group, 8192 fragments per group2024 inodes per groupSuperblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729, 204801, 221185Block size=1024(bytes)307200 blockslv1分区大小=1024×307200/1024/1024=300(MB)307200个blocks组成了300M,如果我们要减小50M,应该减少多少blocks?307200 x—— =—–300 50x=307200X50/300=51200[root@oracle lvm]# mke2fs -f /dev/rootvg/lv1 mke2fs: bad fragment size – /dev/rootvg/lv1[root@oracle lvm]# resize2fs -f /dev/rootvg/lv1 resize2fs 1.35 (28-Feb-2004)The filesystem is already 307200 blocks long. Nothing to do!调整lv分区大小,减小50M[root@oracle lvm]# lvreduce -L-50M /dev/rootvg/lv1 Rounding up size to full physical extent 48.00 MB WARNING: Reducing active logical volume to 252.00 MB THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce lv1? [y/n]: y Reducing logical volume lv1 to 252.00 MB Logical volume lv1 successfully resized重新挂载:[root@oracle lvm]# mount /dev/rootvg/lv1 /mnt/lvm/删除[root@oracle lvm]# umount /mnt/lvm/aa lost+found/ 动态加大VG:这里我们新增一个PV并加入VG1 fdisk增加一个(0x)8e标志的分区/dev/hda72 vgextend rootvg /dev/hda7好了,vg增大了缩小逻辑卷组VG:1 搬移PV中的资料(只限于同一VG中)#pvmove [-n ] []如#pvmove /dev/hda5 /dev/hda6将VG中pv hda5的内容搬移到hda6中pvmove /dev/hda5(也可以这样,lvm决定hda2的内容被复制到哪里)2 vgreduce rootvg /dev/hda5把vg hda5移除5) 如何删除逻辑卷/逻辑卷组删除VG流程:1 umount /挂接点2 lvremove /dev/rootvg/lv1移除逻辑卷,这里是lv13 vgchange -a n rootvg(关闭rootvg)4 vgremove rootvg移除rootvg删除分区:fdis /dev/sdaCommand (m for help): pDisk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 143 1044225 82 Linux swap/dev/sda3 144 2055 15358140 83 Linux/dev/sda4 2056 2610 4458037+ 5 Extended/dev/sda5 2056 2300 1967931 8e Linux LVM/dev/sda6 2301 2610 2490043+ 8e Linux LVMCommand (m for help): dPartition number (1-6): 4Command (m for help): pDisk /dev/sda: 21.4 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System/dev/sda1 * 1 13 104391 83 Linux/dev/sda2 14 143 1044225 82 Linux swap/dev/sda3 144 2055 15358140 83 LinuxCommand (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.The kernel still uses the old table.The new table will be used at the next reboot.Syncing disks.[root@oracle lvm]# partprobe [root@oracle lvm]# df -lhFilesystem Size Used Avail Use% Mounted on/dev/sda3 15G 2.4G 12G 18% //dev/sda1 99M 8.6M 86M 10% /bootnone 125M 0 125M 0% /dev/shm/dev/mapper/VolGroup00-LogVol02 9.1G 53M 8.6G 1% /home/dev/mapper/VolGroup00-LogVol00 9.7G 55M 9.1G 1% /opt/dev/mapper/VolGroup00-LogVol01 1008M 34M 924M 4% /tmp6) lvm相关命令这个表格,你可以在RHCE_Study_Guide.pdf上找到 Physical Volume Volume Group Logical Volume————————————————————————-scan pvscan vgscan lvscancreate pvcreate vgcreate lvcreatedisplay pvdispaly vgdisplay lvdisplayremove pvremove vgremove lvremove————————————————————————-像一颗深绿色的宝石镶嵌在云南大地上,

linux AS4下LVM的使用手册

相关文章:

你感兴趣的文章:

标签云: