音效素材网提供各类素材,打造精品素材网站!

站内导航 站长工具 投稿中心 手机访问

音效素材

Linux系统扩容根目录磁盘空间的操作方法
日期:2018-07-23 14:21:46   来源:脚本之家

一、使用背景

Linux根目录磁盘空间不够用了,当修改了虚拟机模版增加磁盘大小或者插入了一块新硬盘,但是发现系统里的大小还是没改变。

产生的原因是没有给磁盘格式化,没有增加分区。

二、操作方法

1. 查看磁盘空间大小,使用df -h 命令,发现挂载根目录节点的/dev/mapper/ubuntu14--vg-root 只有28G容量。

root@ubuntu14:/opt# df -h
文件系统            容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu14--vg-root  28G  23G 3.3G  88% /
none              4.0K   0 4.0K  0% /sys/fs/cgroup
udev              3.9G 4.0K 3.9G  1% /dev
tmpfs             799M 384K 799M  1% /run
none              5.0M   0 5.0M  0% /run/lock
none              3.9G   0 3.9G  0% /run/shm
none              100M   0 100M  0% /run/user
/dev/vda1           236M  37M 188M  17% /boot

2. 增加磁盘空间,例如下图使用VM虚拟机增加的方式。

3.使用fdisk -l命令查看磁盘信息。当看到第一行Disk /dev/vda: 161.1 GB与实际df -h显示内容不符时,说明增加磁盘成功了。

root@ubuntu14:/opt# fdisk -l

Disk /dev/vda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a023

  设备 启动   起点     终点   块数  Id 系统
/dev/vda1  *    2048   499711   248832  83 Linux
/dev/vda2     501758  62912511  31205377  5 扩展
/dev/vda5     501760  62912511  31205376  8e Linux LVM

Disk /dev/mapper/ubuntu14--vg-root: 29.8 GB, 29804724224 bytes
255 heads, 63 sectors/track, 3623 cylinders, total 58212352 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu14--vg-root doesn't contain a valid partition table

Disk /dev/mapper/ubuntu14--vg-swap_1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu14--vg-swap_1 doesn't contain a valid partition table

4.使用fdisk /dev/vda, 创建新分区。

注意:不同操作系统的磁盘命名方式不同,有些是/dev/sda。具体使用方式参考第三步中fdisk -l首行显示Disk。如笔者在该系统中首行显示为Disk /dev/vda: 161.1 GB, 161061273600 bytes ,故使用命令fdisk /dev/vda)

按照下面Linux操作进行分区。

root@ubuntu14:/opt# fdisk /dev/vda

命令(输入 m 获取帮助): m
命令操作
  a  toggle a bootable flag
  b  edit bsd disklabel
  c  toggle the dos compatibility flag
  d  delete a partition
  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 #new 新分区
Partition type:
  p  primary (1 primary, 1 extended, 2 free)
  l  logical (numbered from 5)
Select (default p): p  #选择主分区
分区号 (1-4,默认为 3): 3 #分区序号
起始 sector (499712-314572799,默认为 499712): #分区开始回车默认
将使用默认值 499712
Last sector, +扇区 or +size{K,M,G} (499712-501757,默认为 501757): 
将使用默认值 501757

命令(输入 m 获取帮助): n #new 新分区
Partition type:
  p  primary (2 primary, 1 extended, 1 free)
  l  logical (numbered from 5)
Select (default p): p #选择主分区
Selected partition 4  #分区序号
起始 sector (62912512-314572799,默认为 62912512): #分区开始回车默认
将使用默认值 62912512
Last sector, +扇区 or +size{K,M,G} (62912512-314572799,默认为 314572799): 
将使用默认值 314572799

命令(输入 m 获取帮助): t  #修改分区格式
分区号 (1-5): 4  #修改分区号
Hex code (type L to list codes): 8e #格式选择8e  linux LVM
Changed system type of partition 4 to 8e (Linux LVM)

命令(输入 m 获取帮助): p #显示分区信息

Disk /dev/vda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors
Units = 扇区 of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001a023

  设备 启动   起点     终点   块数  Id 系统
