如何将磁盘空间从/dev/sda移动到/dev/sda1?

如何将磁盘空间从/dev/sda移动到/dev/sda1?

我有一个使用 centos 7 和 200GB 磁盘的虚拟机。出于某种原因,我的布局是:

df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/sda1                100GB  95GB  5GB   

运行 fdisk -l:

Disk /dev/sda: 204.8 GB, 204803670016 bytes,400007168 sectors 
Units = sectors of 1 * 512 = 512 bytes 
Sector size(logical/physical): 512 bytes / 512 bytes
I/O size(minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0006c283

Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   199997439    99997696     Linux

我想增加分区 /dev/sda1 上的空间。

答案1

听起来您正在尝试扩展分区。去做这个:

  1. 调整分配的分区的大小。例如:cfdisk /dev/sda并选择调整分区大小的选项。
  2. 操作系统应该自动更新,但以防万一你可以打电话partprobe /dev/sda
  3. 调整文件系统的大小。例如:对于 ext 文件系统resize2fs /dev/sda1

只要您扩展分区(而不是缩小),在系统运行时执行此操作应该是安全的。但一定要备份一切。

答案2

我找到了扩展分区的解决方案:

1.删​​除分区并在其位置创建一个新分区

root@rescue ~ # fdisk /dev/sda

Command (m for help): d
Selected partition 1

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-199999487, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-199999487, default 199999487):
Using default value 199999487

Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N

Command (m for help): p

Disk /dev/sda: 102.4 GB, 102399737856 bytes
255 heads, 63 sectors/track, 12449 cylinders, total 199999488 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00051eb3

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048   199999487    99998720   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

2.调整文件系统大小

# resize2fs /dev/sda1
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sda1 to 24999680 (4k) blocks.
The filesystem on /dev/sda1 is now 24999680 blocks long.

3.重启

相关内容