语境

语境

语境

我在 Azure 上有一个远程 Linux CentOS VM,它托管一个 MYSQL 数据库。我刚刚将磁盘大小从 30GB 升级到 100GB。问题是没有将额外的空间添加到分区中。

$ parted

(parted) print free
Model: Msft Virtual Disk (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system     Flags
        32.3kB  1049kB  1016kB           Free Space
 1      1049kB  31.2GB  31.2GB  primary  ext4            boot
 2      31.2GB  32.2GB  1049MB  primary  linux-swap(v1)
        32.2GB  107GB   75.2GB           Free Space

$ lsblk

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0      2:0    1    4K  0 disk
sda      8:0    0  100G  0 disk
├─sda1   8:1    0   29G  0 part /
└─sda2   8:2    0 1000M  0 part
sdb      8:16   0   50G  0 disk
└─sdb1   8:17   0   50G  0 part /mnt/resource

$ df

Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda1       29822848 25241412   3043440  90% /
devtmpfs         1752756        0   1752756   0% /dev
tmpfs            1761624        0   1761624   0% /dev/shm
tmpfs            1761624     8440   1753184   1% /run
tmpfs            1761624        0   1761624   0% /sys/fs/cgroup
/dev/sdb1       51472864    53276  48781868   1% /mnt/resource
tmpfs             352328        0    352328   0% /run/user/1000

问题

显然,我需要扩展分区 1 (/dev/sda) 以包含可用空间。使用帖子,我试过了

sudo resize2fs /dev/sda 100G

但它被拒绝了

Device or resource busy while trying to open /dev/sda`.

我认为这意味着我无法在使用分区时对其进行扩展,根据我在 Windows 上执行相同操作的经验,这对我来说是合理的。如果是这样,那么如何扩展远程 Azure VM 上的分区

注意:我只能进入 VM,因此无法启动外部程序、使用 GUI,或者只是将驱动器安装到另一台机器上。

操作系统详细信息

  Static hostname: PMCTMYSQL
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 99f30b6b81444d47a888f0313c428bd8
           Boot ID: 444cc3a5a22b4e53a947e06af2d9b4d2
    Virtualization: microsoft
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.36.3.el7.x86_64
      Architecture: x86-64

更多研究

我检查了 SU 建议的其他线程,但由于各种原因,它们并不适用:

建议使用 GUI 工具

  1. 如何在 linux(ubuntu 9.04) 中扩展分区大小?
  2. 如何扩展 Linux ext3 分区?
  3. 如何在 Windows 8.1 双启动配置上扩展 Mint Linux 分区?
  4. 如何调整扩展分区的大小?

使用 VMware

  1. 如何在 linux(ubuntu 9.04) 中扩展分区大小?

使用外部工具(启动盘) 如何在 Linux 中扩展主分区(/dev/sda1)?

  1. https://www.howtoforge.com/linux_resizing_ext3_partitions

答案1

您可以使用 Gparted,因为您使用的是 centOS,您可以通过以下方式安装它:

yum install epel-release
yum install gparted

以下是有关如何使用它的一些信息:

http://gparted.org/display-doc.php%3Fname%3Dmoving-space-between-partitions

答案2

你想扩展/dev/sda2到100G吗?像这样:

[root@jason ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs       100G  1.2G   99G   2% /
devtmpfs       devtmpfs  828M     0  828M   0% /dev
tmpfs          tmpfs     839M     0  839M   0% /dev/shm
tmpfs          tmpfs     839M  8.3M  830M   1% /run
tmpfs          tmpfs     839M     0  839M   0% /sys/fs/cgroup
/dev/sda1      xfs       497M   62M  436M  13% /boot
/dev/sdb1      ext4       69G   53M   66G   1% /mnt/resource
tmpfs          tmpfs     168M     0  168M   0% /run/user/1000

如果是的话,我们可以使用shell扩展/dev/sda2到100G。(centos 7.3)

[root@jason ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bd020

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2              64        3917    30944256   83  Linux

Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First cylinder (64-13054, default 64): 
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-13054, default 13054): 
Using default value 13054
Partition 2 of type Linux and of size 99.5 GiB is set

Command (m for help): a
Partition number (1,2, default 2): 2

Command (m for help): p

Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bd020

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
/dev/sda2   *          64       13054   104343231   83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@jason ~]# reboot

重启完成后,我们应该使用此命令来扩展它xfs_growfs -d /dev/sda2centos 7),centos 6我们应该使用sudo resize2fs /dev/sda2

[root@jason ~]# xfs_growfs -d /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=1934016 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7736064, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3777, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7736064 to 26085807
[root@jason ~]# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sda2      xfs       100G  1.2G   99G   2% /

有关扩展操作系统磁盘的更多信息,请参阅此关联

相关内容