/dev/vda1  *    2048   499711   248832  83 Linux
/dev/vda2     501758  62912511  31205377  5 扩展
/dev/vda3     499712   501757    1023  83 Linux
/dev/vda4    62912512  314572799  125830144  8e Linux LVM
/dev/vda5     501760  62912511  31205376  8e Linux LVM
Partition table entries are not in disk order
命令(输入 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)
Syncing disks.

5. 重启Linux操作系统,使用reboot命令。

6. 创建物理卷,使用pvcreate /dev/vda4命令。

root@ubuntu14:~# pvcreate /dev/vda4
 Physical volume "/dev/vda4" successfully created

7.查看新建的物理卷和大小,使用pvdisplay命令。

root@ubuntu14:~# pvdisplay
 --- Physical volume ---
 PV Name        ubuntu14-vg
 PV Size        29.76 GiB / not usable 2.00 MiB
 Allocatable      yes (but full)
 PE Size        4.00 MiB
 Total PE       7618
 Free PE        0
 Allocated PE     7618
 PV UUID        XR32TY-aRQC-IQC6-oCx7-aa9X-KdJe-bHmaBd
 "/dev/vda4"        /dev/vda5
 VG Name is a new physical volume of "120.00 GiB"
 --- NEW Physical volume ---
 PV Name        /dev/vda4
 VG Name        
 PV Size        120.00 GiB
 Allocatable      NO
 PE Size        0  
 Total PE       0
 Free PE        0
 Allocated PE     0
 PV UUID        MVK0IT-LDgP-eWwZ-fzQM-tdyY-kRQ-nbk122

8. 将添加新的物理卷,加载到ubuntu14-vg卷组,使用vgextend ubuntu14-vg /dev/vda4命令。

root@ubuntu14:~# vgextend ubuntu14-vg /dev/vda4
Volume group "ubuntu14-vg" successfully extended

9. 查看卷组信息,使用vgdisplay命令。

root@ubuntu14:~# vgdisplay         
 --- Volume group ---
 VG Name        ubuntu14-vg
 System ID       
 Format        lvm2
 Metadata Areas    2
 Metadata Sequence No 4
 VG Access       read/write
 VG Status       resizable
 MAX LV        0
 Cur LV        2
 Open LV        2
 Max PV        0
 Cur PV        2
 Act PV        2
 VG Size        149.76 GiB
 PE Size        4.00 MiB
 Total PE       38338
 Alloc PE / Size    7618 / 29.76 GiB
 Free PE / Size    30720 / 120.00 GiB
 VG UUID        cq2Z6G-P6j1-S2gM-mibz-d63V-NjkS-dHYe7D

10.增加ubuntu14-vg大小,增加120G。使用lvresize -L +120G /dev/mapper/ubuntu14--vg-root命令。

root@ubuntu14:~# lvresize -L +120G /dev/mapper/ubuntu14--vg-root
 Extending logical volume root to 147.76 GiB
 Logical volume root successfully resized

11. 重新识别ubuntu14-vg大小,使用resize2fs /dev/mapper/ubuntu14--vg-root命令。

root@ubuntu14:~# resize2fs /dev/mapper/ubuntu14--vg-root
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/mapper/ubuntu14--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 10
The filesystem on /dev/mapper/ubuntu14--vg-root is now 38733824 blocks long.

12.查看扩容后的大小 ,使用df -h命令。

root@ubuntu14:~# df -h
文件系统            容量 已用 可用 已用% 挂载点
/dev/mapper/ubuntu14--vg-root 146G  23G 117G  17% /
none              4.0K   0 4.0K  0% /sys/fs/cgroup
udev              3.9G 4.0K 3.9G  1% /dev
tmpfs             799M 388K 799M  1% /run
none              5.0M   0 5.0M  0% /run/lock
none              3.9G   0 3.9G  0% /run/shm
none              100M   0 100M  0% /run/user
/dev/vda1           236M  37M 188M  17% /boot

当看到/dev/mapper/ubuntu14--vg-root 已经更新到新的大小时,则表示增加成功。

