天天看点

linux添加xfs磁盘,centos7 LV XFS添加磁盘

在centos7环境下实现,原来centos7的磁盘分区是lv+xfs格式。

在linux系统下创建LVM方式的磁盘:在此可以不进行第一步。

1. 磁盘分区(略)

2. 创建物理卷

# pvcreate /dev/sd{b1,c,d,e}(这个地方可以是多个磁盘,或者是多个分区。也可以是单个分区或者是单个磁盘。)

# pvs

3. 创建卷组

# vgcreate volgroup_name /dev/sd{b1,c,d,e}

# vgs

4. 创建逻辑卷

# lvcreate -n log_vol_name -L 10G vlogroup_name

# lvs

5. 格式化逻辑卷

# mkfs.xfs /dev/vlogroup_name/log_vol_name

6. 挂载逻辑卷

# 同挂载本地硬盘同理

现在需要添加一块磁盘来扩展LV的空间。步骤日志如下:

查看原来磁盘格式:

[[email protected]~]# df -hT

Filesystem              Type      Size Used Avail Use% Mounted on

/dev/mapper/centos-rootxfs        18G  947M  17G   6% /

发现新加磁盘名称为/dev/sdb

[[email protected]~]# fdisk -l

分区新磁盘 如果大于2T磁盘使用parted工具

[[email protected]~]# fdisk /dev/sdb

Welcometo fdisk (util-linux 2.23.2).

.

.

.

使用parted工具进行分区

1. 命令行方式(非交互模式):

# parted /dev/sdb mklabel gpt mkpart1xfs1 2T

2. 使用交互模式:

# parted /dev/sdb

....

(parted)    mklabel   gpt

(parted)    mkpart   p1

File system type?  [ext2]?  ext3

Start?  1

End?   5T

(parted)    print

Number  Start     End   Size  File system  Name  Flags

1        32.3kB  5TB   5TB      ext3       p1

[[email protected]~]# fdisk-l

(略)

.

.

.

查看原来lv状态

[[email protected]~]# vgdisplay

--- Volume group ---

VG Name               centos

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

VG Size               19.51 GiB

PE Size               4.00 MiB

Total PE              4994

Alloc PE / Size       4984 / 19.47 GiB

Free  PE / Size       10 / 40.00 MiB

VG UUID              EDjB3T-qhXo-Mmml-rN8w-bPYk-AdL6-Cf0Y6u

创建物理卷

[[email protected]~]# pvcreate /dev/sdb1

Physical volume "/dev/sdb1"successfully created

将新的物理卷加入卷组中

[[email protected]~]# vgextend centos /dev/sdb1

Volume group "centos" successfullyextended

查看新加入物理卷后的卷组状态

[[email protected]~]# vgdisplay

--- Volume group ---

VG Name              centos

System ID

Format                lvm2

Metadata Areas        2

Metadata Sequence No  4

VG Access             read/write

VG Status             resizable

MAX LV                0

Cur LV                2

Open LV               2

Max PV                0

Cur PV                2

Act PV                2

VG Size               59.50 GiB

PE Size               4.00 MiB

Total PE              15233

Alloc PE / Size       4984 / 19.47 GiB

Free  PE / Size       10249 / 40.04 GiB

VG UUID              EDjB3T-qhXo-Mmml-rN8w-bPYk-AdL6-Cf0Y6u

[[email protected]~]# df -h

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/centos-root  18G  946M   17G  6% /

devtmpfs                 1.9G     0 1.9G   0% /dev

tmpfs                    1.9G     0 1.9G   0% /dev/shm

tmpfs                    1.9G  8.5M 1.9G   1% /run

tmpfs                    1.9G     0 1.9G   0% /sys/fs/cgroup

/dev/sda1                497M  120M 378M  25% /boot

查看增加逻辑卷容量命令lvextend的用法

[[email protected]~]# lvextend --help

lvextend: Add space to a logical volume

lvextend

[-A|--autobackup y|n]

[--alloc AllocationPolicy]

[--commandprofile ProfileName]

[-d|--debug]

[-f|--force]

[-h|--help]

[-i|--stripes Stripes [-I|--stripesizeStripeSize]]

{-l|--extents[+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] |

-L|--size[+]LogicalVolumeSize[bBsSkKmMgGtTpPeE]}

--poolmetadatasize[+]MetadataVolumeSize[bBsSkKmMgG]}

[-m|--mirrors Mirrors]

[--nosync]

[--use-policies]

[-n|--nofsck]

[--noudevsync]

[-r|--resizefs]

[-t|--test]

[--type VolumeType]

[-v|--verbose]

[--version]

LogicalVolume[Path] [PhysicalVolumePath... ]

把整个剩余容量都添加到逻辑卷中

[[email protected] ~]#lvextend -l+10249 /dev/centos/root

Size of logicalvolume centos/root changed from 17.47 GiB (4472 extents) to 57.50 GiB (14721extents).

Logical volume root successfully resized

这个地方需要说明一下,如果磁盘格式是XFS文件系统,则使用xfs_growfs命令,如果磁盘是ext格式则需要使用resize2fs命令

修改xfs文件系统容量

[[email protected] ~]# xfs_growfs /dev/mapper/centos-root

meta-data=/dev/mapper/centos-rootisize=256    agcount=4, agsize=1144832blks

=                       sectsz=512   attr=2, projid32bit=1

=                       crc=0        finobt=0

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

=                       sunit=0      swidth=0 blks

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

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

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

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

datablocks changed from 4579328 to 15074304

查看扩容后的逻辑卷大小

[[email protected]~]# df -hT

Filesystem              Type      Size Used Avail Use% Mounted on

/dev/mapper/centos-root xfs        58G 946M   57G   2% /

devtmpfs                devtmpfs  1.9G     0 1.9G   0% /dev

tmpfs                   tmpfs     1.9G    0  1.9G   0% /dev/shm

tmpfs                   tmpfs     1.9G 8.5M  1.9G   1% /run

tmpfs                   tmpfs     1.9G    0  1.9G   0% /sys/fs/cgroup

/dev/sda1               xfs       497M 120M  378M  25% /boot

[[email protected]~]#