如何扩展分区Linux分区


1

语境

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

$分开

(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

您是说要扩展/dev/sda2到100G吗?
Jason Ye

没有。/ dev / sda1需要扩展到100G。我已经更新了答案,以包含lsblk和df结果。
KareemElashmawy

Answers:



0

您想扩展/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 6sudo 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% /

有关扩展OS磁盘的更多信息,请参考此链接

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.