1.磁盘格式化,并更改磁盘属性为8e;
[root@node ~]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x0d11ad5c. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won‘t be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx 5 Extended 42 SFS 86 NTFS volume set da Non-FS data 6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility 8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt 9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary 16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT 1e Hidden W95 FAT1 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. #########按照/dev/sdb1的创建,创建/sdb2,/sdc1,/sdc2 [root@node ~]# fdisk -l /dev/sd{b,c} Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0d11ad5c Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223+ 8e Linux LVM /dev/sdb2 655 1308 5253255 8e Linux LVM Disk /dev/sdc: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x3decac7b Device Boot Start End Blocks Id System /dev/sdc1 1 784 6297448+ 8e Linux LVM /dev/sdc2 785 1307 4200997+ 8e Linux LVM
创建LVM:
[root@node ~]# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdc2 dev_is_mpath: failed to get device for 8:17 Physical volume "/dev/sdb1" successfully created dev_is_mpath: failed to get device for 8:33 Physical volume "/dev/sdc1" successfully created dev_is_mpath: failed to get device for 8:34 Physical volume "/dev/sdc2" successfully created [root@node ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name vg_node PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID zNBrQw-Rd6a-NZBC-1gxD-DXHp-HZ70-BPSk5u "/dev/sdb1" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID r8tD2m-XeuR-fep8-fd6b-ZKl7-fjMF-f8m8g6 "/dev/sdc1" is a new physical volume of "6.01 GiB" --- NEW Physical volume --- PV Name /dev/sdc1 VG Name PV Size 6.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID jKnzbU-Ra59-TZfb-GVzM-XEi9-zfhf-WmuQMj "/dev/sdc2" is a new physical volume of "4.01 GiB" --- NEW Physical volume --- PV Name /dev/sdc2 VG Name PV Size 4.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID PMxP8n-wsBw-dZKt-PnAp-W1Bh-XcNC-TrUiwM [root@node ~]# vgs VG #PV #LV #SN Attr VSize VFree vg_node 1 2 0 wz--n- 19.51g 0 [root@node ~]# vgcreate testvg /dev/sdb1 /dev/sdc1 /dev/sdc2 Volume group "testvg" successfully created [root@node ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 3 0 0 wz--n- 15.02g 15.02g vg_node 1 2 0 wz--n- 19.51g 0 [root@node ~]# vgdisplay testvg --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 3 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 3 Act PV 3 VG Size 15.02 GiB PE Size 4.00 MiB Total PE 3844 Alloc PE / Size 0 / 0 Free PE / Size 3844 / 15.02 GiB VG UUID 9BL2Sl-vRSM-4M1E-zrOJ-WyMd-6VLA-xFkNPJ [root@node ~]# lvcreate -L 7G -n mylv testvg Logical volume "mylv" created [root@node ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mylv testvg -wi-a----- 7.00g lv_root vg_node -wi-ao---- 17.57g lv_swap vg_node -wi-ao---- 1.94g [root@node ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name testvg PV Size 5.01 GiB / not usable 2.10 MiB Allocatable yes PE Size 4.00 MiB Total PE 1282 Free PE 1027 Allocated PE 255 PV UUID r8tD2m-XeuR-fep8-fd6b-ZKl7-fjMF-f8m8g6 --- Physical volume --- PV Name /dev/sdc1 VG Name testvg PV Size 6.01 GiB / not usable 1.85 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 1537 Free PE 0 Allocated PE 1537 PV UUID jKnzbU-Ra59-TZfb-GVzM-XEi9-zfhf-WmuQMj --- Physical volume --- PV Name /dev/sdc2 VG Name testvg PV Size 4.01 GiB / not usable 2.54 MiB Allocatable yes PE Size 4.00 MiB Total PE 1025 Free PE 1025 Allocated PE 0 PV UUID PMxP8n-wsBw-dZKt-PnAp-W1Bh-XcNC-TrUiwM --- Physical volume --- PV Name /dev/sda2 VG Name vg_node PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID zNBrQw-Rd6a-NZBC-1gxD-DXHp-HZ70-BPSk5u [root@node ~]# ls -l /dev/testvg/mylv lrwxrwxrwx 1 root root 7 Apr 15 02:24 /dev/testvg/mylv -> ../dm-2 [root@node ~]# ls /dev/dm* /dev/dm-0 /dev/dm-1 /dev/dm-2 [root@node ~]# lvdisplay /dev/testvg/mylv --- Logical volume --- LV Path /dev/testvg/mylv LV Name mylv VG Name testvg LV UUID HG35jJ-0YsO-IkzD-D836-cmOS-B8RE-Y7cdR3 LV Write Access read/write LV Creation host, time node.magine356wj.com, 2015-04-15 02:24:53 +0800 LV Status available # open 0 LV Size 7.00 GiB Current LE 1792 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 [root@node ~]# lvdisplay /dev/mapper/mylv Volume group "mylv" not found Skipping volume group mylv [root@node ~]# lvdisplay /dev/mapper/testvg-mylv --- Logical volume --- LV Path /dev/testvg/mylv LV Name mylv VG Name testvg LV UUID HG35jJ-0YsO-IkzD-D836-cmOS-B8RE-Y7cdR3 LV Write Access read/write LV Creation host, time node.magine356wj.com, 2015-04-15 02:24:53 +0800 LV Status available # open 0 LV Size 7.00 GiB Current LE 1792 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 [root@node ~]# mke2fs -t ext4 /dev/testvg/mylv mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe blocks 458752 inodes, 1835008 blocks 91750 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1879048192 56 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@node ~]# mount /dev/testvg/mylv /mnt [root@node ~]# cp /etc/fstab /mnt/ [root@node ~]# whoami [root@node ~]# cat /mnt/fstab # # /etc/fstab # Created by anaconda on Wed Apr 15 01:35:08 2015 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_node-lv_root / ext4 defaults 1 1 UUID=f8e87dfa-7f58-4396-94e6-5caf9b46eca5 /boot ext4 defaults 1 2 /dev/mapper/vg_node-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
扩展VG:
1.先准备好一个pv (/sdb2)
2.使用vgextend命令即可完成扩展
[root@node ~]# pvcreate /dev/sdb2 ##sdb2 准备成pv Physical volume "/dev/sdb2" successfully created [root@node ~]# pvdisplay --- Physical volume --- PV Name /dev/sdb1 VG Name testvg PV Size 5.01 GiB / not usable 2.10 MiB Allocatable yes PE Size 4.00 MiB Total PE 1282 Free PE 1027 Allocated PE 255 PV UUID r8tD2m-XeuR-fep8-fd6b-ZKl7-fjMF-f8m8g6 --- Physical volume --- PV Name /dev/sdc1 VG Name testvg PV Size 6.01 GiB / not usable 1.85 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 1537 Free PE 0 Allocated PE 1537 PV UUID jKnzbU-Ra59-TZfb-GVzM-XEi9-zfhf-WmuQMj --- Physical volume --- PV Name /dev/sdc2 VG Name testvg PV Size 4.01 GiB / not usable 2.54 MiB Allocatable yes PE Size 4.00 MiB Total PE 1025 Free PE 1025 Allocated PE 0 PV UUID PMxP8n-wsBw-dZKt-PnAp-W1Bh-XcNC-TrUiwM --- Physical volume --- PV Name /dev/sda2 VG Name vg_node PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID zNBrQw-Rd6a-NZBC-1gxD-DXHp-HZ70-BPSk5u "/dev/sdb2" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID mUpWZn-cQTT-jF17-ZheX-2w0e-sUdw-Ez4yPn [root@node ~]# vgextend testvg /dev/sdb2 ##sdb2加入到testvg Volume group "testvg" successfully extended [root@node ~]# vgs ##空间增加了 VG #PV #LV #SN Attr VSize VFree testvg 4 1 0 wz--n- 20.02g 13.02g vg_node 1 2 0 wz--n- 19.51g 0 [root@node ~]# vgdisplay testvg --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 4 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 4 Act PV 4 VG Size 20.02 GiB PE Size 4.00 MiB Total PE 5126 Alloc PE / Size 1792 / 7.00 GiB Free PE / Size 3334 / 13.02 GiB VG UUID 9BL2Sl-vRSM-4M1E-zrOJ-WyMd-6VLA-xFkNPJ [root@node ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_node lvm2 a-- 19.51g 0 /dev/sdb1 testvg lvm2 a-- 5.01g 4.01g /dev/sdb2 testvg lvm2 a-- 5.01g 5.01g /dev/sdc1 testvg lvm2 a-- 6.00g 0 /dev/sdc2 testvg lvm2 a-- 4.00g 4.00g [root@node ~]# cat /mnt/fstab # # /etc/fstab # Created by anaconda on Wed Apr 15 01:35:08 2015 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_node-lv_root / ext4 defaults 1 1 UUID=f8e87dfa-7f58-4396-94e6-5caf9b46eca5 /boot ext4 defaults 1 2 /dev/mapper/vg_node-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
缩减VG:
确定要移除的pv(/sdc2)
讲此pv上的数据移至其他pv
从卷组中将此pv移除
[root@node ~]# pvmove /dev/sdc2 No data to move for testvg [root@node ~]# vgreduce testvg /dev/sdc2 Removed "/dev/sdc2" from volume group "testvg" [root@node ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 3 1 0 wz--n- 16.02g 9.02g vg_node 1 2 0 wz--n- 19.51g 0 [root@node ~]# vgdisplay testvg --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 3 Act PV 3 VG Size 16.02 GiB PE Size 4.00 MiB Total PE 4101 Alloc PE / Size 1792 / 7.00 GiB Free PE / Size 2309 / 9.02 GiB VG UUID 9BL2Sl-vRSM-4M1E-zrOJ-WyMd-6VLA-xFkNPJ
扩展逻辑卷:
确定扩展多大(3G)
确定当前逻辑卷组所在的卷组有足够的空间
要有5G以上的空闲空间
扩展:
[root@node ~]# lvextend -L +3G /dev/testvg/mylv ###物理边界扩展 Extending logical volume mylv to 10.00 GiB Logical volume mylv successfully resized [root@node ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node-lv_root 18G 3.8G 13G 24% / tmpfs 495M 72K 495M 1% /dev/shm /dev/sda1 485M 35M 426M 8% /boot /dev/mapper/testvg-mylv 6.9G 144M 6.4G 3% /mnt [root@node ~]# resize2fs /dev/testvg/mylv ##逻辑边界扩展 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/testvg/mylv is mounted on /mnt; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/testvg/mylv to 2621440 (4k) blocks. The filesystem on /dev/testvg/mylv is now 2621440 blocks long. [root@node ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node-lv_root 18G 3.8G 13G 24% / tmpfs 495M 72K 495M 1% /dev/shm /dev/sda1 485M 35M 426M 8% /boot /dev/mapper/testvg-mylv 9.9G 144M 9.3G 2% /mnt [root@node ~]# e2fsck /dev/testvg/mylv ##文件系统检测 ,不能再挂载状态检测 e2fsck 1.41.12 (17-May-2010) /dev/testvg/mylv is mounted. e2fsck: Cannot continue, aborting. [root@node ~]# e2fsck -f /dev/testvg/mylv e2fsck 1.41.12 (17-May-2010) /dev/testvg/mylv is mounted. e2fsck: Cannot continue, aborting. [root@node ~]# umount /mnt [root@node ~]# e2fsck -f /dev/testvg/mylv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/testvg/mylv: 12/655360 files (0.0% non-contiguous), 77936/2621440 blocks [root@node ~]# mount /dev/testvg/mylv /mnt [root@node ~]# mount /dev/mapper/vg_node-lv_root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) /dev/mapper/testvg-mylv on /mnt type ext4 (rw) [root@node ~]# cat /mnt/fstab # # /etc/fstab # Created by anaconda on Wed Apr 15 01:35:08 2015 # # Accessible filesystems, by reference, are maintained under ‘/dev/disk‘ # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/vg_node-lv_root / ext4 defaults 1 1 UUID=f8e87dfa-7f58-4396-94e6-5caf9b46eca5 /boot ext4 defaults 1 2 /dev/mapper/vg_node-lv_swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 ########################################################################## fsck:检测所有的文件系统,e2fsck 检测ext系列的,-t 指定文件类型;-f 强制检测
缩减逻辑卷:
确认缩减逻辑卷,缩减后的磁盘大小必须必存储的文件大小大
[root@node ~]# umount /mnt [root@node ~]# e2fsck -f /dev/testvg//mylv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/testvg//mylv: 12/655360 files (0.0% non-contiguous), 77936/2621440 blocks [root@node ~]# resize2fs /dev/testvg/mylv 3G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/testvg/mylv to 786432 (4k) blocks. The filesystem on /dev/testvg/mylv is now 786432 blocks long. [root@node ~]# lvreduce -L 3G /dev/testvg/mylv WARNING: Reducing active logical volume to 3.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv? [y/n]: y Reducing logical volume mylv to 3.00 GiB Logical volume mylv successfully resized [root@node ~]# e2fsck -f /dev/testvg/mylv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/testvg/mylv: 12/196608 files (0.0% non-contiguous), 47805/786432 blocks [root@node ~]# mount /dev/testvg/mylv /mnt [root@node ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node-lv_root 18G 3.8G 13G 24% / tmpfs 495M 72K 495M 1% /dev/shm /dev/sda1 485M 35M 426M 8% /boot /dev/mapper/testvg-mylv 3.0G 139M 2.7G 5% /mnt
原文地址:http://magine356wj.blog.51cto.com/2664956/1636634