欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

linux新建立LVM磁盘卷流程说明

程序员文章站 2022-04-26 15:20:04
[root@RAC1 ~]# fdisk -l Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track,...

[root@RAC1 ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 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: 0x000c9810

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 64 10444 83373056 8e Linux LVM ----sdba已经有逻辑编号了

Disk /dev/sdb: 17.2 GB, 17179869184 bytes ----可以看出sdb还未分配逻辑编号

255 heads, 63 sectors/track, 2088 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

Disk /dev/mapper/vg_rac1-lv_root: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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

Disk /dev/mapper/vg_rac1-lv_swap: 4227 MB, 4227858432 bytes

255 heads, 63 sectors/track, 514 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

Disk /dev/mapper/vg_rac1-lv_home: 27.5 GB, 27455913984 bytes

255 heads, 63 sectors/track, 3337 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

[root@RAC1 ~]# fdisk /dev/sdb ---对sdb磁盘进行逻辑分区

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x726b3678.

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-2088, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):

Using default value 2088

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): w

The partition table has been altered!

Clling ioctl() to re-read partition table.

Syncing disks.

[root@RAC1 ~]# mkfs -t ext4 -c /dev/sdb1 ----将sdb1格式化ext4磁盘格式

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1048576 inodes, 4192957 blocks

209647 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=4294967296

128 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

Checking for bad blocks (read-only test): 完成

正在写入inode表: 完成

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 26 mounts or

180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@RAC1 ~]# pvdisplay ----查询PV逻辑块

--- Physical volume ---

PV Name /dev/sda2

VG Name vg_rac1

PV Size 79.51 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 20354

Free PE 0

Allocated PE 20354

PV UUID YpRRUv-QZFd-OCUm-Qpe6-CbOc-qJ6j-sj6nMP

[root@RAC1 ~]# pvcreate /dev/sdb1 ----将sdb1创建位PV逻辑快

Physical volume "/dev/sdb1" successfully created

[root@RAC1 ~]# pvdisplay

--- Physical volume ---

PV Name /dev/sda2

VG Name vg_rac1

PV Size 79.51 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 20354

Free PE 0

Allocated PE 20354

PV UUID YpRRUv-QZFd-OCUm-Qpe6-CbOc-qJ6j-sj6nMP

"/dev/sdb1" is a new physical volume of "15.99 GiB"

--- NEW Physical volume ---

PV Name /dev/sdb1

VG Name

PV Size 15.99 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID TRZ31M-3pVV-1uhx-Wz5L-zF0O-fz3D-tH5tjg

[root@RAC1 ~]#

[root@RAC1 ~]# vgcreate data_vg /dev/sdb1 ----创建vg磁盘组名字为data_vg

Volume group "data_vg" successfully created

[root@RAC1 ~]# vgdisplay

--- Volume group ---

VG Name data_vg

System ID

Format lvm2

Metadata Areas 1

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 1

Act PV 1

VG Size 15.99 GiB

PE Size 4.00 MiB

Total PE 4094

Alloc PE / Size 0 / 0

Free PE / Size 4094 / 15.99 GiB

VG UUID cBX1rU-PrU4-dJAy-Pqi2-pX6e-tlHo-19HSwZ

--- Volume group ---

VG Name vg_rac1

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 4

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 3

Open LV 3

Max PV 0

Cur PV 1

Act PV 1

VG Size 79.51 GiB

PE Size 4.00 MiB

Total PE 20354

Alloc PE / Size 20354 / 79.51 GiB

Free PE / Size 0 / 0

VG UUID 3STo0z-xIfp-rHDO-O4tp-BTW2-B4Qj-uJkvNm

[root@RAC1 ~]# pvdisplay -----查看pv逻辑块信息

--- Physical volume ---

PV Name /dev/sdb1

VG Name data_vg

PV Size 15.99 GiB / not usable 2.74 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 4094

Free PE 4094

Allocated PE 0

PV UUID TRZ31M-3pVV-1uhx-Wz5L-zF0O-fz3D-tH5tjg

--- Physical volume ---

PV Name /dev/sda2

VG Name vg_rac1

PV Size 79.51 GiB / not usable 3.00 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 20354

Free PE 0

Allocated PE 20354

PV UUID YpRRUv-QZFd-OCUm-Qpe6-CbOc-qJ6j-sj6nMP

[root@RAC1 ~]#

[root@RAC1 ~]#

[root@RAC1 ~]# vgextend data_vg /dev/sdb1 -----将sdb1的PV磁盘块添加到vg磁盘组

Physical volume '/dev/sdb1' is already in volume group 'data_vg'

Unable to add physical volume '/dev/sdb1' to volume group 'data_vg'.

[root@RAC1 ~]# vgdisplay ---查看已有的vg磁盘组

--- Volume group ---

VG Name data_vg

System ID

Format lvm2

Metadata Areas 1

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 1

Act PV 1

VG Size 15.99 GiB

PE Size 4.00 MiB

Total PE 4094

Alloc PE / Size 0 / 0

Free PE / Size 4094 / 15.99 GiB

VG UUID cBX1rU-PrU4-dJAy-Pqi2-pX6e-tlHo-19HSwZ

--- Volume group ---

VG Name vg_rac1

System ID

Format lvm2

Metadata Areas 1

Metadata Sequence No 4

VG Access read/write

VG Status resizable

MAX LV 0

Cur LV 3

Open LV 3

Max PV 0

Cur PV 1

Act PV 1

VG Size 79.51 GiB

PE Size 4.00 MiB

Total PE 20354

Alloc PE / Size 20354 / 79.51 GiB

Free PE / Size 0 / 0

