虚拟服务器linux系统磁盘扩容

您所在的位置:网站首页 mbr类型磁盘扩容 虚拟服务器linux系统磁盘扩容

虚拟服务器linux系统磁盘扩容

2023-05-06 08:22| 来源: 网络整理| 查看: 265

0 分享至

用微信扫码二维码

分享至好友和朋友圈

最近编译服务器磁盘空间满了,导致无法编译,由于是搭建的虚拟服务器,所以通过以下步骤对磁盘空间进行扩容。为虚拟服务器添加硬盘空间

由原来的100G增大到300G

重新划分分区 root@debian:/home/tester# fdisk -lDisk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectorsDisk model: Virtual disk Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0ab29950Device Boot Start End Sectors Size Id Type/dev/sda1 2048 207716349 207714302 99G 83 Linux/dev/sda2 207716350 209713151 1996802 975M 5 Extended/dev/sda5 207716352 209713151 1996800 975M 82 Linux swap / Solaris

可以看到sda分区下有300G的空间,但sda1、sda2、sda3下面总共加起来才100G,说明已经添加成功,但并没有分配到现有分区。

通过fdisk命令对分区进行重新划分

root@debian:/home/tester# fdisk /dev/sdaWelcome to fdisk (util-linux 2.33.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): d #删除现有分区Partition number (1,2,5, default 5): 1 #删除的分区序号Partition 1 has been deleted.Command (m for help): d #删除现有分区Partition number (2,5, default 5): 2 #删除的分区序号Partition 2 has been deleted.Command (m for help): d #删除现有分区No partition is defined yet!Command (m for help): 5 #删除的分区序号5: unknown commandCommand (m for help): F # 查看分区的块序号Unpartitioned space /dev/sda: 300 GiB, 322121498624 bytes, 629143552 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesStart End Sectors Size 2048 629145599 629143552 300GCommand (m for help): n # 重新创建分区Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): #默认P,可不填内容Using default response p.Partition number (1-4, default 1): #默认1,可不填First sector (2048-629145599, default 2048): #默认最早的可分配区块,可不填Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-629145599, default 629145599): 627145599 # 需要填写,另外需要留大概1G的空间给sda2分区Created a new partition 1 of type 'Linux' and of size 299 GiB.Partition #1 contains a ext4 signature.Do you want to remove the signature? [Y]es/[N]o: y # 确认通过The signature will be removed by a write command. Command (m for help): n # 创建sda2分区Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions)Select (default p): Using default response p.Partition number (2-4, default 2): 2First sector (627145600-629145599, default 627146752): Last sector, +/-sectors or +/-size{K,M,G,T,P} (627146752-629145599, default 629145599): Created a new partition 2 of type 'Linux' and of size 976 MiB.Command (m for help): w # 将上述修改写入磁盘The partition table has been altered.Failed to remove partition 5 from system: 设备或资源忙Failed to update system information about partition 1: 设备或资源忙The kernel still uses the old partitions. The new table will be used at the next reboot. Syncing disks. 让新的分区生效 root@debian:/home/tester# fdisk -lDisk /dev/sda: 300 GiB, 322122547200 bytes, 629145600 sectorsDisk model: Virtual disk Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0ab29950Device Boot Start End Sectors Size Id Type/dev/sda1 2048 627145599 627143552 299G 83 Linux/dev/sda2 627146752 629145599 1998848 976M 83 Linux

可以看到,经过上一步后sda1已经可以看到有299G,但df查看sda1还是只有99G,说明还没有生效。此时就需要查看磁盘的类型是什么决定是使用resize2fs命令还是xfs_growfs让其生效。

root@debian:/home/tester# df -PTh文件系统 类型 容量 已用 可用 已用% 挂载点udev devtmpfs 7.9G 0 7.9G 0% /devtmpfs tmpfs 1.6G 8.7M 1.6G 1% /run/dev/sda1 ext4 97G 72G 21G 79% / tmpfs tmpfs 7.9G 0 7.9G 0% /dev/shmtmpfs tmpfs 5.0M 0 5.0M 0% /run/locktmpfs tmpfs 7.9G 0 7.9G 0% /sys/fs/cgrouptmpfs tmpfs 1.6G 0 1.6G 0% /run/user/

可以看出/dev/sda1是ext4格式,那就需要使用resize2fs命令,如果是xfs格式则需要使用xfs_growfs命令

root@debian:/home/tester# resize2fs /dev/sda1resize2fs 1.44.5 (15-Dec-2018)Filesystem at /dev/sda1 is mounted on /; on-line resizing requiredold_desc_blocks = 13, new_desc_blocks = 38The filesystem on /dev/sda1 is now 78392944 (4k) blocks long.

成功后,再使用df命令查看,就可以看到分配的/dev/sda1的空间已经分配成功,总空间已经达到300G

root@debian:/home/tester# df文件系统 1K-块 已用 可用 已用% 挂载点udev 8195812 0 8195812 0% /devtmpfs 1642484 8852 1633632 1% /run/dev/sda1 308124984 75618208 218912528 26% /tmpfs 8212408 0 8212408 0% /dev/shmtmpfs 5120 0 5120 0% /run/locktmpfs 8212408 0 8212408 0% /sys/fs/cgrouptmpfs 1642480 0 1642480 0% /run/user/1000 常见问题

fdisk/resize2fs等命令有可能在你的系统中找不到,程序默认应该都是存在的,只是存放的路径未添加到环境变量中。

可以通过whereis + 命令 查看命令是否存在,和存在什么路径下。

然后通过echo $PATH命令确认上述的路径是否在存在,如果不存在可以通过修改/etc/profile文件增加该环境变量,让其支持。

特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。

Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.

/阅读下一篇/ 返回网易首页 下载网易新闻客户端


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3