【金沙澳门官网7817网址】LVM相关的通令及逻辑卷达成

 首先清除磁盘上的分区表信息, ,/dev/sdb 就是我新添加的磁盘了,4、创建物理分区,(如果开机状态添加的),模拟给redhat6添加两块SCSI硬盘大小为5G和7G,/dev/sdb 就是我新添加的磁盘了,4、创建物理分区

创设逻辑卷
 [root@SD-H0-ATTACH-G0S0 ~]# lvcreate -l 16T -n lv_mongodb
vg_mongodb
  Logical volume “lv_mongodb” created

LVM 逻辑卷管理

简介:

LVM ( Logical Volume Manager ) 逻辑卷管理

一、创建 LV

1、首先在您的设想机上增多一块新的硬盘用来做试验。

2、安装 lvm : yum -y install lvm2

3、查看新加上的磁盘

shell > fdisk -l

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: 0x00000000

## 当中,/dev/sdb 正是自己新加上的磁盘了

4、创设物理分区

shell > 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 0x62beb6a4.
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): m                          # 帮忙音讯
Command action
        a toggle a bootable flag
        b edit bsd disklabel
        c toggle the dos compatibility flag
        d delete a partition                    # 删除五个分区
        l list known partition types            # 打印分区类型对应的 ID

        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        # 改变分区 ID
        u change display/entry units
        v verify the partition table
        w write table to disk and exit          # 保存退出
        x extra functionality (experts only)

## 推行的命令是 fdisk /dev/sdb .

Command (m for help): n                          # 推行加多分区指令
Command action
e extended
p primary partition (1-4)
p                                                # 加多一个主分区
Partition number (1-4): 1                        # 分区号为 1
First cylinder (1-2610, default 1):              #
分区起头地点(直接回车)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
+1024M  # 分区竣事地点(+1024M 表示 1G 大小)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-2610, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-2610, default 2610):
+1024M

Command (m for help): p                          # 施行打字与印刷分区表

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: 0x62beb6a4

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux

## 能够看到分了多少个区 /dev/sdb1 /dev/sdb2

Command (m for help): t                          # 试行更动分区 ID (83
表示Linux 普通分区、82 表示swap、8e 表示LVM)
Partition number (1-4): 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

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: 0x62beb6a4

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 8e Linux LVM
/dev/sdb2 133 264 1060290 8e Linux LVM

## 已经看到分区 ID 变为 8e ; 文件系统为 Linux LVM

Command (m for help): w                          # 实施保存退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

shell > fdisk -l /dev/sdb

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: 0x62beb6a4

Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 8e Linux LVM
/dev/sdb2 133 264 1060290 8e Linux LVM

## 能够观望磁盘 /dev/sdb 有五个分区 /dev/sdb1 /dev/sdb2

5、创建 PV (物理卷)

shell > pvcreate /dev/sdb1 /dev/sdb2
  Physical volume “/dev/sdb1” successfully created
  Physical volume “/dev/sdb2” successfully created

## 使用 pvcreate 成立 PV 前边跟想要成立的分区

shell > pvscan
  PV /dev/sda3 VG vg_study lvm2 [18.80 GiB / 0 free]
  PV /dev/sdb1 lvm2 [1.01 GiB]
  PV /dev/sdb2 lvm2 [1.01 GiB]
  Total: 3 [20.82 GiB] / in use: 1 [18.80 GiB] / in no VG: 2 [2.02
GiB]

## 使用 pvscan 、pvdisplay 、pvs 都得以查阅 PV
## PV /dev/sdb1 pv /dev/sdb2 为本人新创立的 PV 大小为 1G(PV /dev/sda3
为事先创制的属 VG vg_study )

6、创建 VG (卷组)

shell > vgcreate my_vg /dev/sdb1 /dev/sdb2
  Volume group “my_vg” successfully created

## 使用 vgcreate 创立卷组,后边接 vg 名,接 pv

shell > vgdisplay
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 2
  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 2
  Act PV 2
  VG Size 2.02 GiB
  PE Size 4.00 MiB
  Total PE 516
  Alloc PE / Size 0 / 0
  Free PE / Size 516 / 2.02 GiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

## 一样能够行使 vgscan 、vgs 、vgdisplay 来查阅 VG
## 能够看出 VG名称叫 my_vg 、VG 大小为 2G 、PE 大小 4M 等

7、创建 LV (逻辑卷)

shell > lvcreate -L 2G -n my_lv my_vg
  Logical volume “my_lv” created

## 使用 lvcreate 创建 LV ,-L 指定 LV大小,-n 指定 LV名称,后面接 VG名