VG UUID 3STo0z-xIfp-rHDO-O4tp-BTW2-B4Qj-uJkvNm

[root@RAC1 ~]#

[root@RAC1 ~]# lvdisplay

--- Logical volume ---

LV Path /dev/vg_rac1/lv_root

LV Name lv_root

VG Name vg_rac1

LV UUID 6UVdUJ-x7fB-6C40-KhKb-zluq-1Zjc-OAl12C

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:50 +0800

LV Status available

# open 1

LV Size 50.00 GiB

Current LE 12800

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

--- Logical volume ---

LV Path /dev/vg_rac1/lv_home

LV Name lv_home

VG Name vg_rac1

LV UUID uABSyv-iebN-DMNy-XVfe-IfYR-DjwY-a9en2z

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:54 +0800

LV Status available

# open 1

LV Size 25.57 GiB

Current LE 6546

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:2

--- Logical volume ---

LV Path /dev/vg_rac1/lv_swap

LV Name lv_swap

VG Name vg_rac1

LV UUID tgC9L1-ZFcp-e1kz-rclV-vlkV-ui9l-NjGroT

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:56 +0800

LV Status available

# open 1

LV Size 3.94 GiB

Current LE 1008

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

[root@RAC1 ~]# lvcreate -n share -L 10G data_vg -----从vg磁盘组划出空间

Logical volume "share" created

[root@RAC1 ~]# lvdisplay ----查看已有的lv分区

--- Logical volume ---

LV Path /dev/data_vg/share

LV Name share

VG Name data_vg

LV UUID ovum77-AgIo-8pFt-p8xp-E9XV-VTW3-9IjPfT

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-20 14:53:28 +0800

LV Status available

# open 0

LV Size 10.00 GiB

Current LE 2560

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:3

--- Logical volume ---

LV Path /dev/vg_rac1/lv_root

LV Name lv_root

VG Name vg_rac1

LV UUID 6UVdUJ-x7fB-6C40-KhKb-zluq-1Zjc-OAl12C

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:50 +0800

LV Status available

# open 1

LV Size 50.00 GiB

Current LE 12800

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:0

--- Logical volume ---

LV Path /dev/vg_rac1/lv_home

LV Name lv_home

VG Name vg_rac1

LV UUID uABSyv-iebN-DMNy-XVfe-IfYR-DjwY-a9en2z

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:54 +0800

LV Status available

# open 1

LV Size 25.57 GiB

Current LE 6546

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:2

--- Logical volume ---

LV Path /dev/vg_rac1/lv_swap

LV Name lv_swap

VG Name vg_rac1

LV UUID tgC9L1-ZFcp-e1kz-rclV-vlkV-ui9l-NjGroT

LV Write Access read/write

LV Creation host, time RAC1, 2017-02-07 09:09:56 +0800

LV Status available

# open 1

LV Size 3.94 GiB

Current LE 1008

Segments 1

Allocation inherit

Read ahead sectors auto

- currently set to 256

Block device 253:1

[root@RAC1 ~]#

[root@RAC1 ~]# lvs -----查看lv逻辑分区信息

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

share data_vg -wi-a----- 10.00g

lv_home vg_rac1 -wi-ao---- 25.57g

lv_root vg_rac1 -wi-ao---- 50.00g

lv_swap vg_rac1 -wi-ao---- 3.94g

[root@RAC1 ~]# pvs -------查看pv逻辑块信息

PV VG Fmt Attr PSize PFree

/dev/sda2 vg_rac1 lvm2 a-- 79.51g 0

/dev/sdb1 data_vg lvm2 a-- 15.99g 5.99g

[root@RAC1 ~]# vgs ----查看vg磁盘组信息

VG #PV #LV #SN Attr VSize VFree

data_vg 1 1 0 wz--n- 15.99g 5.99g

vg_rac1 1 3 0 wz--n- 79.51g 0

[root@RAC1 ~]#

[root@RAC1 /]# mkfs.ext4 /dev/data_vg/share -----将磁盘格式化为系统所支持的文件类型

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 2621440 blocks

131072 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=2684354560

80 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

正在写入inode表: 完成

Creating journal (32768 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.

[root@RAC1 /]# mount /dev/data_vg/share /bbsoft/ -----挂载到新的目录

[root@RAC1 /]# df -lh

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_rac1-lv_root 50G 4.7G 43G 11% /

tmpfs 1.9G 80K 1.9G 1% /dev/shm

/dev/sda1 485M 39M 421M 9% /boot

/dev/mapper/vg_rac1-lv_home 26G 5.0G 19G 21% /home

/dev/mapper/data_vg-share 9.9G 151M 9.2G 2% /bbsoft

[root@RAC1 /]#

[root@RAC1 ~]# vim /etc/fstab ----新增的磁盘空间,要将其修改为系统启动时自动挂载。

#

# /etc/fstab

# Created by anaconda on Tue Feb 7 09:10:36 2017

#

# 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_rac1-lv_root / ext4 defaults 1 1

UUID=cf8b8b95-229f-4817-b4c4-0c78b5af93fd /boot ext4 defaults 1 2

/dev/mapper/vg_rac1-lv_home /home ext4 defaults 1 2

/dev/mapper/vg_rac1-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

/dev/mapper/data_vg-share /bbsoft ext4 defaults 0 0

磁盘所在位置 挂载的目录 磁盘格式

~

~

"/etc/fstab" 20L, 926C 已写入

[root@RAC1 ~]# reboot -f

[root@RAC1 ~]# blkid -o value -s UUID /dev/sdb1 -----查看sdb1 的UUID多少

TRZ31M-3pVV-1uhx-Wz5L-zF0O-fz3D-tH5tjg

[root@RAC1 ~]#