


Add a new hard drive to a Linux guest without restarting the virtual machine
As a system administrator, I often need to use additional hard drives to expand storage space or separate system data from user data. I will show you how to add a hard drive from a host to a Linux guest virtualized using VMWare software, in the process of adding a physical block device to the virtual host.
You can explicitly add or remove a SCSI device, or rescan the entire SCSI bus without restarting the Linux virtual machine. This guide was tested with Vmware Server and Vmware Workstation v6.0 (older versions should also be supported). All commands are tested under RHEL, Fedora, CentOS and Ubuntu Linux guest/host operating systems.
First, add the hard disk through the vmware hardware settings menu. Click “VM > Settings”
Or you can also press CTRL D to enter the settings dialog box.
Click “Add” to add a new hard drive to the client:
Select the hardware type as "Hard disk" and click "Next":
Select “create a new virtual disk” and click “Next”:
Set the virtual disk type to "SCSI" and click "Next":
Set the maximum disk size as needed and click “Next”
Finally, select the file location and click “Finish”.
Enter the following command to rescan the SCSI bus:
echo "- - -" > /sys/class/scsi_host/host# /scan fdisk -l tail -f /var/log/message
The output is:
You need to replace host# with a real value, such as host0. You can check this value with the following command:
# ls /sys/class/scsi_host
Output:
host0
Then enter the following command to request a rescan:
echo "- - -" > /sys/class/scsi_host/host0/scan fdisk -l tail -f /var/log/message
The output is:
Jul 18 16:29:39 localhost kernel: Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Jul 18 16:29:39 localhost kernel: Type: Direct-Access ANSI SCSI revision: 02 Jul 18 16:29:39 localhost kernel: target0:0:1: Beginning Domain Validation Jul 18 16:29:39 localhost kernel: target0:0:1: Domain Validation skipping write tests Jul 18 16:29:39 localhost kernel: target0:0:1: Ending Domain Validation Jul 18 16:29:39 localhost kernel: target0:0:1: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127) Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB) Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through Jul 18 16:29:39 localhost kernel: SCSI device sdb: 2097152 512-byte hdwr sectors (1074 MB) Jul 18 16:29:39 localhost kernel: sdb: Write Protect is off Jul 18 16:29:39 localhost kernel: sdb: cache data unavailable Jul 18 16:29:39 localhost kernel: sdb: assuming drive cache: write through Jul 18 16:29:39 localhost kernel: sdb: unknown partition table Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi disk sdb Jul 18 16:29:39 localhost kernel: sd 0:0:1:0: Attached scsi generic sg1 type 0 Jul 18 16:29:39 localhost kernel: Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Jul 18 16:29:39 localhost kernel: Type: Direct-Access ANSI SCSI revision: 02 Jul 18 16:29:39 localhost kernel: target0:0:2: Beginning Domain Validation Jul 18 16:29:39 localhost kernel: target0:0:2: Domain Validation skipping write tests Jul 18 16:29:39 localhost kernel: target0:0:2: Ending Domain Validation Jul 18 16:29:39 localhost kernel: target0:0:2: FAST-40 WIDE SCSI 80.0 MB/s ST (25 ns, offset 127) Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB) Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through Jul 18 16:29:39 localhost kernel: SCSI device sdc: 2097152 512-byte hdwr sectors (1074 MB) Jul 18 16:29:39 localhost kernel: sdc: Write Protect is off Jul 18 16:29:39 localhost kernel: sdc: cache data unavailable Jul 18 16:29:39 localhost kernel: sdc: assuming drive cache: write through Jul 18 16:29:39 localhost kernel: sdc: unknown partition table Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi disk sdc Jul 18 16:29:39 localhost kernel: sd 0:0:2:0: Attached scsi generic sg2 type 0
In addition to rescanning the entire bus, you can also use the following command to add or delete specified disks:
# echo 1 > /sys/block/devName/device/delete # echo 1 > /sys/block/sdc/device/delete
使用下面语法添加指定设备:
# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
这里,
- :主机
- :总线(通道)
- :目标 (Id)
- :LUN 号
例如。使用参数 host#0,bus#0,target#2,以及 LUN#0 来添加 /dev/sdc,则输入:
# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi # fdisk -l # 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: scsi0 Channel: 00 Id: 02 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02
现在使用 fdisk 并通过 mkfs.ext3[1] 命令创建分区:
# fdisk /dev/sdc ### [if you want ext3 fs] ### # mkfs.ext3 /dev/sdc3 ### [if you want ext4 fs] ### # mkfs.ext4 /dev/sdc3
# mkdir /disk3
打开 /etc/fstab 文件,输入:
# vi /etc/fstab
加入下面这行:
/dev/sdc3 /disk3 ext3 defaults 1 2
若是 ext4 文件系统则加入:
/dev/sdc3 /disk3 ext4 defaults 1 2
保存并关闭文件。
你可以使用 e2label 命令为分区加标签 [2]。假设,你想要为 /backupDisk 这块新分区加标签,则输入:
# e2label /dev/sdc1 /backupDisk
详情参见 "Linux 分区的重要性 [3]。
The above is the detailed content of Add a new hard drive to a Linux guest without restarting the virtual machine. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.