shell > lvdisplay
  — Logical volume —
  LV Path /dev/my_vg/my_lv
  LV Name my_lv
  VG Name my_vg
  LV UUID j9Bduh-3TB9-Owhz-X3PX-fVeQ-bvJe-OAFBVp
  LV Write Access read/write
  LV Creation host, time study.localhost.localdomain, 2014-11-26
11:14:28 +0800
  LV Status available
  # open 0
  LV Size 2.00 GiB
  Current LE 512
  Segments 2
  Allocation inherit
  Read ahead sectors auto
  – currently set to 256
  Block device 253:1

## 一样可以运用 lvscan 、lvs 、lvdisplay 来查看 LV
## 能够看到 LV路线 /dev/my_vg/my_lv 、LV名 my_lv 、VG名 my_vg
、LV大小 2G 等

8、成立文件系统 (格式化)

shell > mkfs.ext4 /dev/my_vg/my_lv
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
首先个数据块=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

正在写入inode表: 落成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

## 使用 mkfs.ext4 格式化为 ext4 文件系统

9、挂载使用

shell > mkdir /data
shell > mount /dev/my_vg/my_lv /data/
shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 2.2G 71M 2.0G 4% /data

## 创建 /data 目录,将 /dev/my_vg/my_lv 挂载到 /data

shell > umount /data/
shell > blkid /dev/my_vg/my_lv
/dev/my_vg/my_lv: UUID=”a8cb322e-1872-4ea8-bfba-f21b678bc849″
TYPE=”ext4″
shell > echo “UUID=”a8cb322e-1872-4ea8-bfba-f21b678bc849″ /data ext4
defaults 0 0” >> /etc/fstab
shell > mount -a
shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.5G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 2.2G 71M 2.0G 4% /data

## 也得以采纳 blkid 生成 UUID 然后写入到 /etc/fstab
文件中,达成开机自动挂载

二、扩容 LV

1、首先创设物理分区(珍视是此番创造后要格式化)

2、创建 PV

3、扩容 VG

shell > vgextend my_vg /dev/sdb3
  Volume group “my_vg” successfully extended

## 使用 vgextend 指令扩展 VG ,后边接要扩充的 VG名 ,前面接将哪个 PV
增添进去

shell > vgdisplay my_vg
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 3
  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 3
  Act PV 3
  VG Size 3.02 GiB
  PE Size 4.00 MiB
  Total PE 774
  Alloc PE / Size 512 / 2.00 GiB
  Free PE / Size 262 / 1.02 GiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

## 能够应用 vgdisplay my_vg 来钦点查看哪个 VG
## 能够看出 VG 总大小为 3G 、已选拔 2G 、空闲 1G(因为大家扩进去 1G 的
PV)

4、扩容 LV

shell > lvextend -L +1G /dev/my_vg/my_lv
  Size of logical volume my_vg/my_lv changed from 2.00 GiB (512
extents) to 3.00 GiB (768 extents).
  Logical volume my_lv successfully resized

## 使用 lvextend 扩大体量 LV ,-L 钦命扩多大 ,前面接 LV 实际路径/dev/my_vg/my_lv

shell > lvdisplay /dev/my_vg/my_lv
  — Logical volume —
  LV Path /dev/my_vg/my_lv
  LV Name my_lv
  VG Name my_vg
  LV UUID j9Bduh-3TB9-Owhz-X3PX-fVeQ-bvJe-OAFBVp
  LV Write Access read/write
  LV Creation host, time study.localhost.localdomain, 2014-11-26
11:14:28 +0800
  LV Status available
  # open 1
  LV Size 3.00 GiB
  Current LE 768
  Segments 3
  Allocation inherit
  Read ahead sectors auto
  – currently set to 256
  Block device 253:1

## 可以应用 lvdisplay /dev/my_vg/my_lv 来查看 LV 大小
## LV 大小变为了 3G (原 2G)

5、投入使用

shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 2.2G 71M 2.0G 4% /data

## 我们发掘分区 /data 大小依然 2G

shell > resize2fs /dev/my_vg/my_lv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/my_vg/my_lv is mounted on /data; on-line resizing
required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/my_vg/my_lv to 786432 (4k)
blocks.
The filesystem on /dev/my_vg/my_lv is now 786432 blocks long.

shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 3.2G 71M 3.0G 3% /data

## 使用 resize2fs /dev/my_vg/my_lv 重新计算分区大小后 发现扩容到了
3G

三、缩减 LV

1、模拟数据写入

shell > dd if=/dev/zero of=/data/block.db bs=1024M count=1
记录了1+0 的读入
记录了1+0 的写出
1073741824字节(1.1 GB)已复制,81.6381 秒,13.2 MB/秒

