Linuxパーティションの拡張

記事ディレクトリ

Linux パーティションの拡張

残念ながら、私が構築したローカル テスト クラスターの 1 つのノードに事前に割り当てられたストレージ スペースでは十分ではなく、それを拡張する方法はありません。

まず、VM のディスク容量を拡張します (すべてのスナップショットを削除します。スナップショットのあるものは拡張できません)。

[root@linux121 ~]# df -lh  --查看当前节点存储空间
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.1M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  7.4G  9.7G   44% /
/dev/sda1               1014M  181M  834M   18% /boot
tmpfs                     98M     0   98M    0% /run/user/0


[root@linux121 ~]# fdisk -l --查询本机可以识别的硬盘和分区

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a94d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节

[root@linux121 ~]# fdisk /dev/sda  和fdisk -l --查询本机可以识别的硬盘和分区保持一致
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3)3
起始 扇区 (41943040-83886079,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{
    
    K,M,G} (41943040-83886079,默认为 83886079):
将使用默认值 83886079
分区 3 已设置为 Linux 类型,大小设为 20 GiB

命令(输入 m 获取帮助):pvcreate /dev/sda3

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a94d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040    83886079    20971520   83  Linux

命令(输入 m 获取帮助):vgscan
Remaining 2047 unallocated 512-byte sectors

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# w
 16:33:15 up 10 min,  1 user,  load average: 0.00, 0.11, 0.13
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/0    192.168.88.1     16:24    3.00s  0.05s  0.00s w

[root@linux121 ~]# fdisk -l

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a94d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040    83886079    20971520   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节


[root@linux121 ~]# fdisk -l

磁盘 /dev/sda:42.9 GB, 42949672960 字节,83886080 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a94d5

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM
/dev/sda3        41943040    83886079    20971520   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O 大小(最小/最佳)512 字节 / 512 字节

您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# partprobe;
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)/dev/sr0 已按照只读方式打开。
[root@linux121 ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.
[root@linux121 ~]# vgscan
  Reading volume groups from cache.
  Found volume group "centos" using metadata type lvm2
您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
[root@linux121 ~]# lvextend -L +20G /dev/mapper/centos-root
  Insufficient free space: 5120 extents needed, but only 5119 available
您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# ^C
[root@linux121 ~]# lvextend -L +24G /dev/mapper/centos-root
  Insufficient free space: 6144 extents needed, but only 5119 available
您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# lvextend -L +19G /dev/mapper/centos-root
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <36.00 GiB (9215 extents).
  Logical volume centos/root successfully resized.
[root@linux121 ~]# dh -f
bash: dh: 未找到命令...
[root@linux121 ~]# ^C
您在 /var/spool/mail/root 中有新邮件
[root@linux121 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.1M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  7.4G  9.7G   44% /
/dev/sda1               1014M  181M  834M   18% /boot
tmpfs                     98M     0   98M    0% /run/user/0
[root@linux121 ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 9436160
[root@linux121 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 470M     0  470M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  8.1M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   36G  7.4G   29G   21% /
/dev/sda1               1014M  181M  834M   18% /boot
tmpfs                     98M     0   98M    0% /run/user/0
您在 /var/spool/mail/root 中有新邮件

おすすめ

転載: blog.csdn.net/qq_43408367/article/details/126255726