Centos LVM Extended Disk instance

Source: Internet
Author: User
Tags uppercase letter webdate

Environment: CentOS

Prior knowledge:

Maximum disk problems

1, for LVM volumes created by LVM2, the capacity size depends on the kernel limit (and, of course, your disk space).
For LVM volumes created by LVM1, the maximum possible capacity of an LVM logical volume depends on the size of the extension used. The calculation formula is:
65534 * Extended size = maximum Logical volume size, default PE is 4M, range is 8k-16g,lvm1 max expansion to 1PB

65534 * 16GB = 1,048,544 GB

2, for disks larger than 2TB, should be partitioned with parted (the next article will explain), Fdisk can only support disk partitions below 2TB

3, the file system used by the system needs to support your logical volume size. The Linux default file system is ReiserFS, which supports up to 16TB of space.

OK, the problem is clear, because of the environment, the disk is not more than 2TB, we will use FDISK to partition

========================

1, see if the system supports LVM, whether there is PV

[Email protected] ~]# Rpm-qa |grep lvmlvm2-2.02.46-8.el5[[email protected] ~]# pvdisplay [[email protected] ~]#

2. View disk information

[Email protected] ~]# fdisk-l======disk/dev/sdb:21.4 GB, 21474836480 bytes255 heads, $ sectors/track, 2610 Cylindersu NITs = cylinders of 16065 * 8225280 bytes Device Boot Start End Blocks Id System

3, Partition

[[email protected] ~]# fdisk /dev/sdb  #选择磁盘The  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 &NBSP;SETUPS&NBSP;CAUSE&NBSP;PROBLEMS&NBSP;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): n   #创建分区Command  action   e    extended   p   primary partition  (1-4) p   # Select Create Primary partition partition number  (1-4): 1  #第一个分区First  cylinder  (1-2610, default &NBSP;1):  using default value 1last cylinder or +size or +sizem or +sizek  (1-2610,  default 2610): +10g  #分区大小Command   (m for help): ncommand action    e   extended   p   primary partition  (1-4) ppartition number  (1-4): 2  #第2个分区First  cylinder  (1218-2610, default  1218):  using default value 1218last cylinder or +size or +sizem  or +sizeK  (1218-2610, default 2610): using default value  2610command  (m for help): p   #查看分区信息Disk  /dev/sdb: 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/sdb1                1        1217      9775521   83  Linux      #id类型为83, we need to modify the LVM type ID/ dev/sdb2            1218         2610    11189272+  83  LinuxCommand  (M &NBSP;FOR&NBSP;HELP): l   #查看类型代码  0  Empty            1e  Hidden W95 FAT1 80  Old Minix        bf  Solaris          1  fat12           24  nec dos          81  Minix / old Lin c1  DRDOS/sec  ( fat- 2  xenix root      39  plan 9           82  linux swap / so c4   DRDOS/sec  (fat- 3  xenix usr       3c   PartitionMagic  83  Linux            c6  DRDOS/sec  (fat- 4  fat16 <32m       40  venix 80286     84  os/2 hidden  C:  c7  Syrinx          5   extended        41  ppc prep boot   85  linux  extended  da  non-fs data     6  fat16            42  SFS              86  ntfs volume set db  cp/m  / CTOS / . 7  HPFS/NTFS       4d   QNX4.x          87  NTFS volume  set de  dell utility    8  aix              4e  QNX4.x 2nd part 88   Linux plaintext df  bootit          9   aix bootable    4f  qnx4.x 3rd part 8e  linux lvm        e1  dos access      a  os /2 boot manag 50  ontrack dm      93   amoeba          e3  dos r/o          b  w95 fat32       51   ontrack dm6 aux 94  amoeba bbt      e4   SpeedStor       c  W95 FAT32  (LBA)  52   cp/m            9f  bsd/os           eb  BeOS fs          e  w95 fat16  (LBA)  53  OnTrack DM6 Aux a0   IBM Thinkpad hi ee  EFI GPT          f  w95 ext ' d  (LBA)  54  OnTrackDM6       a5  FreeBSD         ef  EFI  ( fat-12/16/10  opus            55   EZ-Drive        a6  OpenBSD          f0  Linux/PA-RISC b11  Hidden FAT12     56  Golden Bow      a7  NeXTSTEP         f1  SpeedStor      12   compaq diagnost 5c  priam edisk     a8  darwin ufs       f4  SpeedStor      14  Hidden FAT16  <3 61  SpeedStor       a9  NetBSD           f2  DOS secondary  16   hidden fat16    63  gnu hurd or sys ab   darwin boot     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 auto1b  hidden w95 fat3 70  disksecure  Mult bb  Boot Wizard hid fe  LANstep         1c  Hidden W95 FAT3 75  PC/IX            be  solaris boot    ff   BBT   Command  (m for help): t   #修改类型idPartition   number  (1-4): 1hex code  (type l to list codes): 8eChanged  system type of partition 1 to 8e  (LINUX&NBSP;LVM) Command  (m for &NBSP;HELP): tpartition number  (1-4): 2hex code  (type L to list  codes):  8e  changed system type of partition 2 to 8e   (LINUX&NBSP;LVM) command (m for help): p   #再次查看Disk  /dev/sdb: 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/sdb1                1        1217      9775521   8e  Linux LVM   #已经更改/dev/sdb2             1218         2610    11189272+  8e  Linux LVMCommand  (m for &NBSP;HELP): &NBSP;W&NBSP;&NBSP; #保存退出The  partition table has been altered! Calling ioctl ()  to re-read partition table. Syncing disks.

