1

分区格式化

查看分区信息

fdisk -l
如果提示命令找不到:sudo: command not found, 可以尝试使用/sbin/fdisk -l

[root@www application]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sda: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
Disk identifier: B408EEC8-6FC3-4F9B-B726-EB390EF3469D


#         Start          End    Size  Type            Name
 1         2048         4095      1M  BIOS boot       
 2         4096      2101247      1G  Microsoft basic 
 3      2101248  11721043967    5.5T  Linux LVM       
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdc: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: gpt
Disk identifier: 44D5CA56-C9DA-437F-916D-F043BD79B458


#         Start          End    Size  Type            Name

Disk /dev/sdb: 6001.2 GB, 6001175126016 bytes, 11721045168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/vg-root: 5986.3 GB, 5986332966912 bytes, 11692056576 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/vg-swap: 12.7 GB, 12683575296 bytes, 24772608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes


Disk /dev/mapper/vg-tmp: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

查看已分区信息

[root@www application]# df -H
Filesystem           Size  Used Avail Use% Mounted on
devtmpfs              13G     0   13G   0% /dev
tmpfs                 13G     0   13G   0% /dev/shm
tmpfs                 13G  9.4M   13G   1% /run
tmpfs                 13G     0   13G   0% /sys/fs/cgroup
/dev/mapper/vg-root  6.0T  1.6G  5.7T   1% /    
/dev/sda2            1.1G  125M  880M  13% /boot
/dev/mapper/vg-tmp   1.1G  2.7M  951M   1% /tmp
tmpfs    

格式化分区

# 格式化为xfs格式
mkfs.xfs  /dev/sdb

如果格式化成ext4模式, 执行以下命令

# 格式化为ext4格式
mkfs -t ext4 /dev/sdb

挂载分区

挂载分区

mount /dev/sdb  /home/sdb

开机自动挂载

  1. 查询分区UUID
    lsblk -f

    [root@iZ6wej8ckbd9pfqzwittlqZ ~]# lsblk -f
    NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
    vda                                                      
    └─vda1 ext4         4f4de78b-e926-4e41-9ab6-0643a8eed46f /
    vdb    xfs          b15e3c40-a8d5-447d-a645-5a1cfbcd340a /disk2
  2. 添加分区信息
    vim /etc/fstab

    /* 添加如下信息  */
    b15e3c40-a8d5-447d-a645-5a1cfbcd340a /disk2  xfs defaults        0 0

添加分区到卷组

分区除了挂载到指定目录外, 还可以添加到卷组, 这样可以将不同分区挂载到同一目录
pv、vg、lv的意思
image.png

物理卷(Physical Volume,PV):就是指硬盘分区,也可以是整个硬盘或已创建的软RAID,是LVM的基本存储设备。

卷组(Volume Group,VG):是由一个或多个物理卷所组成的存储池,在卷组上能创建一个或多个逻辑卷。

逻辑卷(Logical Volume,LV):类似于非LVM系统中的硬盘分区,它建立在卷组之上,是一个标准的块设备,在逻辑卷之上可以建立文件系统。

1. 创建PV(Physical Volume)

pvcreate /dev/sdb

[root@www application]# pvcreate /dev/sdb
WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb.
  Physical volume "/dev/sdb" successfully created.

2. 把PV加入VG(Volume Group)中

相当于扩充VG的大小,

  1. 使用vgs查看vg组:

    [root@www application]# vgs
      VG #PV #LV #SN Attr   VSize  VFree
      vg   1   3   0 wz--n- <5.46t 4.00m

可以看到有一个名称为"vg"的卷组, PV物理卷1个, LV逻辑卷3个, 可用空间5.46T
pvs查看这1个物理卷

[root@www application]# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/sda3  vg lvm2 a--  <5.46t  4.00m
  /dev/sdb      lvm2 ---  <5.46t <5.46t

可以发现已经加入卷组的/dev/sda3物理卷, 未加入卷组的/dev/sdb物理卷