## 大家运用 dd 命令写了 1G 的多少到 /data

shell > cp /etc/passwd /data/ ##
复制那几个文件的目标是表达数据是或不是遗失

shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 3.2G 1.2G 1.9G 39% /data

## 未来这些剩余空间 大家想把他离去来 1G

2、首先检查一下文件系统

shell > umount /data/ ## 必必要先 umount
shell > e2fsck -f /dev/my_vg/my_lv
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
其次步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要音讯
/dev/my_vg/my_lv: 13/196608 files (0.0% non-contiguous), 291646/786432
blocks

3、重新总结大小

shell > resize2fs /dev/my_vg/my_lv 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/my_vg/my_lv to 524288 (4k) blocks.
The filesystem on /dev/my_vg/my_lv is now 524288 blocks long.

## 重新定义大小为 2G

4、缩小 LV

shell > lvreduce -L -1G /dev/my_vg/my_lv
  WARNING: Reducing active logical volume to 2.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce my_lv? [y/n]: y
  Size of logical volume my_vg/my_lv changed from 3.00 GiB (768
extents) to 2.00 GiB (512 extents).
  Logical volume my_lv successfully resized

## 使用 lvreduce 来缩小 LV ,-L -1G 缩小 1G

shell > mount -a
shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 2.2G 1.2G 863M 58% /data

shell > ls /data/
block.db lost+found passwd

## 重新挂载分区,发掘数目尚未难题 (仅是测量检验,未有察觉标题)

5、VG 中移除 PV

shell > vgdisplay my_vg
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 3
  Metadata Sequence No 6
  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 3.02 GiB
  PE Size 4.00 MiB
  Total PE 774
  Alloc PE / Size 637 / 2.49 GiB
  Free PE / Size 137 / 548.00 MiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

## 首先大家 vgdisplay my_vg ,发现 VG 空闲 548M

shell > pvdisplay
  — Physical volume —
  PV Name /dev/sdb1
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.41 MiB
  Allocatable yes (but full)
  PE Size 4.00 MiB
  Total PE 258
  Free PE 0
  Allocated PE 258
  PV UUID JB8X8v-jBPU-eOiN-aEOU-TOig-tv01-SuHytd

  — Physical volume —
  PV Name /dev/sdb2
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes (but full)
  PE Size 4.00 MiB
  Total PE 258
  Free PE 0
  Allocated PE 258
  PV UUID YXBMJJ-RyG3-z1xa-tlw6-piaI-cTgj-SIBIlz

  — Physical volume —
  PV Name /dev/sdb3
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 258
  Free PE 137
  Allocated PE 121
  PV UUID jSpEdJ-fxZh-LP27-rFIM-0gnO-mL2x-PpBJpK

## 其次使用 pvdisplay 查看 PV 的运用状态开掘:
/dev/sdb1 PE 空闲 0
 /dev/sdb2 PE 空闲 0
 /dev/sdb3 PE 空闲 137 (上海教室呈现种种 PE 为 4M ,那么 /dev/sdb3
总空闲体量=137*4 = 548M)
## 正好等于 VG 的悠闲大小,而 PV /dev/sdb3 大小为 1G
,也等于说有部分空间被占用,所以不恐怕移除该 PV

shell > vgreduce my_vg /dev/sdb3
  Physical volume “/dev/sdb3” still in use
shell > umount /data/
shell > vgreduce my_vg /dev/sdb3
  Physical volume “/dev/sdb3” still in use

## 提示正在被占用,不能移除( umount 分区也不行 )

shell > umount /data/

shell > e2fsck -f /dev/my_vg/my_lv
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
其次步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要音信
/dev/my_vg/my_lv: 14/163840 files (0.0% non-contiguous), 289591/652288
blocks

shell > resize2fs /dev/my_vg/my_lv 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/my_vg/my_lv to 524288 (4k) blocks.
The filesystem on /dev/my_vg/my_lv is now 524288 blocks long.

shell > lvreduce -L -500M /dev/my_vg/my_lv
  WARNING: Reducing active logical volume to 2.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce my_lv? [y/n]: y
  Size of logical volume my_vg/my_lv changed from 2.49 GiB (637
extents) to 2.00 GiB (512 extents).
  Logical volume my_lv successfully resized

## 我们把 LV 缩小了 500M

shell > vgdisplay my_vg
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 3
  Metadata Sequence No 9
  VG Access read/write
  VG Status resizable
  MAX LV 0
  Cur LV 1
  Open LV 0
  Max PV 0
  Cur PV 3
  Act PV 3
  VG Size 3.02 GiB
  PE Size 4.00 MiB
  Total PE 774
  Alloc PE / Size 512 / 2.00 GiB
  Free PE / Size 262 / 1.02 GiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

