码迷,mamicode.com
首页 > 系统相关 > 详细

VMware Linux Guest 增加磁盘无需重启的方法

时间:2016-12-19 21:09:51      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:code   方法   use   style   下一步   .com   target   扫描   nbsp   

摘要

    常常需要需要给VMware Linux Guest增加磁盘适配一些测试场景,而又不想花费时间重启Guest,查找文档,发现一种简单的方法,记录一下操作步骤。

操作步骤

1 编辑Linux Guest配置,增加磁盘

技术分享
 技术分享
下一步,直到完成所有的创建步骤。
技术分享
技术分享

 2 扫描SCSI Bus,添加SCSI设备

为了验证效果,先看看当前的磁盘设备,很明显,没有扫描到刚添加的磁盘。
  1. [root@BendSha_RHEL5_5_x64 /]# fdisk -l
  2. Disk /dev/sda: 21.4 GB, 21474836480 bytes
  3. 255 heads, 63 sectors/track, 2610 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sda1 * 1 38 305203+ 83 Linux
  7. /dev/sda2 39 2353 18595237+ 83 Linux
  8. /dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
  9. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  10. 255 heads, 63 sectors/track, 1305 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12. Device Boot Start End Blocks Id System
  13. /dev/sdb1 1 1305 10482381 83 Linux
 
查看scsi_host信息
  1. [root@BendSha_RHEL5_5_x64 /]# ls /sys/class/scsi_host
  2. host0 host11 host14 host17 host2 host22 host25 host28 host30 host6 host9
  3. host1 host12 host15 host18 host20 host23 host26 host29 host4 host7
  4. host10 host13 host16 host19 host21 host24 host27 host3 host5 host8
 
我们添加的磁盘是在host0,扫描host0
  1. [root@BendSha_RHEL5_5_x64 /]# echo "- - -" > /sys/class/scsi_host/host0/scan
  2. [root@BendSha_RHEL5_5_x64 /]#
 
查看/proc/scsi/scsi信息,应该多了一个Id等于2的SCSI设备
  1. [root@BendSha_RHEL5_5_x64 /]# cat /proc/scsi/scsi
  2. Attached devices:
  3. Host: scsi0 Channel: 00 Id: 00 Lun: 00
  4. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  5. Type: Direct-Access ANSI SCSI revision: 02
  6. Host: scsi0 Channel: 00 Id: 01 Lun: 00
  7. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  8. Type: Direct-Access ANSI SCSI revision: 02
  9. Host: scsi1 Channel: 00 Id: 00 Lun: 00
  10. Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
  11. Type: CD-ROM ANSI SCSI revision: 05
  12. Host: scsi0 Channel: 00 Id: 02 Lun: 00
  13. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  14. Type: Direct-Access ANSI SCSI revision: 02
 
fdisk查看磁盘设备,扫描到了 /dev/sdc
  1. [root@BendSha_RHEL5_5_x64 /]# fdisk -l
  2. Disk /dev/sda: 21.4 GB, 21474836480 bytes
  3. 255 heads, 63 sectors/track, 2610 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Device Boot Start End Blocks Id System
  6. /dev/sda1 * 1 38 305203+ 83 Linux
  7. /dev/sda2 39 2353 18595237+ 83 Linux
  8. /dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
  9. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  10. 255 heads, 63 sectors/track, 1305 cylinders
  11. Units = cylinders of 16065 * 512 = 8225280 bytes
  12. Device Boot Start End Blocks Id System
  13. /dev/sdb1 1 1305 10482381 83 Linux
  14. Disk /dev/sdc: 21.4 GB, 21474836480 bytes
  15. 255 heads, 63 sectors/track, 2610 cylinders
  16. Units = cylinders of 16065 * 512 = 8225280 bytes
  17. Disk /dev/sdc doesn‘t contain a valid partition table

