广告
返回顶部
首页 > 资讯 > 操作系统 >Linux系统下怎么对硬盘分区进行扩容
  • 182
分享到

Linux系统下怎么对硬盘分区进行扩容

2023-06-12 21:06:54 182人浏览 安东尼
摘要

这篇文章主要讲解了“linux系统下怎么对硬盘分区进行扩容”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux系统下怎么对硬盘分区进行扩容”吧!硬盘快满了,加硬盘扩容,不管是独立的服务器

这篇文章主要讲解了“linux系统下怎么对硬盘分区进行扩容”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux系统下怎么对硬盘分区进行扩容”吧!

硬盘快满了,加硬盘扩容,不管是独立的服务器,还是云空间新买的硬盘,扩容方式一样。

一,不采用lvm,直接将硬盘挂载到目录
1,查看硬盘分区情况

代码如下:


[root@iZ94zz3wqciZ ~]# df  
Filesystem     1K-blocks     Used Available Use% Mounted on  
/dev/xvda1      20641404 14778400   4814480  76% /  
tmpfs             509300        0    509300   0% /dev/shm  
 
[root@iZ94zz3wqciZ ~]# fdisk -l  
 
Disk /dev/xvda: 21.5 GB, 21474836480 bytes  
255 heads, 63 sectors/track, 2610 cylinders  
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 identifier: 0x00078f9c  
 
   Device Boot      Start         End      Blocks   Id  System  
/dev/xvda1   *           1        2611    20970496   83  Linux     //id是83,非lvm  
 
Disk /dev/xvdb: 23.6 GB, 23622320128 bytes         //新买的硬盘  
255 heads, 56 sectors/track, 3230 cylinders  
Units = cylinders of 14280 * 512 = 7311360 bytes  
Sector size (logical/physical): 512 bytes / 512 bytes  
I/O size (minimum/optimal): 512 bytes / 512 bytes  
Disk identifier: 0x27cc1f5a  

2,硬盘分区并查看分区情况

代码如下:


[root@iZ94zz3wqciZ ~]# fdisk -S 56 /dev/xvdb      //分区  
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').  
 
Command (m for help): n   //输入n  
Command action  
  e   extended  
  p   primary partition (1-4)  
p  //主分区  
Partition number (1-4): 1   //分区号1  
First cylinder (1-3230, default 1):  
Using default value 1  
Last cylinder, +cylinders or +size{K,M,G} (1-3230, default 3230):  
Using default value 3230  
 
Command (m for help): wq   //保存并退出  
The partition table has been altered!  
 
[root@iZ94zz3wqciZ ~]# fdisk -l      
 
Disk /dev/xvda: 21.5 GB, 21474836480 bytes  
255 heads, 63 sectors/track, 2610 cylinders  
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 identifier: 0x00078f9c  
 
   Device Boot      Start         End      Blocks   Id  System  
/dev/xvda1   *           1        2611    20970496   83  Linux  
 
Disk /dev/xvdb: 23.6 GB, 23622320128 bytes  
255 heads, 56 sectors/track, 3230 cylinders  
Units = cylinders of 14280 * 512 = 7311360 bytes  
Sector size (logical/physical): 512 bytes / 512 bytes  
I/O size (minimum/optimal): 512 bytes / 512 bytes  
Disk identifier: 0x27cc1f5a  
 
   Device Boot      Start         End      Blocks   Id  System  
/dev/xvdb1               1        3230    23062172   83  Linux    //分区后  

3,格式化新分区xvdb1

代码如下:


[root@iZ94zz3wqciZ ~]# mkfs.ext4 /dev/xvdb1   //格式化分区  
mke2fs 1.41.12 (17-May-2010)  
Filesystem label=  
OS type: Linux  
Block size=4096 (log=2)  
Fragment size=4096 (log=2)  
Stride=0 blocks, Stripe width=0 blocks  
1441792 inodes, 5765543 blocks  
288277 blocks (5.00%) reserved for the super user  
First data block=0  
Maximum filesystem blocks=4294967296  
176 block groups  
32768 blocks per group, 32768 fragments per group  
8192 inodes per group  
Superblock backups stored on blocks:  
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,  
       4096000  
 
