Linux系统/data目录扩容
[root@fdfs-ds01 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/rootvg-lv01 39G 8.1G 29G 23% /tmpfs 7.8G 12K 7.8G 1% /dev/shm/dev/sda1 194M 34M 150M 19% /boot/dev/mapper/datavg-lv02 2.0T 1.7T 182G 91% /data <==给data目录扩展2TB容量一. 从VMware虚拟机添加一块2TB的硬盘到服务器

二. ESXi 不关机识别刚刚新添加的scsi硬盘下面看一下在系统不重启的情况,如何让系统认识新的磁盘,并能对其分区与格式化
1、在开机状态下新增磁盘
2、执行下面的命令
[root@fdfs-ds01 ~]# echo "- - -" > /sys/class/scsi_host/host0/scan[root@fdfs-ds01 ~]# echo "- - -" > /sys/class/scsi_host/host1/scan[root@fdfs-ds01 ~]# echo "- - -" > /sys/class/scsi_host/host2/scan特别注意
① “- – -” 这三个-之间是有空格的
② 假如 fdisk -l 还是未发现新硬盘,则将上面命令中的host0,替换为host1,host2,....看看
我们再查看系统日志/var/log/messages,发现对SCSI设备进行了一次重新扫描,用fdisk -l也看到了新增加的磁盘了。上面的命令主要的目的就是scan the SCSI bus。
[root@fdfs-ds01 ~]# fdisk -l | grep DDisk /dev/sda: 42.9 GB, 42949672960 bytesDisk identifier: 0x0002f8b7 Device Boot Start End Blocks Id SystemDisk /dev/sdb: 2199.0 GB, 2199023255552 bytesDisk identifier: 0xc1f030ee Device Boot Start End Blocks Id SystemDisk /dev/mapper/rootvg-lv01: 41.6 GB, 41641050112 bytesDisk identifier: 0x00000000Disk /dev/mapper/datavg-lv02: 2146.4 GB, 2146409906176 bytesDisk identifier: 0x00000000Disk /dev/sdc: 2199.0 GB, 2199023255552 bytes <==看到硬盘被成功识别出来了Disk identifier: 0x00000000
三. 格式化新添加的硬盘[root@fdfs-ds01 ~]# fdisk /dev/sdcDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x07d85a0a.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).DOS partition table format can not be used on drives for volumeslarger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUIDpartition table format (GPT). WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n <==命令 n 用于添加新分区Command action e extended p primary partition (1-4)p <==择创建主分区Partition number (1-4): 1 <==主分区的编号First cylinder (1-267349, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349):Using default value 267349 Command (m for help): w <==保存所有配置并退出The partition table has been altered! Calling ioctl() to re-read partition table.Syncing disks.
[root@fdfs-ds01 data]# mkfs -t ext4 /dev/sdc1
四. 扩充根分区接着,使用vgextend 命令加到lvm组里面去,做如下操作:[root@fdfs-ds01 data]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv02 datavg -wi-ao---- 1.95t lv01 rootvg -wi-ao---- 38.78g
[root@fdfs-ds01 data]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created
[root@fdfs-ds01 data]# vgextend datavg /dev/sdc1 Volume group "datavg" successfully extended
[root@fdfs-ds01 data]# vgdisplay --- Volume group --- VG Name datavg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 2 Act PV 2 VG Size 4.00 TiB <==VG组容量已经从2TB增加到4TB PE Size 4.00 MiB Total PE 1048574 Alloc PE / Size 511744 / 1.95 TiB Free PE / Size 536830 / 2.05 TiB <==主要查看Free PE / Size,说明我们最多可以有2.05TB的扩充空间 VG UUID Z7H7Wd-O7hT-69tE-7iq2-TXNi-0xIO-nCqoIk --- Volume group --- VG Name rootvg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 1 Max PV 0 Cur PV 1 Act PV 1 VG Size 38.78 GiB PE Size 32.00 MiB Total PE 1241 Alloc PE / Size 1241 / 38.78 GiB Free PE / Size 0 / 0 VG UUID Hnif90-DJXc-elxC-Hn1H-aQfn-Ysvb-iDCJrF
最后,给/data目录增加空间[root@fdfs-ds01 data]# lvextend -L +1.98T /dev/mapper/datavg-lv02 /dev/sdc1 Rounding size to boundary between physical extents: 1.98 TiB Extending logical volume lv02 to 3.93 TiB Logical volume lv02 successfully resized
使用 resize2fs 命令刷新 /dev/mapper/datavg-lv02 文件系统大小[root@fdfs-ds01 data]# resize2fs /dev/mapper/datavg-lv02resize2fs 1.41.12 (17-May-2010)Filesystem at /dev/mapper/datavg-lv02 is mounted on /data; on-line resizing requiredold desc_blocks = 125, new_desc_blocks = 252Performing an on-line resize of /dev/mapper/datavg-lv02 to 1055528960 (4k) blocks.The filesystem on /dev/mapper/datavg-lv02 is now 1055528960 blocks long.
[root@fdfs-ds01 data]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/rootvg-lv01 39G 8.1G 29G 23% /tmpfs 7.8G 12K 7.8G 1% /dev/shm/dev/sda1 194M 34M 150M 19% /boot/dev/mapper/datavg-lv02 3.9T 1.7T 2.1T 45% /data <==给/data目录扩展2TB容量完成