web-dev-qa-db-ja.com

Linuxpartedのパーティションを拡張する方法

環境

MYSQLデータベースをホストするAzure上にリモートLinuxCentOS VMがあります。ディスクサイズを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)を拡張する必要があります。 this postを使用して、試しました

Sudo resize2fs /dev/sda 100G

しかし、それはで拒否されます

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

これは、使用中はパーティションを拡張できないことを意味すると思います。これは、Windowsで同じことを行った経験を考えると理にかなっています。その場合、リモートAzure VMでパーティションを拡張するにはどうすればよいですか?

注:私はVMにシェルするだけなので、外部プログラムを起動したり、GUIを使用したり、単にドライブを別のマシンにマウントしたりすることはできません。

OSの詳細

  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. Windows8.1のデュアルブート構成でMintLinuxパーティションを拡張する方法は?
  4. 拡張パーティションのサイズを変更する方法は?

VMwareを使用

  1. linux(ubuntu 9.04)でパーティションサイズを拡張する方法は?

外部ツール(ブートディスク)を使用します Linuxでプライマリパーティション(/ dev/sda1)を拡張する方法は?

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

CentOSを使用しているので、Gpartedを使用できます。次の方法でインストールできます。

yum install epel-release
yum install gparted

使用方法に関する情報は次のとおりです。

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

1
Genaro Morales

/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

はいの場合、シェルを使用して/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ディスクの詳細については、こちらを参照してください リンク

0
Jason Ye