首页 > 代码库 > VMware Linux Guest 增加磁盘无需重启的方法
VMware Linux Guest 增加磁盘无需重启的方法
摘要
常常需要需要给VMware Linux Guest增加磁盘适配一些测试场景,而又不想花费时间重启Guest,查找文档,发现一种简单的方法,记录一下操作步骤。
操作步骤
1 编辑Linux Guest配置,增加磁盘
下一步,直到完成所有的创建步骤。
2 扫描SCSI Bus,添加SCSI设备
为了验证效果,先看看当前的磁盘设备,很明显,没有扫描到刚添加的磁盘。
[root@BendSha_RHEL5_5_x64 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 2353 18595237+ 83 Linux
/dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
查看scsi_host信息
[root@BendSha_RHEL5_5_x64 /]# ls /sys/class/scsi_host
host0 host11 host14 host17 host2 host22 host25 host28 host30 host6 host9
host1 host12 host15 host18 host20 host23 host26 host29 host4 host7
host10 host13 host16 host19 host21 host24 host27 host3 host5 host8
我们添加的磁盘是在host0,扫描host0
[root@BendSha_RHEL5_5_x64 /]# echo "- - -" > /sys/class/scsi_host/host0/scan
[root@BendSha_RHEL5_5_x64 /]#
查看/proc/scsi/scsi信息,应该多了一个Id等于2的SCSI设备
[root@BendSha_RHEL5_5_x64 /]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
fdisk查看磁盘设备,扫描到了 /dev/sdc
[root@BendSha_RHEL5_5_x64 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 2353 18595237+ 83 Linux
/dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn‘t contain a valid partition table
3 格式化并创建挂载点
[root@BendSha_RHEL5_5_x64 /]# mkfs.ext4 /dev/sdc
mke4fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
......
[root@BendSha_RHEL5_5_x64 /]# mkdir /data
[root@BendSha_RHEL5_5_x64 /]# mount /dev/sdc /data/
[root@BendSha_RHEL5_5_x64 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 11G 5.5G 67% /
/dev/sda1 289M 30M 245M 11% /boot
tmpfs 941M 0 941M 0% /dev/shm
/dev/sdb1 9.9G 220M 9.2G 3% /logvol
/dev/sdc 20G 172M 19G 1% /data
拓展
这里顺便提一下,如果需要添加一个指定设备名的设备,可以参照下面的语法:
echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
其中:
<H> : Host
<B> : Bus (Channel)
<T> : Target (Id)
<L> : LUN numbers
测试一下,我们先把之前的/dev/sdc删除,执行echo 1 > /sys/block/devname/device/delete,可根据设备名删除指定设备:
[root@BendSha_RHEL5_5_x64 /]# ls /sys/block/
fd0 ram0 ram10 ram12 ram14 ram2 ram4 ram6 ram8 sda sdc
md0 ram1 ram11 ram13 ram15 ram3 ram5 ram7 ram9 sdb sr0
[root@BendSha_RHEL5_5_x64 /]# echo 1 > /sys/block/sdc/device/delete
[root@BendSha_RHEL5_5_x64 /]# ls /sys/block/
fd0 ram0 ram10 ram12 ram14 ram2 ram4 ram6 ram8 sda sr0
md0 ram1 ram11 ram13 ram15 ram3 ram5 ram7 ram9 sdb
添加一个设备:host # 0, bus # 0, target # 2 and LUN # 0
[root@BendSha_RHEL5_5_x64 /]# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
查看/proc/scsi/scsi和磁盘设备
[root@BendSha_RHEL5_5_x64 /]# cat /proc/scsi/scsi
Attached devices:
Host: scsi0 Channel: 00 Id: 00 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi0 Channel: 00 Id: 01 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
Host: scsi1 Channel: 00 Id: 00 Lun: 00
Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
Type: CD-ROM ANSI SCSI revision: 05
Host: scsi0 Channel: 00 Id: 02 Lun: 00
Vendor: VMware, Model: VMware Virtual S Rev: 1.0
Type: Direct-Access ANSI SCSI revision: 02
[root@BendSha_RHEL5_5_x64 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 38 305203+ 83 Linux
/dev/sda2 39 2353 18595237+ 83 Linux
/dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Disk /dev/sdd: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdd doesn‘t contain a valid partition table
VMware Linux Guest 增加磁盘无需重启的方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。