天天看點

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]~]#