Home System Tutorial LINUX Add a new hard drive to a Linux guest without restarting the virtual machine

Add a new hard drive to a Linux guest without restarting the virtual machine

Apr 03, 2024 pm 04:34 PM
linux centos linux tutorial Red Hat linux system linux command linux certification red hat linux linux video

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.

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

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.

Step 1: Add a new hard drive to the virtual guest

First, add the hard disk through the vmware hardware settings menu. Click “VM > Settings”

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Or you can also press CTRL D to enter the settings dialog box.

Click “Add” to add a new hard drive to the client:

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Select the hardware type as "Hard disk" and click "Next":

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Select “create a new virtual disk” and click “Next”:

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Set the virtual disk type to "SCSI" and click "Next":

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Set the maximum disk size as needed and click “Next”

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

Finally, select the file location and click “Finish”.

Step 2: Rescan the SCSI bus and add SCSI devices without restarting the virtual machine

Enter the following command to rescan the SCSI bus:

echo "- - -" > /sys/class/scsi_host/host# /scan
fdisk -l
tail -f /var/log/message
Copy after login

The output is:

在不重启虚拟机的情况下为 Linux 客户机添加新硬盘

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
Copy after login

Then enter the following command to request a rescan:

echo "- - -" > /sys/class/scsi_host/host0/scan
fdisk -l
tail -f /var/log/message
Copy after login

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
Copy after login
How to delete the /dev/sdc device?

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
Copy after login
How to add the /dev/sdc device?

使用下面语法添加指定设备:

# echo "scsi add-single-device <H> <B> <T> <L>" > /proc/scsi/scsi
Copy after login

这里,

  • :主机
  • :总线(通道)
  • :目标 (Id)
  • :LUN 号

例如。使用参数 host#0bus#0target#2,以及 LUN#0 来添加 /dev/sdc,则输入:

# echo "scsi add-single-device 0 0 2 0">/proc/scsi/scsi
# fdisk -l
# cat /proc/scsi/scsi
Copy after login

结果输出:

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
Copy after login
步骤 #3:格式化新磁盘

现在使用 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
Copy after login
步骤 #4:创建挂载点并更新 /etc/fstab
# mkdir /disk3
Copy after login

打开 /etc/fstab 文件,输入:

# vi /etc/fstab
Copy after login

加入下面这行:

/dev/sdc3 /disk3 ext3 defaults 1 2
Copy after login

若是 ext4 文件系统则加入:

/dev/sdc3 /disk3 ext4 defaults 1 2
Copy after login

保存并关闭文件。

可选操作:为分区加标签

你可以使用 e2label 命令为分区加标签 [2]。假设,你想要为 /backupDisk 这块新分区加标签,则输入:

# e2label /dev/sdc1 /backupDisk
Copy after login

详情参见 "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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

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).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

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).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

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.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

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)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

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.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

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.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

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 vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

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.

See all articles