Writing inode tables: done  
Creating journal (32768 blocks): done  
Writing superblocks and filesystem accounting infORMation: done  
 
This filesystem will be automatically checked every 35 mounts or  
180 days, whichever comes first.  Use tune2fs -c or -i to override.  

4,创建目录,并挂载分区

代码如下:


[root@iZ94zz3wqciZ ~]# mkdir /mnt/fastdfs    //挂载目录  
[root@iZ94zz3wqciZ ~]# echo "/dev/xvdb1    /mnt/fastdfs    ext4    defaults    0 0" >> /etc/fstab   //重启会自动挂载  
[root@iZ94zz3wqciZ ~]# mount -a    //挂载所有目录  
 
[root@iZ94zz3wqciZ ~]# df  
Filesystem     1K-blocks     Used Available Use% Mounted on  
/dev/xvda1      20641404 14778404   4814476  76% /  
tmpfs             509300        0    509300   0% /dev/shm  
/dev/xvdb1      22694396   176064  21365516   1% /mnt/fastdfs    //新的分区已挂载  


到这儿,就把一块独立的硬盘加到系统当中了。这种扩容的方式操作简单,但是扩展性不强,不推荐这种扩容方式。

二,采用lvm的方式,进行硬盘扩容(推荐)
1,取消前面测试的挂载,并删除分区

代码如下:


[root@iZ94zz3wqciZ ~]# umount -a         //取消挂载  
 
[root@iZ94zz3wqciZ ~]# fdisk /dev/xvdb   //分区  
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').  
 
Command (m for help): d       //删除分区  
Selected partition 1  
 
Command (m for help): wq     //保存  
The partition table has been altered!  


2,安装lvm

代码如下:


[root@iZ94zz3wqciZ Nginx]# uname -a   //查看内核信息  
Linux iZ94zz3wqciZ 2.6.32-431.23.3.el6.x86_64 #1 SMP Thu Jul 31 17:20:51 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux  
 
[root@iZ94zz3wqciZ ~]# yum install lvm2 device-mapper   //安装 LVM2,2.6.9以后版本不用装device-mapper  
 
[root@iZ94zz3wqciZ nginx]# lsmod | grep dm_mod    //是否加载了dm_mod  
dm_mod                 84337  5 dm_mirror,dm_log  


lvm的安装,首先加载device-mapper模块,从linux内核2.6.9开始,device-mapper模块就已经包含在内,所以你只需加载即可。加载mapper模块:modprobe dm_mod。
3,创建lvm分区

代码如下:


[root@iZ94zz3wqciZ ~]# fdisk /dev/xvdb   //分区  
 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): l

