首页 > 系统相关 >Ubuntu扩充硬盘空间

Ubuntu扩充硬盘空间

时间:2022-12-24 10:11:20浏览次数:54  
标签:space free check see Ubuntu 硬盘空间 扩充 your size

Use Your Default Free Space

As you can see above: the Ubuntu installer (by default) left almost half of my disk space unusable by the root file system! I’ve looked around to find an explanation on why these are the default settings, but can’t find anything. Before extending your underlying hypervisor disk or storage volume, you may want to see if you have free space available and ready to be used to extend your existing file system. If you used the Ubuntu defaults during installation, then there is a good chance you have this free space.

Start by checking your root filesystem free space with df -h. As you can see I am only using 14% of my ~49GB volume, but we’ll pretend I’m close to 100% and need to make that 49GB volume larger.

To check for existing free space on your Volume Group (where it is left by the installer default settings), run the command vgdisplay and check for free space. Here you can see I have 49.25GB of free space ready to be used. If you don’t have any free space, move on to the next section to use some free space from an extended physical (or virtual) disk.

To use up that free space on your Volume Group (VG) for your root Logical Volume (LV), first run the lvdisplay command and check the Logical Volume size, then run lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv to extend the LV to the maximum size usable, then run lvdisplay one more time to make sure it changed.

At this point you have increased the size of the block volume where your root filesystem resides, but you still need to extend the filesystem on top of it. First, run df -h to verify your (almost full) root file system, then run resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv to extend your filesystem, and run df -h one more time to make sure you’re successful.

And that’s it. You just allocated the free space left behind by the Ubuntu installer to your root filesystem. If this is still not enough space, continue on to the next section to allocate more space by extending an underlying disk.

 

Use Space from Extended Physical (or Virtual) Disk

First you need to increase the size of the disk being presented to the Linux OS. This is most likely done by expanding the virtual disk in KVM/VMWare/Hyper-V or by adjusting your RAID controller / storage system to increase the volume size. You can often do this while Linux is running; without shutting down or restarting. I’ve extended my 100GB disk to 200GB for my example machine.

Once that is done, you may need to get Linux to rescan the disk for the new free space. Check for free space by running cfdisk and see if there is free space listed, use “q” to exit once you’re done.

If you don’t see free space listed, then initiate a rescan of /dev/sda  with echo 1>/sys/class/block/sda/device/rescan. Once done, rerun cfdisk and you should see the free space listed.

Select your /dev/sda3 partition from the list and then select “Resize” from the bottom menu. Hit ENTER and it will prompt you to confirm the new size. Hit ENTER again and you will now see the /dev/sda3 partition with a new larger size.

Select “Write” from the bottom menu, type yes to confirm, and hit ENTER. Then use “q” to exit the program.

Now that the LVM partition backing the  /dev/sda3 Physical Volume (PV) has been extended, we need to extend the PV itself. Run pvresize /dev/sda3 to do this and then use pvdisplay to check the new size.

As you can see above, my PV has been increased from 98.5GB to 198.5GB. Now let’s check the Volume Group (VG) free space with vgdisplay.

We can see above that the VG has 100GB of free space. Now let’s check the size of our upstream Logical Volume (LV) using lvdisplay, extend the LV to use up all the VG’s free space with lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv, and then check the LV one more time with lvdisplay to make sure it has been extended.

At this point, the block volume underpinning our root filesystem has been extended, but the filesystem itself has not been resized to fit that new volume. To do this, run df -h to check the current size of the file system, then run resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv to resize it, and df -h one more time to check the new file system available space.

And there you go. You’ve now taken an expanded physical (or virtual) disk and moved that free space all the way up through the LVM abstraction layers to be used by your (critically full) root file system. Time to check it off the to-do list and move on to the next IT emergency.

标签:space,free,check,see,Ubuntu,硬盘空间,扩充,your,size
From: https://www.cnblogs.com/Evan-fanfan/p/17002444.html

相关文章

  • Google的操作系统就是Ubuntu?
    记得以前网上曾有一个新闻说google要推出基于Linux的桌面操作系统与微软竞争,不过事过不久后有人指出该新闻是某网友制作的假新闻。虽然这条假新闻没有当年盖茨遇刺身亡那么......
  • Ubuntu换源
    什么是安装源?安装源类似于一个软件仓库,绝大部分系统软件和工具都可以从软件仓库中自动下载和安装。Ubuntu安装后默认的官方源是美国的服务器,因此访问速度很慢。所以需要......
  • 利用VirtualBox安装Ubuntu详细图文教程
    在VirtualBox虚拟机中安装Ubuntu系统也很简单,下面是详细的图文教程,请大家参考。VirtualBox虚拟机安装过程略。1.创建一个新的虚拟机 给虚拟机命名,选择合适的Ubuntu版本。2.......
  • Day01_04_Linux_Ubuntu教程之安装配置 Java 开发环境
    一.Linux安装配置Java开发环境1.概述此处在Ubuntu18.04系统下以jdk-8u211-linux-x64.tar.gz.zip为例2.下载地址​​http://www.oracle.com/technetwork/java/javase/......
  • Day01_06_Linux_Ubuntu教程之安装配置MySQL
    Linux安装MySQL服务器及客户端本教程以ubuntu18.04系统为例1.安装mysql1.1更新ubuntu的source数据源apt-getupdate1.2安装mysql-serverapt-getinstallmysql-server......
  • gdal源码安装(ubuntu)
    gdal源码安装(ubuntu)1、安装依赖proj#配置环境变量(base)root@FIB:~#exportPKG_CONFIG_PATH=/usr/local/anaconda3/lib/pkgconfig/:$PKG_CONFIG_PATH#下载源码......
  • Jenkins教程之_01_Ubuntu下Jenkins安装启动教程
    01_Ubuntu下Jenkins安装启动教程Jenkins简介Jenkins是⼀个开源的Java软件项⽬,是基于Java开发的⼀种持续集成CI&CD⼯具,⽤于监控持续重复的⼯......
  • ubuntu如何安装composer
    >wgethttps://getcomposer.org/composer.phar>mvcomposer.pharcomposer>chmod+xcomposer全局:sudomvcomposer/usr/local/bin测试:composer--version ......
  • Ubuntu:Docker 容器操作
    创建容器1.dockerrun[option]镜像名[向启动容器中传入的命令]常用可选说明-i表示以“交互模式”运行容器-t表示容器启动后会进入其命令行。加入这两个参数......
  • Ubuntu:Docker启动与停止
    安装完成Docker后,默认已经启动了docker服务,如需手动控制docker服务的启停,可执行如下命令启动dockersudoservicedockerstart停止dockersudoservicedockerstop......