## 未来再看 VG 大小 空闲 1G

shell > pvdisplay
  — Physical volume —
  PV Name /dev/sdb3
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 258
  Free PE 258
  Allocated PE 0
  PV UUID jSpEdJ-fxZh-LP27-rFIM-0gnO-mL2x-PpBJpK

## pvdisplay 也意识 /dev/sdb3 正好全部悠然

shell > vgreduce my_vg /dev/sdb3
  Removed “/dev/sdb3” from volume group “my_vg”

## 已经打响将 PV /dev/sdb3 从 VG my_vg 中移除

shell > vgs
  VG #PV #LV #SN Attr VSize VFree
  my_vg 2 1 0 wz–n- 2.02g 16.00m

## 使用 vgs 能够看到 vg my_vg 中包含 PV 数为 2

6、删除 PV

shell > pvremove /dev/sdb3
  Labels on physical volume “/dev/sdb3” successfully wiped

## 使用 pvremove 删除 PV /dev/sdb3

shell > pvs
  PV VG Fmt Attr PSize PFree
  /dev/sdb1 my_vg lvm2 a– 1.01g 0
  /dev/sdb2 my_vg lvm2 a– 1.01g 16.00m

## 使用 pvs 看到独有七个 PV 了
## 然后 fdisk /dev/sdb 将 sdb3 的 ID 改为 83 ,保存
mkfs.ext4 /dev/sdb3 ,重新挂载到目录,至此 /dev/sdb3 成为平常分区

四、删除全数 lv vg pv

shell > umount /data/
shell > lvremove /dev/my_vg/my_lv
  Do you really want to remove active logical volume my_lv? [y/n]:
y
  Logical volume “my_lv” successfully removed
  shell > vgremove my_vg
  Volume group “my_vg” successfully removed
shell > pvremove /dev/sdb1
  Labels on physical volume “/dev/sdb1” successfully wiped
shell > pvremove /dev/sdb2
  Labels on physical volume “/dev/sdb2” successfully wiped

## 删除比创设轻巧多了 …

LVM2详解 

Ubuntu 上利用 LVM 轻便调解分区并创造快速照相 

行使LVM创制弹性磁盘存款和储蓄——第一某个 

在Linux中扩展/缩减LVM(第二片段) 

在 LVM中 摄像逻辑卷快速照相并还原(第三有的)

在LVM中装置精简财富调配卷(第四有些)

采取条块化I/O管理三个LVM磁盘(第五片段)

本文永远更新链接地址:

逻辑卷管理 简要介绍: LVM ( Logical Volume
Manager ) 逻辑卷管理 一、创造 LV
1、首先在你的虚构机上增多一块新的硬盘用来做尝试。 2、安装 lv…

  PV        VG      Fmt  Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a–  19.51g    0
  /dev/sdb1          lvm2 a–  4.99g 4.99g
  /dev/sdc1          lvm2 a–  6.99g 6.99g

## 使用 mkfs.ext4 格式化为 ext4 文件系统

始建物理卷
 [root@SD-H0-ATTACH-G0S0 ~]# pvcreate /dev/sda
  Writing physical volume data to disk “/dev/sda”
  Physical volume “/dev/sda” successfully created

4推行命令:partprobe —–>重新读取分区表
                  cat /proc/partitons
—–>查看分区表是还是不是加载创的新分区

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: 0x62beb6a4

 首先排除磁盘上的分区表新闻:
 [root@SD-H0-ATTACH-G0S0 ~]# dd if=/dev/zero of=/dev/sda bs=512
count=1
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.000446406 s, 1.1 MB/s

Command (m for help): n    —>命令n 成立新分区
Command action
  e  extended                      —->e为扩张分区
  p  primary partition (1-4)—–>p为主分区
p                                          —–>我们那边选用主分区
Partition number (1-4): 1  —–>主分区编号,选拔暗中认可

shell > vgs
  VG #PV #LV #SN Attr VSize VFree
  my_vg 2 1 0 wz–n- 2.02g 16.00m

金沙澳门官网7817网址 1

GiB

6 vg 卷组
        1;创建vg  vgcreate

      [root@localhost ~]# vgcreate myvg /dev/sdb1
/dev/sdc1—->vgcreate vg_name /part/to/sd :vgcreate 卷组名
跟要开创vg的设施
      Volume group “myvg” successfully created
      2;显示vg  vgs/vgdisplay

    [root@localhost ~]# vgs
  VG      #PV #LV #SN Attr  VSize  VFree
  VolGroup  1  2  0 wz–n- 19.51g    0

## 试行的下令是 fdisk /dev/sdb .