Above we divide the disk SDB into 2 primary partitions, if you do not need to create LVM, just mount a new disk to use, you do not need to modify the LVM Id,fdisk, after the format of the partition, the direct mount can be used, fdisk-l view the disk

[Email protected] ~]# fdisk-l======disk/dev/sdb:21.4 GB, 21474836480 bytes255 heads, $ sectors/track, 2610 Cylindersu               NITs = cylinders of 16065 * 8225280 bytes Device Boot Start End Blocks Id system/dev/sdb1 1 1217 9775521 8e Linux lvm/dev/sdb2 1218 2610 11189272+ 8e Linux LVM

2, create PV, at the beginning we have checked, the system does not exist PV, directly create PV

[Email protected] ~]# pvcreate/dev/sdb1/dev/sdb2 physical Volume "/DEV/SDB1" Successfully created physical volume "/d EV/SDB2 "successfully created[[email protected] ~]# pvscan pv/dev/sdb1 lvm2 [9.32 GB] Pv/dev/sdb 2 lvm2 [10.67 GB] Total:2 [19.99 GB]/in use:0 [0]/In no vg:2 [19.99 GB]

3, create VG (volume group)

[Email protected] ~]# vgcreate date_vg/dev/sdb1/dev/sdb2 Volume Group "DATE_VG" successfully created[[email protected]  ~]# Vgscan Reading All physical volumes.  This is a while ...  Found Volume Group "DATE_VG" using metadata type Lvm2[[email protected] ~]# vgdisplay-v DATE_VG #查看卷组信息 [[email protected] ~]# vgreduce date_vg/dev/sdb2 #从vg删除pv [[email protected] ~]# vgextend date_vg/dev/sdb2 #重新添加 Volume Group "DATE_VG" Su Ccessfully Extended

4, creating the LV

After you create a volume group, you can use the Lvcreate command to create a logical volume based on it. Before you create a logical volume, you also need to plan the size of the logical volume (divided by actual need), the mode of the logical volume, and so on.

1. Logical Volume mode

The logical volume has the following two modes, depending on how it is written:

Linear mode: Write the first physical volume that makes up a linear logical volume, write the data to the 2nd physical volume, and so on.

Interleaved mode: Writes data interleaved to write data to multiple physical volumes that compose a logical volume (written in a similar way to RAID 0). Logical volumes created in this manner cannot be extended in the physical volume in which they reside. Speed is fast, security is not high, if one of the physical volume problems, it is a big trouble

To create a interleaved logical volume, you can use the following command # option I to indicate that the interleaved value is 2, less than the number of physical volumes # option I (Uppercase letter i) indicates the block size of the specified logical volume, in this case the 4mb# option L (lowercase l) represents the number of blocks, in this case the number of blocks is 100 [email Protected] ~]# lvcreate-i 2-i 4-l 100-n date01_lv DATE_VG
#选项L用于指定逻辑卷的大小 # option n is used to specify the name of the logical volume [[email protected] ~]# lvcreate-l 10g-n date01_lv DATE_VG

Expanding logical volumes

#1, expand to how many g[[email protected] ~]# lvextend-l 18g/dev/date_vg/date01_lv #2, expand how much g[[email protected] ~]# lvextend-l +5g/dev /date_vg/date01_lv #注意, the size of the expansion should be less than the size of the volume group

Creating a file system

[[email protected] ~]# mkfs.ext3/dev/date_vg/date01_lv/[[email protected] ~]# mkdir/webdate/[[email protected] ~]# Moun t/dev/date_vg/date01_lv//webdate/
In order to automatically mount the logical volume when the system starts, you can add the following at the end of the configuration file/etc/fstab:/dev/date_vg/date01_lv//webdate/ext3 defaults 0 2

Online File system expansion

If you change the disk size using Lvextend, you should use RESIZE2FS for online expansion

Note: Command RESIZE2FS can only be used to adjust the ext2, ext3 file system, if the logical volume is using other file systems, you need to refer to the relevant documentation for specific commands

[[email protected] ~]# lvextend -l +2g /dev/date_vg/date01_lv [[email  Protected] ~]# resize2fs /dev/date_vg/date01_lv [[email protected] ~]# df  -lhFilesystem            Size   used avail use% mounted on/dev/sda2               48g  2.3g   43g   6% //dev/sda1              289M   16M   258M   6% /boottmpfs                  252M     0  252M    0% /dev/shm/dev/mapper/date_vg-date01_lv                         17g  170m   16g   2%  /webdate

Logical Volume Snapshot

When a database file is backed up, the information in the database is constantly written and deleted because the database is in a working state, resulting in inconsistent data after the backup. Snapshots (snapshot) can be used at this time.

Creating a logical volume snapshot is the same as creating a logical volume, using the Lvcreate command.

(1) Before you create a snapshot volume, you need to confirm the size of the original volume, because the snapshot volume that you create should usually be larger than the original volume (1.1 times to 1.2 times times).

#使用lvcreate命令创建名为db_snapshot的快照卷 # option L is used to specify the size of the snapshot Volume # option s indicates the snapshot volume to be created # option n is used to specify the name of the snapshot volume [[email protected] ~]# Lvcreate-l 2g-s-N datebak/dev/date_vg/date01_lv/

Once the snapshot volume is created, you can mount and back up the data files in it.

(2) After the backup is complete, you can uninstall and delete the snapshot volume using the following command:

[Email protected] ~]# umount/dev/date_vg/datebak/[[email protected] ~]# lvremove/dev/date_vg/datebak/


Centos LVM Extended Disk instance

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.