lvs查看这3个逻辑卷:

[root@www application]# lvs
  LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root vg -wi-ao----  5.44t                                                    
  swap vg -wi-ao---- 11.81g                                                    
  tmp  vg -wi-ao----  1.00g
  1. 将/dev/sdb加入VG
    vgextend vg(卷组名称) /dev/sdb(PV,物理卷)

    [root@www application]# vgextend vg /dev/sdb
      Volume group "vg" successfully extended
    
    
    # 删除PV卷可以用命令
    # vgreduce vg /dev/sdc

    查看vgs、lvs、pvs的变化

    [root@www application]# vgs
      VG #PV #LV #SN Attr   VSize   VFree 
      vg   2   3   0 wz--n- <10.92t <5.46t   /* sdb的容量添加进来的 */
    [root@www application]# lvs
      LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root vg -wi-ao----  5.44t                                                    
      swap vg -wi-ao---- 11.81g                                                    
      tmp  vg -wi-ao----  1.00g                                                    
    [root@www application]# pvs
      PV         VG Fmt  Attr PSize  PFree 
      /dev/sda3  vg lvm2 a--  <5.46t  4.00m
      /dev/sdb   vg lvm2 a--  <5.46t <5.46t   /* 成功加入了vg */

    除了lvs, vgs、pvs都有sdb加入后的变化

  2. LV(Logicl Volume)扩容
    将sdb的容量添加到LV中

    lvextend -l +100%FREE /dev/mapper/vg-root
    # 扩展全部空间到lv中去,后面的/dev/mapper/vg-root是指定扩展的文件位置,可在df -hT中看见
    
    
    # 也可以加指定容量
    # lvextend -L +20G /dev/mapper/centos-root
    
    # 减少容量:
    # lvreduce -L -3G /dev/mapper/vg-root

    再查看lvs, 容量已经增加了

    [root@www application]# lvs
      LV   VG Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root vg -wi-ao---- 10.90t      # 增加了sdb的容量                                   
      swap vg -wi-ao---- 11.81g                                                    
      tmp  vg -wi-ao----  1.00g 
  3. 重新读取VG大小
    此时查看df -hT

    [root@www application]# df -hT
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs              13G     0   13G   0% /dev
    tmpfs                 13G     0   13G   0% /dev/shm
    tmpfs                 13G  9.4M   13G   1% /run
    tmpfs                 13G     0   13G   0% /sys/fs/cgroup
    /dev/mapper/vg-root  6.0T  1.6G  5.7T   1% /     # 没有增加sdb的容量
    /dev/sda2            1.1G  125M  880M  13% /boot
    /dev/mapper/vg-tmp   1.1G  2.7M  951M   1% /tmp
    tmpfs                2.6G     0  2.6G   0% /run/user/0

    如果是ext文件系统, 使用 resize2fs /dev/mapper/vg-root 命令
    如果是xfs文件系统, 使用 xfs_growfs /dev/mapper/vg-root 命令

    [root@www application]# resize2fs /dev/mapper/vg-root
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/mapper/vg-root is mounted on /; on-line resizing required
    old_desc_blocks = 697, new_desc_blocks = 1396
    The filesystem on /dev/mapper/vg-root is now 2926638080 blocks long.

再次用df -hT查看已分区信息

[root@www application]# df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs   12G     0   12G   0% /dev
tmpfs               tmpfs      12G     0   12G   0% /dev/shm
tmpfs               tmpfs      12G  9.0M   12G   1% /run
tmpfs               tmpfs      12G     0   12G   0% /sys/fs/cgroup
/dev/mapper/vg-root ext4       11T  1.4G   11T   1% /    # sdb的容量已经添加进来了
/dev/sda2           ext2     1008M  119M  839M  13% /boot
/dev/mapper/vg-tmp  ext4      976M  2.6M  907M   1% /tmp
tmpfs               tmpfs     2.4G     0  2.4G   0% /run/user/0


YYGP
25 声望11 粉丝

写BUG


引用和评论

0 条评论