[root@SD-H0-ATTACH-G0S0 ~]# pvdisplay
  — Physical volume —
  PV Name              /dev/sdb2
  VG Name              vg_lvs2
  PV Size              1.09 TiB / not usable 3.00 MiB
  Allocatable          yes (but full)
  PE Size              4.00 MiB
  Total PE              285762
  Free PE              0
  Allocated PE          285762
  PV UUID              93Hrn1-R8m4-fv8S-S7G6-3vpa-N4EH-GOevM9
 
  — Physical volume —
  PV Name              /dev/sda
  VG Name              vg_mongodb
  PV Size              18.19 TiB / not usable 4.00 MiB
  Allocatable          yes
  PE Size              4.00 MiB
  Total PE              4767999
  Free PE              4767999
  Allocated PE          0
  PV UUID              nUhMM9-S51t-nlKz-wgVS-nkCh-sgXD-Qr4bZv

Selected partition 1
Hex code (type L to list codes): 8e—–>类型为8e LVM
倘使有不知晓类型的可以L查看
Changed system type of partition 1 to 8e (Linux LVM)

LVM2详解 
http://www.linuxidc.com/Linux/2015-09/122976.htm

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

First cylinder (1-652, default 1): —–>起首柱面号码,选择私下认可

## 使用 lvreduce 来缩小 LV ,-L -1G 缩小 1G

现存一台服务器已经安装了操作系统,接上了盘柜未来,须求创制逻辑卷以供系统挂载使用。整个磁盘作为三个分区,CentOS
6.3文件系统有最大16T限制。

  — Physical volume —

shell > resize2fs /dev/my_vg/my_lv 2G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/my_vg/my_lv to 524288 (4k) blocks.
The filesystem on /dev/my_vg/my_lv is now 524288 blocks long.

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

2:pv  :查看pv信息
[root@localhost ~]# pvs  —–> 查看pv信息

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-2610, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-2610, default 2610):
+1024M

格式化文件系统
 [root@SD-H0-ATTACH-G0S0 ~]# mkfs.ext4 /dev/vg_mongodb/lv_mongodb
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 width=0 blocks
1073741824 inodes, 4294967295 blocks
214748364 blocks (5.00%) reserved for the super user
First data block=0
131072 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,
2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616,
78675968,
        102400000, 214990848, 512000000, 550731776, 644972544,
1934917632,
        2560000000, 3855122432

  Found volume group “VolGroup” using metadata type lvm2

7 lv 逻辑卷
  1逻辑卷创设:lvcreate -L #G -n lv_name vg_name
      -L :钦赐创制lv大小
      -n :lv的名字
 
[root@localhost ~]# lvcreate -L 6G -n testlv myvg—>
  Logical volume “testlv” created
2 lv 的查看 :lvs :查看音信 / lvdisplay:查看详细消息
[root@localhost ~]# lvs
  LV      VG      Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync
Convert
  lv_root VolGroup -wi-ao—- 17.51g                                   
       
  lv_swap VolGroup -wi-ao—-  2.00g                                   
       
  testlv  myvg    -wi-a—–  6.00g
3 扫描lv  :lvscan
[root@localhost ~]# lvscan
  ACTIVE            ‘/dev/myvg/testlv’ [6.00 GiB] inherit
  ACTIVE            ‘/dev/VolGroup/lv_root’ [17.51 GiB] inherit
  ACTIVE            ‘/dev/VolGroup/lv_swap’ [2.00 GiB] inherit
4 格式化 mkfs /mke2fs
    mke2fs -j /dev/myvg/testlv
[root@localhost ~]# mkfs /dev/myvg/testlv
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 width=0 blocks
393216 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 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

Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
5挂载lv mount
      mkdir -p /mnt/lv  在mnt目录下创办lv目录,留挂载用
      mount /dev/myvg/testlv /mnt/lv
[root@localhost lv]# ll /mnt/lv —–>查看挂载点,看到lost+found
表明成功挂载
total 16
drwx——. 2 root root 16384 Mar 24 19:07 lost+found
6 查看挂载后的lv大小  df -lh
[root@localhost lv]# df -lh
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  18G  1.9G  15G  12% /
tmpfs                        931M    0  931M  0% /dev/shm
/dev/sda1                    485M  39M  421M  9% /boot
/dev/mapper/myvg-testlv      6.0G  12M  5.6G  1% /mnt/lv
8:lv的扩展
  *1 扩展lv物理边界 ,先查看一下vg中是还是不是有丰裕的可用空间

    lvextend -L [+]#G /part/to/lv_name
  注:  带+扩展#G    不带+表明扩充到#G