3 格式化并创建挂载点

  1. [root@BendSha_RHEL5_5_x64 /]# mkfs.ext4 /dev/sdc
  2. mke4fs 1.41.12 (17-May-2010)
  3. /dev/sdc is entire device, not just one partition!
  4. Proceed anyway? (y,n) y
  5. Filesystem label=
  6. OS type: Linux
  7. Block size=4096 (log=2)
  8. ......
  9. [root@BendSha_RHEL5_5_x64 /]# mkdir /data
  10. [root@BendSha_RHEL5_5_x64 /]# mount /dev/sdc /data/
  11. [root@BendSha_RHEL5_5_x64 /]# df -h
  12. Filesystem Size Used Avail Use% Mounted on
  13. /dev/sda2 18G 11G 5.5G 67% /
  14. /dev/sda1 289M 30M 245M 11% /boot
  15. tmpfs 941M 0 941M 0% /dev/shm
  16. /dev/sdb1 9.9G 220M 9.2G 3% /logvol
  17. /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,可根据设备名删除指定设备:
  1. [root@BendSha_RHEL5_5_x64 /]# ls /sys/block/
  2. fd0 ram0 ram10 ram12 ram14 ram2 ram4 ram6 ram8 sda sdc
  3. md0 ram1 ram11 ram13 ram15 ram3 ram5 ram7 ram9 sdb sr0
  4. [root@BendSha_RHEL5_5_x64 /]# echo 1 > /sys/block/sdc/device/delete
  5. [root@BendSha_RHEL5_5_x64 /]# ls /sys/block/
  6. fd0 ram0 ram10 ram12 ram14 ram2 ram4 ram6 ram8 sda sr0
  7. md0 ram1 ram11 ram13 ram15 ram3 ram5 ram7 ram9 sdb
 
添加一个设备:host # 0, bus # 0, target # 2 and LUN # 0
  1. [root@BendSha_RHEL5_5_x64 /]# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
 
查看/proc/scsi/scsi和磁盘设备
  1. [root@BendSha_RHEL5_5_x64 /]# cat /proc/scsi/scsi
  2. Attached devices:
  3. Host: scsi0 Channel: 00 Id: 00 Lun: 00
  4. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  5. Type: Direct-Access ANSI SCSI revision: 02
  6. Host: scsi0 Channel: 00 Id: 01 Lun: 00
  7. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  8. Type: Direct-Access ANSI SCSI revision: 02
  9. Host: scsi1 Channel: 00 Id: 00 Lun: 00
  10. Vendor: NECVMWar Model: VMware SATA CD00 Rev: 1.00
  11. Type: CD-ROM ANSI SCSI revision: 05
  12. Host: scsi0 Channel: 00 Id: 02 Lun: 00
  13. Vendor: VMware, Model: VMware Virtual S Rev: 1.0
  14. Type: Direct-Access ANSI SCSI revision: 02
  15. [root@BendSha_RHEL5_5_x64 /]# fdisk -l
  16. Disk /dev/sda: 21.4 GB, 21474836480 bytes
  17. 255 heads, 63 sectors/track, 2610 cylinders
  18. Units = cylinders of 16065 * 512 = 8225280 bytes
  19. Device Boot Start End Blocks Id System
  20. /dev/sda1 * 1 38 305203+ 83 Linux
  21. /dev/sda2 39 2353 18595237+ 83 Linux
  22. /dev/sda3 2354 2610 2064352+ 82 Linux swap / Solaris
  23. Disk /dev/sdb: 10.7 GB, 10737418240 bytes
  24. 255 heads, 63 sectors/track, 1305 cylinders
  25. Units = cylinders of 16065 * 512 = 8225280 bytes
  26. Device Boot Start End Blocks Id System
  27. /dev/sdb1 1 1305 10482381 83 Linux
  28. Disk /dev/sdd: 21.4 GB, 21474836480 bytes
  29. 255 heads, 63 sectors/track, 2610 cylinders
  30. Units = cylinders of 16065 * 512 = 8225280 bytes
  31. Disk /dev/sdd doesn‘t contain a valid partition table

VMware Linux Guest 增加磁盘无需重启的方法

标签:code   方法   use   style   下一步   .com   target   扫描   nbsp   

原文地址:http://www.cnblogs.com/bendsha/p/6198908.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!