|
| 1 | +--- |
| 2 | +title: Directly Attaching Disks to VMs in Proxmox |
| 3 | +date: 2023-09-14 |
| 4 | +categories: [How-to, Proxmox] |
| 5 | +tags: [proxmox,howto,storage] # TAG names should always be lowercase |
| 6 | +--- |
| 7 | + |
| 8 | +Proxmox Virtual Environment (PVE) is a versatile virtualization platform that provides a wide range of features for managing virtual machines (VMs). One powerful capability is the ability to directly attach physical disks to VMs. This can be particularly useful when you want to provide dedicated storage to a VM, pass through specialized hardware, or create high-performance storage solutions. In this guide, we'll walk you through the process of directly attaching disks to VMs in Proxmox. |
| 9 | + |
| 10 | +## Prerequisites |
| 11 | + |
| 12 | +Before you begin, ensure that you have: |
| 13 | + |
| 14 | +1. A Proxmox Virtual Environment (PVE) server up and running. |
| 15 | +2. A physical disk that you want to attach to a VM. Make a note of its serial number or identifier. |
| 16 | + |
| 17 | +## Step 1: Update Package Repositories |
| 18 | + |
| 19 | +To ensure your system is up to date, log in to your Proxmox server and run the following commands: |
| 20 | + |
| 21 | +```shell |
| 22 | +apt update |
| 23 | +``` |
| 24 | + |
| 25 | +## Step 2: Install 'lshw' for Hardware Information |
| 26 | + |
| 27 | +To gather information about the available disks and their identifiers, you can use the `lshw` tool. If it's not already installed, you can install it by running: |
| 28 | + |
| 29 | +```shell |
| 30 | +apt install lshw |
| 31 | +``` |
| 32 | + |
| 33 | +## Step 3: Identify the Disk to Attach |
| 34 | + |
| 35 | +Now, let's use `lshw` to identify the disk that you want to attach to your VM. Run the following command to list information about disks and storage devices: |
| 36 | + |
| 37 | +```shell |
| 38 | +lshw -class disk -class storage |
| 39 | +``` |
| 40 | + |
| 41 | +This command will provide detailed information about the disks on your system, including their serial numbers or identifiers. Make note of the serial number or identifier of the disk you want to attach. |
| 42 | + |
| 43 | +## Step 4: Create a Symlink to the Disk |
| 44 | + |
| 45 | +Next, you need to create a symlink to the disk using its serial number or identifier. Replace `<serial of disk>` with the actual serial number or identifier of your disk: |
| 46 | + |
| 47 | +```shell |
| 48 | +ls -l /dev/disk/by-id | grep <serial of disk> |
| 49 | +``` |
| 50 | + |
| 51 | +This command will display the symlink associated with your disk. Make a note of the symlink, as you will use it in the next step. |
| 52 | + |
| 53 | +## Step 5: Attach the Disk to the VM |
| 54 | + |
| 55 | +Now that you have the symlink to your disk, you can attach it to the VM. Use the following command, replacing `<vm id>` with the actual ID or name of your VM, and `<ata-**>` with the symlink from the previous command: |
| 56 | + |
| 57 | +```shell |
| 58 | +qm set <vm id> -scsi2 /dev/disk/by-id/<ata-**> |
| 59 | +``` |
| 60 | + |
| 61 | +This command tells Proxmox to attach the specified disk to the VM as a SCSI device. You can use different SCSI controllers (e.g., `-scsi0`, `-scsi1`, `-scsi2`, etc.) for attaching multiple disks to the same VM. |
| 62 | + |
| 63 | +## Conclusion |
| 64 | + |
| 65 | +Directly attaching disks to VMs in Proxmox provides flexibility and performance advantages, allowing you to tailor your virtualized environments to specific needs. By following these steps, you can seamlessly integrate physical disks into your virtual machines, expanding storage, and maximizing the utility of your Proxmox environment. |
| 66 | + |
| 67 | +Keep in mind that attaching disks directly to VMs requires careful consideration of hardware compatibility, performance requirements, and data management. Always ensure that you have adequate backups and follow best practices when dealing with storage in virtualized environments. |
0 commit comments