[root@localhost ~]# lvextend -L 10G /dev/myvg/testlv
  Extending logical volume testlv to 10.00 GiB
  Logical volume testlv successfully resized
 (2)查看lv大小 lvs
  Logical volume testlv successfully resized
[root@localhost lv]# lvs
  LV      VG      Attr      LSize  Pool Origin Data%  Move Log Cpy%Sync
Convert
  lv_root VolGroup -wi-ao—- 17.51g                                   
       
  lv_swap VolGroup -wi-ao—-  2.00g                                   
       
  testlv  myvg    -wi-ao—- 10.0 
那是lv已经增加到10G了。大家前天来看一下df -lh文件(3)系统中的lv大小
[root@localhost lv]# df -lh
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  18G  1.9G  15G  12% /
tmpfs                        931M    0  931M  0% /dev/shm
/dev/sda1                    485M  39M  421M  9% /boot
/dev/mapper/myvg-testlv      6.0G  12M  5.6G  1% /mnt/lv 
那是文件系统中的lv照旧6G未有变动,全体大家还要扩张lv的文件系统边界
*2 扩大lv的文件系统边界
(在redhat5上帮衬在线增加,redhat6不匡助。须要卸载挂载)
  lvsize2fs /part/to/lv_name #G
        -p  扩张到和概况边界同样大
  先卸载挂载umount /dev/myvg/testlv
[root@localhost lv]# umount /dev/myvg/testlv
umount: /mnt/lv: device is busy.—->磁盘繁忙,不让大家卸载。
        (In some cases useful info about processes that use
        the device is found by lsof(8) or fuser(1))
[root@localhost lv]# fuser -mk
/dev/myvg/testlv—->把挂载点上的长河截至,也许会logout 重登
//dev/myvg/testlv:    2164c
 再强行磁盘检查 e2fsck -f /dev/myvg/testlv
  [root@localhost ~]# e2fsck -f /dev/myvg/testlv   
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
最终扩张lv的文件系统边界 resize2fs /dev/myvg/testlv 10G
[root@localhost ~]# resize2fs /dev/myvg/testlv 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/testlv to 2621440 (4k) blocks.
The filesystem on /dev/myvg/testlv is now 2621440 blocks long.
再次挂载运维,mount /dve/myvg/testlv /mnt/lv
安装开机自动挂载 vi /etc/fstab 在中间增添一行

/dev/myvg/testlv        /mnt/lv                ext3    defaults      0
0
~
9 :lv的缩减
  1,要先检查文件系统,明确削减后的多少可见放的下
  2,无法在线缩减,必须先卸载
  3,缩减从前,必须先磁盘检查e2fsck ,再减去lv文件系统大小resize2fs
/part/to/lv_name
    最终在缩减lv物理边界的大lvreduce -L #G /part/to/lv_name。
  4,重新挂载启用
10 快照卷
lvcreate  -s  -L #G  -n lv_name  vg

本文永远更新链接地址:http://www.linuxidc.com/Linux/2017-03/142218.htm

金沙澳门官网7817网址 2

## 已经见到分区 ID 变为 8e ; 文件系统为 Linux LVM

挂载使用
 [root@SD-H0-ATTACH-G0S0 ~]# mount /dev/vg_mongodb/lv_mongodb
