一、挂载
1)新增数据盘执行分区
[root@monitor ~]# lsblk |grep vdb
vdb 252:16 0 100G 0 disk
[root@monitor ~]# fdisk /dev/vdb
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048): 回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 回车
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set
#修改/dev/vdb分区编码为LVM
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): l
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 8e #选择lvm
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w #保存
2)创建pv
#刷新硬盘分区状态
[root@monitor ~]# partprobe
[root@monitor ~]# lsblk |grep vdb
vdb 252:16 0 100G 0 disk
└─vdb1 252:17 0 100G 0 part
#创建pv
[root@monitor ~]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
#查看pv,还可以使用命令pvs 和pvscan查看简略信息。
[root@monitor ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID SS5nij-dqhR-iDc3-Sc0U-lgBs-B3d7-r5vmwI
"/dev/vdb1" is a new physical volume of "<100.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vdb1
VG Name
PV Size <100.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID b4c5yl-Kale-yMaa-E1Hl-ydkk-BmOb-x15zr5
3)格式化
#格式化为xfs格式
[root@monitor ~]# mkfs.xfs -f /dev/vdb1
meta-data=/dev/vdb1 isize=512 agcount=4, agsize=6553536 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=26214144, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=12799, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
4)挂载
#创建data数据目录
[root@monitor ~]# mkdir /data
#挂载100G到data目录
[root@monitor ~]#mount /dev/vdb1 /data
#使用命令df -Th查看磁盘挂载情况
[root@monitor ~]# lsblk |grep /data
└─vdb1 252:17 0 100G 0 part /data
5)开机自动挂载
- 挂载好的磁盘需要设置开机自动挂载,我们不采用/etc/fstab直接指定 /dev/xvde1的方法,而推荐使用UUID来配置自动挂载数据盘。
#先执行命令blkid /dev/vdb1,查询磁盘分区的UUID
[root@monitor ~]# blkid /dev/vdb1
/dev/vdb1: UUID="4a03afed-cbce-4fa6-8ad5-bc0d70f8fc2a" TYPE="xfs"
#编辑/etc/fstab,在末尾增加一行
UUID=4a03afed-cbce-4fa6-8ad5-bc0d70f8fc2a /data xfs defaults 0 0
6)检测自启动挂载
#取消挂载
[root@monitor ~]# umount /dev/vdb1
[root@monitor ~]# lsblk |grep vdb1
└─vdb1 252:17 0 100G 0 part
#检查能否自动挂载,执行mount -a确认是否自动挂上了data数据目录
[root@monitor ~]# mount -a
#自动挂载成功则无问题。
[root@monitor ~]# lsblk |grep vdb1
└─vdb1 252:17 0 100G 0 part /data
#重启测试(注意不要生产测试)
[root@monitor ~]# reboot
[root@monitor ~]# lsblk |grep data
└─vdb1 252:17 0 100G 0 part /data
【六项详解】:
LABEL=/ / ext3 defaults 1 1
/dev/sda2 /mnt/D/ vfat defaults 0 0
第一列:设备名或者设备卷标名,(/dev/sda10 或者 LABEL=/)
第二列:设备挂载目录 (例如上面的“/”或者“/mnt/D/”)
第三列:设备文件系统 (例如上面的“ext3”或者“vfat”)
第四列:挂载参数 (看帮助man mount)
对于已经挂载好的设备,例如上面的/dev/sda2,现在要改变挂载参数,这时可以不用卸载该设备,而可以使用下面的命令(没有挂载的设备,remount 这个参数无效)
#mount /mnt/D/ -o remount,ro (改defaults为ro)
为了安全起见,可以指明其他挂载参数,例如:
noexec(不允许可执行文件可执行,但千万不要把根分区挂为noexec,那就无法使用系统了,连mount 命令都无法使用了,这时只有重新做系统了!
nodev(不允许挂载设备文件)nosuid,nosgid(不允许有suid和sgid属性)
nouser(不允许普通用户挂载)
第五列:指明是否要备份,(0为不备份,1为要备份,一般根分区要备份)
第六列:指明自检顺序。 (0为不自检,1或者2为要自检,如果是根分区要设为1,其他分区只能是2,如不要检查就为0)
二、扩容
1)查看容量
- 发现50G只使用了40G
#一共50G,发现只用了10G
[root@monitor opt]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
└─vda2 252:2 0 9G 0 part
├─centos-root 253:0 0 8G 0 lvm /
└─centos-swap 253:1 0 1G 0 lvm [SWAP]
2)新增分区盘
[root@monitor opt]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): #回车
First sector (20971520-104857599, default 20971520):
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-104857599, default 104857599): #回车
Using default value 104857599
Partition 3 of type Linux and of size 40 GiB is set
Command (m for help): t
Partition number (1-3, default 3): 3 #选择需要指定分区3
Hex code (type L to list all codes): 8e #指定分区类型为lvm
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
3)创建pv
#刷新硬盘分区状态
[root@monitor opt]# partprobe
[root@monitor opt]# lsblk |grep vda3
└─vda3 252:3 0 40G 0 part
#针对vda3建立物理卷
[root@monitor opt]# pvcreate /dev/vda3
Physical volume "/dev/vda3" successfully created.
#查看现在物理卷情况
[root@monitor opt]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size <9.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 2303
Free PE 0
Allocated PE 2303
PV UUID SS5nij-dqhR-iDc3-Sc0U-lgBs-B3d7-r5vmwI
"/dev/vda3" is a new physical volume of "40.00 GiB"
--- NEW Physical volume ---
PV Name /dev/vda3
VG Name
PV Size 40.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID TVkOre-DkIe-EYIO-cAI0-LYXp-5upo-q5k7yG
4)创建VG
#添加vda3到现在的卷组中
[root@monitor opt]# vgextend centos /dev/vda3
Volume group "centos" successfully extended
#查看卷组的情况
[root@monitor opt]# vgdisplay
--- Volume group ---
VG Name centos
...
VG Size 48.99 GiB
PE Size 4.00 MiB
Total PE 12542
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 10239 / <40.00 GiB
VG UUID mJVwQI-WcjV-WHaB-oAnn-RsUB-HSUe-y8Zcyl
5)扩展到目标盘
#扩展lv的容量
[root@monitor ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 2 0 wz--n- 48.99g <40.00g
#全部扩到/目录下面
[root@monitor ~]# lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 47.99 GiB (12286 extents).
Logical volume centos/root successfully resized.
- /dev/centos/root #查看vg和pv的名称指定路径。
6)对文件系统更新
#激活
[root@monitor ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=524032 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2096128, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2096128 to 12580864
#查看
[root@monitor opt]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
├─vda2 252:2 0 9G 0 part
│ ├─centos-root 253:0 0 48G 0 lvm /
│ └─centos-swap 253:1 0 1G 0 lvm [SWAP]
└─vda3 252:3 0 40G 0 part
└─centos-root 253:0 0 48G 0 lvm /
vdb 252:16 0 100G 0 disk
└─vdb1 252:17 0 100G 0 part /data
- 由最初8G增加到了48G