0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
1  FAT12           39  Plan 9          82  Linux swap / So c1  DRDOS/sec (FAT-
2  XENIX root      3c  PartitionMagic  83  Linux           c4  DRDOS/sec (FAT-
3  XENIX usr       40  Venix 80286     84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
4  FAT16 <32M      41  PPC PReP Boot   85  Linux extended  c7  Syrinx
5  Extended        42  SFS             86  NTFS volume set da  Non-FS data
6  FAT16           4d  QNX4.x          87  NTFS volume set db  CP/M / CTOS / .
7  HPFS/NTFS       4e  QNX4.x 2nd part 88  Linux plaintext de  Dell Utility
8  AIX             4f  QNX4.x 3rd part 8e  Linux LVM       df  BootIt
9  AIX bootable    50  OnTrack DM      93  Amoeba          e1  DOS access
a  OS/2 Boot Manag 51  OnTrack DM6 Aux 94  Amoeba BBT      e3  DOS R/O
b  W95 FAT32       52  CP/M            9f  BSD/OS          e4  SpeedStor
c  W95 FAT32 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi eb  BeOS fs
e  W95 FAT16 (LBA) 54  OnTrackDM6      a5  FreeBSD         ee  GPT
f  W95 Ext'd (LBA) 55  EZ-Drive        a6  OpenBSD         ef  EFI (FAT-12/16/  
10  OPUS            56  Golden Bow      a7  NeXTSTEP        f0  Linux/PA-RISC b  
11  Hidden FAT12    5c  Priam Edisk     a8  Darwin UFS      f1  SpeedStor  
12  Compaq diagnost 61  SpeedStor       a9  NetBSD          f4  SpeedStor  
14  Hidden FAT16 <3 63  GNU HURD or Sys ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    64  Novell Netware  af  HFS / HFS+      fb  VMware VMFS  
17  Hidden HPFS/NTF 65  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE  
18  AST SmartSleep  70  DiskSecure Mult b8  BSDI swap       fd  Linux raid auto  
1b  Hidden W95 FAT3 75  PC/IX           bb  Boot Wizard hid fe  LANstep  
1c  Hidden W95 FAT3 80  Old Minix       be  Solaris boot    ff  BBT  
1e  Hidden W95 FAT1  
 
Command (m for help): n  
Command action  
  e   extended  
  p   primary partition (1-4)  
p  
Partition number (1-4): 1  
First cylinder (1-2871, default 1):  
Using default value 1  
Last cylinder, +cylinders or +size{K,M,G} (1-2871, default 2871):  
Using default value 2871  
 
Command (m for help): p  
 
Disk /dev/xvdb: 23.6 GB, 23622320128 bytes  
255 heads, 63 sectors/track, 2871 cylinders  
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 identifier: 0x27cc1f5a  
 
   Device Boot      Start         End      Blocks   Id  System  
/dev/xvdb1               1        2871    23061276   83  Linux      //不是lvm分区格式  
 
Command (m for help): t    //转换  
Selected partition 1  
Hex code (type L to list codes): 8e     //换成8e  
Changed system type of partition 1 to 8e (Linux LVM)  
 
Command (m for help): p  
 
Disk /dev/xvdb: 23.6 GB, 23622320128 bytes  
255 heads, 63 sectors/track, 2871 cylinders  
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 identifier: 0x27cc1f5a  
 
   Device Boot      Start         End      Blocks   Id  System  
/dev/xvdb1               1        2871    23061276   8e  Linux LVM     //现在lvm分区格式了  
 
Command (m for help): wq  
The partition table has been altered!  
 
Calling ioctl() to re-read partition table.  
Syncing disks.  


4,创建逻辑卷组,以及逻辑卷等

代码如下:


[root@iZ94zz3wqciZ ~]# pvcreate /dev/xvdb1     //创建物理卷  
 Physical volume "/dev/xvdb1" successfully created  
 
[root@iZ94zz3wqciZ ~]# vGCreate myfiles /dev/xvdb1    //创建逻辑卷组  
 Volume group "myfiles" successfully created  
 
[root@iZ94zz3wqciZ ~]# vgchange -ay myfiles   //激活逻辑卷组  
 0 logical volume(s) in volume group "myfiles" now active  
 
[root@iZ94zz3wqciZ ~]# vgdisplay myfiles | grep "Total PE"    //查看该卷组所有的PE  
 Total PE              5629  
 
[root@iZ94zz3wqciZ ~]# lvcreate -l 5629 -n fastdfs myfiles    //创建逻辑卷  
 Logical volume "fastdfs" created.

 
5,格式化逻辑卷

代码如下:


[root@iZ94zz3wqciZ ~]# mkfs.ext4 /dev/myfiles/fastdfs    //格式化逻辑卷  
mke2fs 1.41.12 (17-May-2010)  
Filesystem label=  
OS type: Linux  
Block size=4096 (log=2)  
Fragment size=4096 (log=2)  
Stride=0 blocks, Stripe width=0 blocks  
1441792 inodes, 5764096 blocks  
288204 blocks (5.00%) reserved for the super user  
First data block=0  
Maximum filesystem blocks=4294967296  
176 block groups  
32768 blocks per group, 32768 fragments per group  
8192 inodes per group  
Superblock backups stored on blocks:  
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,  
       4096000  
 
Writing inode tables: done  
Creating journal (32768 blocks): done  
Writing superblocks and filesystem accounting information: done  
 
This filesystem will be automatically checked every 39 mounts or  
180 days, whichever comes first.  Use tune2fs -c or -i to override.


6,设置自动挂载,并查看分区

代码如下:


[root@iZ94zz3wqciZ ~]# echo '/dev/myfiles/fastdfs     /mnt/fastdfs            ext4    defaults        0 0' >> /etc/fstab   //自动挂载  
[root@iZ94zz3wqciZ ~]# mount -a     //手动挂载  
[root@iZ94zz3wqciZ ~]# df  
Filesystem           1K-blocks     Used Available Use% Mounted on  
/dev/xvda1            20641404 14778608   4814272  76% /  
tmpfs                   509300        0    509300   0% /dev/shm  
/dev/mapper/myfiles-fastdfs  
                     22694396   176064  21365516   1% /mnt/fastdfs     //lvm逻辑卷已挂载  
 
[root@iZ94zz3wqciZ ~]# reboot     //操作完最好重启一下  


7,再扩容一块硬盘到已有逻辑卷

代码如下:


[root@iZ94zz3wqciZ ~]# fdisk /dev/xvdc   //详细过程同上,就不详细说明了  
 
[root@iZ94zz3wqciZ ~]# reboot  
 
[root@iZ94zz3wqciZ ~]# pvcreate /dev/xvdc1     //创建物理卷  
 Physical volume "/dev/xvdc1" successfully created  
 
[root@iZ94zz3wqciZ ~]# vgextend myfiles /dev/xvdc1    //将新硬盘加入卷组  
 Volume group "myfiles" successfully extended  
 
[root@iZ94zz3wqciZ ~]# vgdisplay myfiles | grep "Total PE"  //查看所有PE  
 Total PE              6907  
 
[root@iZ94zz3wqciZ ~]# lvresize -l 6907 /dev/myfiles/fastdfs  //重新规定大小  
 Size of logical volume myfiles/fastdfs changed from 21.99 GiB (5629 extents) to 26.98 GiB (6907 extents).  
 Logical volume fastdfs successfully resized  
 
[root@iZ94zz3wqciZ ~]# resize2fs /dev/myfiles/fastdfs    //重新规定大小  
resize2fs 1.41.12 (17-May-2010)  
Filesystem at /dev/myfiles/fastdfs is mounted on /mnt/fastdfs; on-line resizing required  
old desc_blocks = 2, new_desc_blocks = 2  
Performing an on-line resize of /dev/myfiles/fastdfs to 7072768 (4k) blocks.  
The filesystem on /dev/myfiles/fastdfs is now 7072768 blocks long.  
 
[root@iZ94zz3wqciZ ~]# df -h  
Filesystem            Size  Used Avail Use% Mounted on  
/dev/xvda1             20G   15G  4.6G  76% /  
tmpfs                 498M     0  498M   0% /dev/shm  
/dev/mapper/myfiles-fastdfs  
                      27G  172M   26G   1% /mnt/fastdfs       //新的5G硬盘加上去了  


如果是频繁的扩容硬盘的话,LVM是首选,扩展真的很方便。

感谢各位的阅读,以上就是“Linux系统下怎么对硬盘分区进行扩容”的内容了,经过本文的学习后,相信大家对Linux系统下怎么对硬盘分区进行扩容这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!

--结束END--

本文标题: Linux系统下怎么对硬盘分区进行扩容

本文链接: https://www.lsjlt.com/news/263135.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Linux系统下怎么对硬盘分区进行扩容
    这篇文章主要讲解了“Linux系统下怎么对硬盘分区进行扩容”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux系统下怎么对硬盘分区进行扩容”吧!硬盘快满了,加硬盘扩容,不管是独立的服务器...
    99+
    2023-06-12
  • Linux下怎么对分区进行扩容
    这篇文章主要介绍“Linux下怎么对分区进行扩容”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Linux下怎么对分区进行扩容”文章能帮助大家解决问题。查看磁盘下未分配的空间# 查看系统空间...
    99+
    2023-06-27
  • Linux系统下硬盘怎么分区
    这篇文章主要介绍“Linux系统下硬盘怎么分区”,在日常操作中,相信很多人在Linux系统下硬盘怎么分区问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Linux系统下硬盘怎么分区”的疑惑有所帮助!接下来,请跟...
    99+
    2023-06-10
  • Linux系统下怎么添加硬盘+分区+格式化
    这篇文章主要讲解了“Linux系统下怎么添加硬盘+分区+格式化”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux系统下怎么添加硬盘+分区+格式化”吧!在我们添加硬盘前,首先要了解lin...
    99+
    2023-06-10
  • win7系统下怎么进行磁盘分区
    磁盘是我们电脑中的重要储存设备,要想充分利用硬盘的存储空间就需要我们对其进行合理的分区,那么win7系统下怎么进行磁盘分区呢接下来小编给大家分享一下win7系统分区教程,有需要的小伙伴好好学习哦.1、首先我们右键单击桌面上的“计算机”图标,...
    99+
    2023-07-19
  • Linux系统下怎么添加新硬盘,分区,格式化
    本篇内容主要讲解“Linux系统下怎么添加新硬盘,分区,格式化”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux系统下怎么添加新硬盘,分区,格式化”吧!预备知识  在我们添加硬盘前,首先要...
    99+
    2023-06-10
  • 在Linux系统的VPS上怎么对硬盘进行分区、格式化和挂载
    本篇内容介绍了“在Linux系统的VPS上怎么对硬盘进行分区、格式化和挂载”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!这是这几天我在设置我...
    99+
    2023-06-12
  • Linux系统分区容量怎么扩充
    这篇文章主要讲解了“Linux系统分区容量怎么扩充”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux系统分区容量怎么扩充”吧!fedoa也用这么久了,越来越觉得windows慢了,虽然...
    99+
    2023-06-17
  • VMware重启添加scsi硬盘如何实现LVM对文件系统分区扩容
    本篇文章为大家展示了VMware重启添加scsi硬盘如何实现LVM对文件系统分区扩容,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。我们将基于LVM对文件系统分区进行扩容。1.预备工作:我们要知道LV...
    99+
    2023-06-28
  • Linux系统要怎么进行分区
    Linux系统要怎么进行分区,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。linux分区方法,不同的人有不同的方法,反正没有统一的方法。在分区方面,我觉得根据自...
    99+
    2023-06-05
  • 怎么在Win10系统中对机械硬盘进行提速
    怎么在Win10系统中对机械硬盘进行提速?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。详细如下:  1、打开我的电脑,然后选择要优化的盘符,右键点击该盘符,在弹出菜单中选择...
    99+
    2023-06-07
  • Win8.1系统下如何对磁盘进行分区便于分类加快读写的速度
      为什么要给磁盘进行分区?很多用户都不了解其中的缘由。对磁盘进行分区,一方面便于分类,另一方面也有助于加快读写的速度,是一个一举两得的举措,那么在Win8.1系统下如何对磁盘进行分区呢?   Win8.1...
    99+
    2022-06-04
    磁盘 分区 速度
  • Linux系统怎么使用fdisk命令进行分区
    Linux系统怎么使用fdisk命令进行分区,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Linux系统命令fdisk命令主要用于磁盘分区,分区之后的磁盘就从连...
    99+
    2023-06-28
  • 在Linux系统怎么正确的对U盘进行格式化
    这篇文章主要介绍了在Linux系统怎么正确的对U盘进行格式化,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。在Linux操作系统中如何对U盘进行格式化:在Linux操作系统中对...
    99+
    2023-06-16
  • 在Linux系统下怎么用Krita软件对照片进行编辑
    本篇内容介绍了“在Linux系统下怎么用Krita软件对照片进行编辑”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成! 图 1:侏儒山...
    99+
    2023-06-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作