/dragon/data
[root@SD-H0-ATTACH-G0S0 ~]#
[root@SD-H0-ATTACH-G0S0 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_lvs2-lv_root
                      1.1T  2.5G  1.1T  1% /
tmpfs                7.8G    0  7.8G  0% /dev/shm
/dev/sdb1            485M  58M  402M  13% /boot
/dev/mapper/vg_mongodb-lv_mongodb
                      16T  129M  15T  1% /dragon/data

  PV Name              /dev/sda2
  VG Name              VolGroup
  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              NtZgu3-kqfB-HYtw-YMzu-oM6r-Fy9c-0kmeqf
 
  “/dev/sdb1” is a new physical volume of “4.99 GiB”
  — NEW Physical volume —
  PV Name              /dev/sdb1
  VG Name             
  PV Size              4.99 GiB
  Allocatable          NO
  PE Size              0 
  Total PE              0
  Free PE              0
  Allocated PE          0
  PV UUID              CCEdHk-dQJi-YfZi-SGnO-cnoc-mLgV-AqwokJ
 
  “/dev/sdc1” is a new physical volume of “6.99 GiB”
  — NEW Physical volume —
  PV Name              /dev/sdc1
  VG Name             
  PV Size              6.99 GiB
  Allocatable          NO
  PE Size              0 
  Total PE              0
  Free PE              0
  Allocated PE          0

4、缩小 LV

创办物理卷组
 [root@SD-H0-ATTACH-G0S0 ~]# vgcreate vg_mongodb /dev/sda
  Volume group “vg_mongodb” successfully created
[root@SD-H0-ATTACH-G0S0 ~]# vgs
  VG        #PV #LV #SN Attr  VSize  VFree
  vg_lvs2      1  2  0 wz–n-  1.09t    0
  vg_mongodb  1  0  0 wz–n- 18.19t 18.19t

Command (m for help): t—–>命令t 退换分区类型

shell > pvdisplay
  — Physical volume —
  PV Name /dev/sdb1
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.41 MiB
  Allocatable yes (but full)
  PE Size 4.00 MiB
  Total PE 258
  Free PE 0
  Allocated PE 258
  PV UUID JB8X8v-jBPU-eOiN-aEOU-TOig-tv01-SuHytd

1,希图干活虚构机vmware
和RedHat6
server,模拟给redhat6增添两块SCSI硬盘大小为5G和7G
也能够自定大小,增加实现->开机,(假如开机状态增添的)# :reboot
2,查看磁盘的磁盘名 fdisk -l (鲜明/dev/sdb和/dev/sdc 两块磁盘)
[root@localhost ~]# ll /dev/sd*
brw-rw—-. 1 root disk 8,  0 Mar 24 06:55 /dev/sda
brw-rw—-. 1 root disk 8,  1 Mar 24 06:55 /dev/sda1
brw-rw—-. 1 root disk 8,  2 Mar 24 06:55 /dev/sda2
brw-rw—-. 1 root disk 8, 16 Mar 24 06:55 /dev/sdb
brw-rw—-. 1 root disk 8, 32 Mar 24 06:55 /dev/sdc
3对/dev/sdb 和/dev/sdc 分区
 [root@localhost ~]# fdisk /dev/sdb

shell > lvdisplay /dev/my_vg/my_lv
  — Logical volume —
  LV Path /dev/my_vg/my_lv
  LV Name my_lv
  VG Name my_vg
  LV UUID j9Bduh-3TB9-Owhz-X3PX-fVeQ-bvJe-OAFBVp
  LV Write Access read/write
  LV Creation host, time study.localhost.localdomain, 2014-11-26
11:14:28 +0800
  LV Status available
  # open 1
  LV Size 3.00 GiB
  Current LE 768
  Segments 3
  Allocation inherit
  Read ahead sectors auto
  – currently set to 256
  Block device 253:1

  Physical volume “/dev/sdb1” successfully created
  Physical volume “/dev/sdc1” successfully created

5、投入使用


shell > umount /data/ ## 必需求先 umount
shell > e2fsck -f /dev/my_vg/my_lv
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要音信
/dev/my_vg/my_lv: 13/196608 files (0.0% non-contiguous), 291646/786432
blocks

  PV UUID              tbAPyW-Mxzp-spvY-6qtA-k08s-pj40-7gWZHo

3:pv 的移除
[root@localhost ~]# pvremove /dev/sdb1——>跟要移除的分区
  Labels on physical volume “/dev/sdb1” successfully wiped
[root@localhost ~]# pvs
  PV        VG      Fmt  Attr PSize  PFree
  /dev/sda2  VolGroup lvm2 a–  19.51g    0
  /dev/sdc1          lvm2 a–  6.99g 6.99g
 —————————————————–
4:pv 元数据的移位
  pvmove  :加入vg以后,及生成PE ;使用pvremove 之前,要pvmove

  — Physical volume —
  PV Name /dev/sdb2
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes (but full)
  PE Size 4.00 MiB
  Total PE 258
  Free PE 0
  Allocated PE 258
  PV UUID YXBMJJ-RyG3-z1xa-tlw6-piaI-cTgj-SIBIlz

  VG Size              19.51 GiB

3 删除vg  vgremove
[root@localhost ~]# vgremove myvg  —->vgremove 卷组名
  Volume group “myvg” successfully removed
 4缩减vg(从vg中缩减pv)  vgreduce
[root@localhost ~]# vgreduce myvg /dev/sdc1—–>vgreduce 卷组名
卷组中的设备
  Removed “/dev/sdc1” from volume group “myvg”
5扩展vg    ;vgextend
[root@localhost ~]# vgextend myvg /dev/sdc1—>vgextend
要增加卷组名 要增加设备
  Volume group “myvg” successfully extended
6扫描vg  vgscan
[root@localhost ~]# vgscan
  Reading all physical volumes.  This may take a while…
  Found volume group “myvg” using metadata type lvm2

## 已经打响将 PV /dev/sdb3 从 VG my_vg 中移除

Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652):
—–>结束柱面编号,依据本身的磁盘划分,能够用+#G来确定