总结

以上所述是小编给大家介绍的Linux系统扩容根目录磁盘空间的操作方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

    您感兴趣的教程

    在docker中安装mysql详解

    本篇文章主要介绍了在docker中安装mysql详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编...

    详解 安装 docker mysql

    win10中文输入法仅在桌面显示怎么办?

    win10中文输入法仅在桌面显示怎么办?

    win10系统使用搜狗,QQ输入法只有在显示桌面的时候才出来,在使用其他程序输入框里面却只能输入字母数字,win10中...

    win10 中文输入法

    一分钟掌握linux系统目录结构

    这篇文章主要介绍了linux系统目录结构,通过结构图和多张表格了解linux系统目录结构,感兴趣的小伙伴们可以参考一...

    结构 目录 系统 linux

    PHP程序员玩转Linux系列 Linux和Windows安装

    这篇文章主要为大家详细介绍了PHP程序员玩转Linux系列文章,Linux和Windows安装nginx教程,具有一定的参考价值,感兴趣...

    玩转 程序员 安装 系列 PHP

    win10怎么安装杜比音效Doby V4.1 win10安装杜

    第四代杜比®家庭影院®技术包含了一整套协同工作的技术,让PC 发出清晰的环绕声同时第四代杜比家庭影院技术...

    win10杜比音效

    纯CSS实现iOS风格打开关闭选择框功能

    这篇文章主要介绍了纯CSS实现iOS风格打开关闭选择框,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作...

    css ios c

    Win7如何给C盘扩容 Win7系统电脑C盘扩容的办法

    Win7如何给C盘扩容 Win7系统电脑C盘扩容的

    Win7给电脑C盘扩容的办法大家知道吗?当系统分区C盘空间不足时,就需要给它扩容了,如果不管,C盘没有足够的空间...

    Win7 C盘 扩容

    百度推广竞品词的投放策略

    SEM是基于关键词搜索的营销活动。作为推广人员,我们所做的工作,就是打理成千上万的关键词,关注它们的质量度...

    百度推广 竞品词

    Visual Studio Code(vscode) git的使用教程

    这篇文章主要介绍了详解Visual Studio Code(vscode) git的使用,小编觉得挺不错的,现在分享给大家,也给大家做个参考。...

    教程 Studio Visual Code git

    七牛云储存创始人分享七牛的创立故事与

    这篇文章主要介绍了七牛云储存创始人分享七牛的创立故事与对Go语言的应用,七牛选用Go语言这门新兴的编程语言进行...

    七牛 Go语言

    Win10预览版Mobile 10547即将发布 9月19日上午

    微软副总裁Gabriel Aul的Twitter透露了 Win10 Mobile预览版10536即将发布,他表示该版本已进入内部慢速版阶段,发布时间目...

    Win10 预览版

    HTML标签meta总结,HTML5 head meta 属性整理

    移动前端开发中添加一些webkit专属的HTML5头部标签,帮助浏览器更好解析HTML代码,更好地将移动web前端页面表现出来...

    移动端html5模拟长按事件的实现方法

    这篇文章主要介绍了移动端html5模拟长按事件的实现方法的相关资料,小编觉得挺不错的,现在分享给大家,也给大家...

    移动端 html5 长按

    HTML常用meta大全(推荐)

    这篇文章主要介绍了HTML常用meta大全(推荐),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参...

    cdr怎么把图片转换成位图? cdr图片转换为位图的教程

    cdr怎么把图片转换成位图? cdr图片转换为

    cdr怎么把图片转换成位图?cdr中插入的图片想要转换成位图,该怎么转换呢?下面我们就来看看cdr图片转换为位图的...

    cdr 图片 位图

    win10系统怎么录屏?win10系统自带录屏详细教程

    win10系统怎么录屏?win10系统自带录屏详细

    当我们是使用win10系统的时候,想要录制电脑上的画面,这时候有人会想到下个第三方软件,其实可以用电脑上的自带...

    win10 系统自带录屏 详细教程

    + 更多教程 +
    WIN服务器linux服务器FTP服务器DNS服务器其他