1 查看centos设备信息
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 65.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 20G 0 disk └─sdb1 8:17 0 20G 0 part └─centos-root 253:0 0 65.1G 0 lvm / sr0 11:0 1 4.2G 0 rom NAME : 这是块设备名。 MAJ:MIN : 显示主要和次要设备号。 RM : 显示设备是否可移动设备。sr0的RM值等于1,这说明他们是可移动设备。 SIZE : 列出设备的容量大小信息。例如50G表明该设备大小为50G,而1K表明该设备大小为1KB。 RO : 该项表明设备是否为只读。在本案例中,所有设备的RO值为0,表明他们不是只读的。 TYPE :显示块设备是否是磁盘或磁盘上的一个分区。在本例中,sda和sdb是磁盘,而sr0是只读存储(rom)。 MOUNTPOINT : 指出设备挂载的挂载点。
2 虚拟机,扩展根目录,使用lvm
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 46G 3.1G 43G 7% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.0M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 178M 837M 18% /boot tmpfs 380M 8.0K 380M 1% /run/user/42 tmpfs 380M 0 380M 0% /run/user/1000 [root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 45.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom
1 添加多块磁盘(vm上添加2块50g磁盘),扩展根目录
[root@zabbix ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 46G 12G 34G 27% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.1M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 178M 837M 18% /boot tmpfs 380M 8.0K 380M 1% /run/user/42 tmpfs 380M 0 380M 0% /run/user/0 tmpfs 380M 0 380M 0% /run/user/1000 ##lsblk查看新插入硬盘情况,如果未显示新添加的磁盘,需用 echo "- - -" > /sys/class/scsi_host/host0/scan,此命令进行激活,激活后即可查看到新加的磁盘。 [root@zabbix ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 45.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk sdc 8:32 0 50G 0 disk sr0 11:0 1 4.2G 0 rom [root@zabbix ~]# ll /dev/sdb /dev/sdc brw-rw---- 1 root disk 8, 16 Sep 11 09:00 /dev/sdb brw-rw---- 1 root disk 8, 32 Sep 11 09:00 /dev/sdc
[root@zabbix ~]# fdisk /dev/sdb ##选择新增硬盘 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. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xb0001f51. Command (m for help): p ##查看已分区数量 Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb0001f51 Device Boot Start End Blocks Id System 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): 1 ##分区号选1,由于扩容盘所以只只设置一个分区 First sector (2048-104857599, default 2048): ##回车 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): #默认 回车 Using default value 104857599 Partition 1 of type Linux and of size 50 GiB is set Command (m for help): p Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb0001f51 ##增加分区,会发现多了一个分区 Device Boot Start End Blocks Id System /dev/sdb1 2048 104857599 52427776 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 1 WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation. Changed type of partition 'Linux' to 'FAT12' Command (m for help): t ## Selected partition 1 Hex code (type L to list all codes): 8e ##修改分区类型,把linux修改为'Linux LVM' WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation. Changed type of partition 'FAT12' to 'Linux LVM' Command (m for help): p ##再次查看分区情况确认是否修改成功 Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xb0001f51 Device Boot Start End Blocks Id System /dev/sdb1 2048 104857599 52427776 8e Linux LVM ##此次修改成功 Command (m for help): w ##最后写入分区表,保存并退出即可 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
[root@zabbix ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 45.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk └─sdb1 8:17 0 50G 0 part sdc 8:32 0 50G 0 disk └─sdc1 8:33 0 50G 0 part sr0 11:0 1 4.2G 0 rom [root@zabbix ~]# lvm ##进入lvm管理 lvm> pvcreate /dev/sdb1 /dev/sdc1 ##初始化刚才的2个分区 Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created. lvm> vgdisplay ##查看vg的可用空间 --- 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 <49.00 GiB PE Size 4.00 MiB Total PE 12543 Alloc PE / Size 12542 / 48.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID wGqWZa-pMkw-NxWJ-2fTQ-rEvZ-329h-bKIRu2 lvm> vgextend centos /dev/sdb1 /dev/sdc1 ##将初始化过的分区加入到虚拟卷组名 Volume group "centos" successfully extended lvm> lvextend -L +99G /dev/mapper/centos-root ##扩展已有的容量 Size of logical volume centos/root changed from <45.12 GiB (11550 extents) to <144.12 GiB (36894 extents). Logical volume centos/root successfully resized. lvm> pvdisplay ##查看卷容量 --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <49.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12543 Free PE 0 Allocated PE 12543 PV UUID 7AVqYT-3yaz-dL7c-tSgq-hJpZ-csmI-YcXBig --- Physical volume --- PV Name /dev/sdb1 VG Name centos PV Size <50.00 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 12799 Free PE 0 Allocated PE 12799 PV UUID G1R8eV-DvER-Jz1x-1hpk-mOzv-ZdJ7-PZnNim --- Physical volume --- PV Name /dev/sdc1 VG Name centos PV Size <50.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 12799 Free PE 255 Allocated PE 12544 PV UUID wtA8My-5caU-OWUu-2OQO-heuQ-0g8I-RHPLwZ lvm> quit ##退出 Exiting.
##centos6.10
mkfs.ext4 /dev/sdh1 [root@rac02 ~]# cat /etc/fstab |grep VolGroup-lv_home /dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2 ### resize2fs /dev/mapper/VolGroup-lv_home [root@zabbix ~]# cat /etc/fstab |grep centos-root ##查看文件系统格式,如果是xfs,需要用xfs的命令来扩展磁盘 /dev/mapper/centos-root / xfs defaults 0 0 [root@zabbix ~]# xfs_growfs /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=2956800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=11827200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=5775, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 11827200 to 37779456 [root@zabbix ~]# df -h ##根目录扩展成功 Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 145G 12G 133G 9% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 9.1M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 178M 837M 18% /boot tmpfs 380M 12K 380M 1% /run/user/42 tmpfs 380M 0 380M 0% /run/user/0 tmpfs 380M 0 380M 0% /run/user/1000 [root@zabbix ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 49G 0 part ├─centos-root 253:0 0 144.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sdb 8:16 0 50G 0 disk └─sdb1 8:17 0 50G 0 part └─centos-root 253:0 0 144.1G 0 lvm / sdc 8:32 0 50G 0 disk └─sdc1 8:33 0 50G 0 part └─centos-root 253:0 0 144.1G 0 lvm / sr0 11:0 1 4.2G 0 rom [root@zabbix ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 3 2 0 wz--n- <148.99g 1020.00m [root@zabbix ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <144.12g swap centos -wi-ao---- <3.88g [root@localhost ~]# fdisk -l [root@localhost ~]# vgdisplay -v centos