shell > lvdisplay
  — Logical volume —
  LV Path /dev/my_vg/my_lv
  LV Name my_lv
  VG Name my_vg
  LV UUID j9Bduh-3TB9-Owhz-X3PX-fVeQ-bvJe-OAFBVp
  LV Write Access read/write
  LV Creation host, time study.localhost.localdomain, 2014-11-26
11:14:28 +0800
  LV Status available
  # open 0
  LV Size 2.00 GiB
  Current LE 512
  Segments 2
  Allocation inherit
  Read ahead sectors auto
  – currently set to 256
  Block device 253:1

转换原数据

5;pvscan 扫描系统上pv
[root@localhost ~]# pvscan
  PV /dev/sda2  VG VolGroup        lvm2 [19.51 GiB / 0    free]
  PV /dev/sdb1                      lvm2 [4.99 GiB]
  PV /dev/sdc1                      lvm2 [6.99 GiB]
  Total: 3 [31.50 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [11.99

## 大家开采分区 /data 大小依旧 2G

[root@localhost ~]# pvdisplay —–> 查看pv的详细音信

shell > pvcreate /dev/sdb1 /dev/sdb2
  Physical volume “/dev/sdb1” successfully created
  Physical volume “/dev/sdb2” successfully created

  myvg      2  0  0 wz–n- 11.98g 11.98g

[root@localhost ~]# vgdisplay
  — Volume group —
  VG Name              myvg
  System ID           
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size              11.98 GiB
  PE Size              4.00 MiB
  Total PE              3068
  Alloc PE / Size      0 / 0 
  Free  PE / Size      3068 / 11.98 GiB
  VG UUID              7qz29d-SrAL-wgpf-0sQZ-XgjJ-mtVf-1eQpEG
 
  — Volume group —
  VG Name              VolGroup
  System ID           
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access            read/write
  VG Status            resizable
  MAX LV                0
  Cur LV                2
  Open LV              2
  Max PV                0
  Cur PV                1
  Act PV                1

shell > 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 0x62beb6a4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.

Command (m for help): w—–>命令w 保存退出
                以同一格局创立/dev/sdc

  — Physical volume —
  PV Name /dev/sdb3
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 258
  Free PE 137
  Allocated PE 121
  PV UUID jSpEdJ-fxZh-LP27-rFIM-0gnO-mL2x-PpBJpK

  1:pv 创建
    [root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc1—–>
pvcreate 跟要到场pv的设备

shell > df -HT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_study-LogVol00 ext4 20G 1.4G 18G 8% /
tmpfs tmpfs 521M 0 521M 0% /dev/shm
/dev/sda1 ext4 204M 30M 164M 16% /boot
/dev/mapper/my_vg-my_lv ext4 2.2G 71M 2.0G 4% /data

5pv  物理卷

6、创建 VG (卷组)

Using default value 652

正在写入inode表: 达成
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

## 重新定义大小为 2G

shell > vgdisplay my_vg
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 3
  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 3
  Act PV 3
  VG Size 3.02 GiB
  PE Size 4.00 MiB
  Total PE 774
  Alloc PE / Size 512 / 2.00 GiB
  Free PE / Size 262 / 1.02 GiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

shell > pvdisplay
  — Physical volume —
  PV Name /dev/sdb3
  VG Name my_vg
  PV Size 1.01 GiB / not usable 3.44 MiB
  Allocatable yes
  PE Size 4.00 MiB
  Total PE 258
  Free PE 258
  Allocated PE 0
  PV UUID jSpEdJ-fxZh-LP27-rFIM-0gnO-mL2x-PpBJpK

## 使用 vgextend 指令扩张 VG ,前面接要扩张的 VG名 ,后边接将哪个 PV
扩大进去

shell > vgdisplay my_vg
  — Volume group —
  VG Name my_vg
  System ID
  Format lvm2
  Metadata Areas 3
  Metadata Sequence No 6
  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 3.02 GiB
  PE Size 4.00 MiB
  Total PE 774
  Alloc PE / Size 637 / 2.49 GiB
  Free PE / Size 137 / 548.00 MiB
  VG UUID ynCJG8-ZIvI-9gBF-dO5K-aQws-N9WW-r26hch

shell > lvextend -L +1G /dev/my_vg/my_lv
  Size of logical volume my_vg/my_lv changed from 2.00 GiB (512
extents) to 3.00 GiB (768 extents).
  Logical volume my_lv successfully resized

Ubuntu 上选用 LVM
轻便调治分区并制作快速照相 
http://www.linuxidc.com/Linux/2015-09/122563.htm

1、首先在您的设想机上增多一块新的硬盘用来做尝试。

二、扩容 LV

## 我们把 LV 缩小了 500M