You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何缩减Linux VM数据盘容量?测试与生产环境实操问询

Safely Shrink Linux VM Data Disk in Test Environment (Before Production)

Got it, let's walk through this step by step—since you're testing first on your Standard disk VM before touching the Premium production one, we'll make sure every step is safe and verifiable.

Prerequisites

  • Your test VM has an OS disk + a 1TB data disk (only <15GB used)
  • You have access to your cloud provider's VM/disk management console
  • Backup first! Even in test, take a snapshot of the data disk or run rsync -av /mnt/data /path/to/backup/location to copy all data to another safe place.

Step-by-Step Shrink Process

  1. Stop the Test VM
    Don't just shut down via SSH—go to your cloud console, find the test VM, and select "Stop" (this ensures the disk is fully offline and avoids filesystem corruption).

  2. Detach the Data Disk (Optional but Recommended)
    In the console, navigate to the VM's disk settings, find the data disk, and detach it. This prevents any accidental conflicts while resizing.

  3. Resize the Disk in the Console
    Go to the standalone disk management page, select your data disk, and edit its capacity to your desired size (e.g., 20GB—leave a little buffer just in case). Save the changes.

  4. Reattach the Disk & Start the VM
    Go back to your test VM's disk settings, reattach the resized data disk, then start the VM.

  5. Verify Disk Size & Fix Partition/FileSystem
    SSH into the VM and run these commands:

    • Check the raw disk size: lsblk (you'll see the disk now shows your new smaller size, e.g., /dev/sdc as 20G)
    • If you're using a partitioned disk (most setups):
      1. Unmount the disk first: umount /mnt/data
      2. Use fdisk /dev/sdc to adjust the partition:
        • Type d to delete the old partition (double-check you're deleting the right one!)
        • Type n to create a new primary partition, using the full available space of the resized disk
        • Type w to write the changes
      3. Critical: Adjust the filesystem
        • For ext4/ext3: resize2fs /dev/sdc1 (this shrinks the filesystem to match the new partition)
        • For XFS: Note that XFS doesn't support shrinking natively. You'll need to backup the data, format the new partition with mkfs.xfs /dev/sdc1, then restore the data from your backup.
  6. Remount & Validate

    • Mount the disk again: mount /dev/sdc1 /mnt/data
    • Check the new capacity: df -h—you should see the disk now shows your target size, and all your data is intact.

Notes for Production Premium Disk

  • Backup everything first! Take a full snapshot of the Premium data disk before any changes—Premium disks are critical for production, so no shortcuts here.
  • The process is almost identical to the test environment, but double-check your cloud provider supports resizing Premium disks (most major providers do, but confirm this first).
  • If your production disk uses LVM, the steps will differ slightly: you'll need to shrink the logical volume first (lvreduce), then the physical volume (pvresize), before resizing the disk in the console.

内容的提问来源于stack exchange,提问作者Jeremy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:36:26