使用脚本快速初始化VMware下Linux虚拟机新增数据盘
1、虚拟机新增磁盘
例如新增60G的数据盘
2、查看主机总线号
代码语言:javascript复制ll /sys/class/scsi_host/
cat /proc/scsi/scsi
3、重新扫描SCSI总线来添加设备
代码语言:javascript复制echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
- echo "- - -" > /sys/class/scsi_host/host0/scan
这个 scan 属性支持以"-"作为通配符,如以下命令可以执行让整个 scsi_host 进行重新搜索, 这个功能用于调试某些对热插拔实现不完善的 SCSI 驱动程序很有用
- host0还是host1,还是host2,取决于 cat /proc/scsi/scsi 之后的 scsi 驱动器的号
4、fdisk -l看到新加的磁盘
5、使用华为云官网帮助文档中脚本对磁盘进行分区、格式化、挂载
该初始化脚本仅适用于划分普通partition分区,做ext4的文件系统。不适用于划分LVM或VG分区
代码语言:javascript复制wget https://ecs-instance-driver.obs.cn-north-1.myhuaweicloud.com/datadisk/LinuxVMDataDiskAutoInitialize.sh
chmod 755 LinuxVMDataDiskAutoInitialize.sh
./LinuxVMDataDiskAutoInitialize.sh
代码语言:javascript复制[root@localhost ~]# ./LinuxVMDataDiskAutoInitialize.sh
Step 1: Initializing script and check root privilege
Is running, please wait!
Success, the script is ready to be installed!
Step 2: Show all active disks:
Disk /dev/sda
Disk /dev/mapper/vg_centos-lv_da
Disk /dev/sdb
Step 3: Please choose the disk(e.g.: /dev/vdb and q to quit):/dev/sdb
Step 4: The disk is partitioning and formatting
Is running, please wait!
Success, the disk has been partitioned and formatted!
Step 5: Make a directory and mount it
Please enter a location to mount (e.g.: /mnt/data):/storage
Success, the mount is completed!
Step 6: Write configuration to /etc/fstab and mount device
Success, the /etc/fstab is Write!
Step 7: Show information about the file system on which each FILE resides
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.2G 17G 12% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 12M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 976M 114M 796M 13% /boot
/dev/mapper/vg_centos-lv_data 63G 33M 63G 1% /data
tmpfs 378M 0 378M 0% /run/user/0
/dev/sdb1 59G 53M 56G 1% /storage
Step 8: Show the write configuration to /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Aug 5 20:31:45 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=3b471a0e-a2cb-4fcd-8b9f-c75a8ebd57ab / ext4 defaults 1 1
UUID=35cba8b6-6304-4559-ba2d-01761d01d532 /boot ext4 defaults 1 2
/dev/mapper/vg_centos-lv_data /data xfs defaults 0 0
UUID=53c2f841-da98-477f-81ef-0f30ecc571e1 swap swap defaults 0 0
/dev/sdb1 /storage ext4 defaults 0 0
可以看到使用脚本已完成分区格式化挂载,以及修改/etc/fstab等一系列操作,简单高效