天天看点

LVM

1.LVM

1.划分物理分区并把分区id修改为8e

[root@desktop24 ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x708b697d.

Command (m for help): n

Partition type:

   p  primary (0 primary, 0 extended, 4 free)

   e  extended

Select (default p): 

Using default response p

Partition number (1-4, default 1): 

First sector (2048-20971519, default 2048): 

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):+500M

Partition 1 of type Linux and of size 500 MiB is set

   p  primary (1 primary, 0 extended, 3 free)

Partition number (2-4, default 2): 

First sector (1026048-20971519, default 1026048): 

Using default value 1026048

Last sector, +sectors or +size{K,M,G} (1026048-20971519, default 20971519):+500M

Partition 2 of type Linux and of size 500 MiB is set

Command (m for help): t

Partition number (1,2, default 2): 

Hex code (type L to list all codes): l

 0 Empty           24  NEC DOS         81 Minix / old Lin bf  Solaris        

 1 FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-

 2 XENIX root      39  Plan 9          83 Linux           c4  DRDOS/sec (FAT-

 3 XENIX usr       3c  PartitionMagic  84 OS/2 hidden C:  c6  DRDOS/sec (FAT-

 4 FAT16 <32M      40  Venix 80286     85 Linux extended  c7  Syrinx        

 5 Extended        41  PPC PReP Boot   86 NTFS volume set da  Non-FSdata    

 6 FAT16           42  SFS             87 NTFS volume set db  CP/M / CTOS /.

 7 HPFS/NTFS/exFAT 4d  QNX4.x          88 Linux plaintext de  DellUtility   

 8 AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df BootIt         

 9 AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1 DOS access     

 a OS/2 Boot Manag 50  OnTrack DM      94 Amoeba BBT      e3  DOS R/O       

 b W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4 SpeedStor      

 c W95 FAT32 (LBA) 52  CP/M            a0 IBM Thinkpad hi eb  BeOS fs        

 e W95 FAT16 (LBA) 53  OnTrack DM6Aux a5  FreeBSD         ee GPT            

 f W95 Ext'd (LBA) 54 OnTrackDM6      a6  OpenBSD         ef EFI (FAT-12/16/

10  OPUS            55 EZ-Drive        a7  NeXTSTEP        f0 Linux/PA-RISC b

11  Hidden FAT12    56 Golden Bow      a8  Darwin UFS      f1 SpeedStor      

12  Compaq diagnost 5c  Priam Edisk     a9 NetBSD          f4  SpeedStor     

14  Hidden FAT16 <3 61  SpeedStor       ab Darwin boot     f2  DOS secondary 

16  Hidden FAT16    63 GNU HURD or Sys af  HFS /HFS+      fb  VMware VMFS   

17  Hidden HPFS/NTF 64  Novell Netware  b7 BSDI fs         fc  VMware VMKCORE 

18  AST SmartSleep  65 Novell Netware  b8  BSDI swap       fd Linux raid auto

1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep       

1c  Hidden W95 FAT3 75  PC/IX           be Solaris boot    ff  BBT           

1e  Hidden W95 FAT1 80  Old Minix     

Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t 

Partition number (1,2, default 2): 1

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x708b697d

   Device Boot      Start         End      Blocks  Id  System

/dev/vdb1            2048     1026047      512000  8e  Linux LVM

/dev/vdb2         1026048    2050047      512000   8e Linux LVM

Command (m for help): wq

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@desktop24 ~]# partprobe 

再添加一个分区

[root@desktop24 ~]# pvcreate /dev/vdb1

  Physical volume "/dev/vdb1"successfully created

[root@desktop24 ~]# vg taxing /dev/vdb1

bash: vg: command not found...

[root@desktop24 ~]# vgcreate taxing /dev/vdb1

  Volume group "taxing"successfully created

[root@desktop24 ~]# lvcreate -L 100M -n timo taxing

  Logical volume "timo"created

[root@desktop24 ~]# mkfs.xfs /dev/taxing/timo

meta-data=/dev/taxing/timo      isize=256    agcount=4,agsize=6400 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=25600, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                  extsz=4096   blocks=0,rtextents=0

[root@desktop24 ~]# mount /dev/taxing/timo /mnt/

[root@desktop24 ~]# df

Filesystem              1K-blocks    Used Available Use% Mounted on

/dev/vda1                104739003805212   6668688  37% /

devtmpfs                   481120       0   481120   0% /dev

tmpfs                      496708      84   496624   1% /dev/shm

tmpfs                      496708  13072    483636   3% /run

tmpfs                      496708       0   496708   0% /sys/fs/cgroup

/dev/mapper/taxing-timo     98988    5280    93708   6% /mnt

设备可以无限扩大,文件系统受限制

[root@desktop24 ~]# lvextend -L 200M /dev/taxing/timo   扩展lv(文件设备)

  Extending logical volume timo to 200.00MiB

  Logical volume timo successfullyresized

[root@desktop24 ~]# xfs_growfs /dev/taxing/timo     延伸格式更新文件(类似mkfs_xfs,,,)在线扩展

meta-data=/dev/mapper/taxing-timo isize=256   agcount=4, agsize=6400 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

log      =internal               bsize=4096   blocks=853, version=2

data blocks changed from 25600 to 51200

[root@desktop24 ~]# pvcreate /dev/vdb2          创建pv物理卷

  Physical volume "/dev/vdb2"successfully created

[root@desktop24 ~]# vgextend taxing /dev/vdb2           扩展vg卷组

  Volume group "taxing"successfully extended

[root@desktop24 ~]# lvextend -L 600M /dev/taxing/timo   扩展lv到指定大小

  Extending logical volume timo to 600.00MiB

[root@desktop24 ~]# xfs_growfs /dev/taxing/timo     延拓文件大小

meta-data=/dev/mapper/taxing-timo isize=256   agcount=8, agsize=6400 blks

data     =                       bsize=4096   blocks=51200, imaxpct=25

realtime =none                  extsz=4096   blocks=0, rtextents=0

data blocks changed from 51200 to 153600

监控命令

[root@desktop24 Desktop]# watch -n 1 'echo "=== pvinfo ===";pvs;echo"=== vginfo ===";vgs;echo === lvinfo ===;lvs;df -h /mnt'

缩小

[root@desktop24 Desktop]# mkfs.ext4 /dev/mapper/taxing-timo   xfs文件不支持缩小

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

38400 inodes, 153600 blocks

7680 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=157286400

5 block groups

32768 blocks per group, 32768 fragments per group

7680 inodes per group

Superblock backups stored on blocks: 

    32768, 98304

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (4096 blocks): done

Writing superblocks and filesystem accounting information: done

[root@desktop24 Desktop]# resize2fs /dev/taxing/timo 200M   缩小设备文件大小

resize2fs 1.42.9 (28-Dec-2013)

Please run 'e2fsck -f /dev/taxing/timo' first.

[root@desktop24 Desktop]# e2fsck -f /dev/taxing/timo        检测设备文件

e2fsck 1.42.9 (28-Dec-2013)

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/taxing/timo: 11/38400 files (0.0% non-contiguous), 6740/153600blocks

[root@desktop24 Desktop]# resize2fs /dev/taxing/timo 200M   先缩小设备文件大小

Resizing the filesystem on /dev/taxing/timo to 51200 (4k) blocks.

The filesystem on /dev/taxing/timo is now 51200 blocks long.

[root@desktop24 Desktop]# lvreduce -L 300M /dev/taxing/timo     再缩小系统文件大小

  WARNING: Reducing active logical volumeto 300.00 MiB

  THIS MAY DESTROY YOUR DATA (filesystemetc.)

Do you really want to reduce timo? [y/n]: y

  Reducing logical volume timo to 300.00MiB

[root@desktop24 Desktop]# pvmove /dev/vdb1 /dev/vdb2        把系统文件1的数据移动到系统文件2上

  /dev/vdb1: Moved: 37.3%

  /dev/vdb1: Moved: 100.0%

[root@desktop24 Desktop]# vgreduce taxing /dev/vdb1     把系统文件/dev/vdb1从卷组中剔除

  Removed "/dev/vdb1" fromvolume group "taxing"

[root@desktop24 Desktop]# pvremove /dev/vdb1            移除系统文件/dev/vdb1

  Labels on physical volume"/dev/vdb1" successfully wiped

[root@desktop24 Desktop]# fdisk /dev/vdb 

Command (m for help): d

Partition 2 is deleted

WARNING: Re-reading the partition table failed with error 16: Device orresource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

[root@desktop24 Desktop]# partprobe 

Error: Partition(s) 2 on /dev/vdb have been written, but we have been unable toinform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remainin use.  You should reboot now beforemaking further changes.

Selected partition 1

Partition 1 is deleted

[root@desktop24 Desktop]# vgreduce --removemissing 

  Please give volume group name

  Run `vgreduce --help' for moreinformation.

[root@desktop24 Desktop]# vgreduce --removemissing taxing

  PVJoduaI-RPH9-xZQ6-MnhZ-q78e-450f-zIu2vU not recognised. Is the devicemissing?

  Wrote out consistent volume grouptaxing

含有数据的设备不能删除 

设备文件快照

[root@desktop24 Desktop]# lvcreate -L 300M -n zed -s /dev/taxing/timo

  Logical volume "zed"created

[root@desktop24 Desktop]# mount /dev/taxing/zed /mnt/

 LV  VG     Attr       LSize  Pool Origin Data%  Move LogCpy%Sync Convert

  timo taxing owi-a-s--- 300.00m

  zed taxing swi-aos--- 300.00m     timo     0.00

Filesystem              Size  Used Avail Use% Mounted on

/dev/mapper/taxing-zed  181M  616K 166M   1% /mnt

本文转自   Taxing祥   51CTO博客,原文链接:http://blog.51cto.com/12118369/1871429

继续阅读