linux磁盘扩容、挂载[fdisk、parted]

一、扩容-fdisk <2G

  • 1、fdisk -l查看磁盘情况,新增/dev/sdb
  • 2、进行磁盘分区 fdisk /dev/sdb
  • 3、创建物理卷,pvcreate /dev/sdb1,pvdisplay查看扩展的磁盘

  • 4、使用vgextend命令进行动态扩展,vgextend centos /dev/sdb1,pvdisplay查看扩展的磁盘

  • 5、将空闲的磁盘扩展到分区,lvextend -l +100%FREE /dev/mapper/centos-root

    • lvextend与lvresize的区别:lvextend只能增加一个体积的大小,而lvresize可以增加或减小它的大小
  • 6、重新加载逻辑卷,使LV扩容生效

    • xfs_growf与resize2fs的区别:xfs_growfs命令是扩展xfs文件系统,resize2fs是扩展ext4文件系统

 二、挂载-fdisk <2G

  • 1、fdisk -l查看磁盘情况,新增/dev/sdb

  • 2、进行磁盘分区
  • 3、格式化分区

    • mkfs.xfs /dev/sdb1、mkfs.ext4 /dev/sdb1
  • 4、挂载
  • 5、设置重启挂载不失效。

    • vim /etc/fstab,把刚格式化就完成的id添加进来。修改成功后重启即可或者命令行输入mount -a 该命令会把配置文件中的所有分区重新挂载一遍
    • mount -a 的意思是将/etc/fstab的所有内容重新加载。
    • mount 是可以显示/etc/fstab的内容。
    • mount -a 是自动挂载 /etc/fstab 里面的东西。
    • 不过这东西开机时已经挂载了,你如果没有修改 fstab 增加新的东西那就肯定没输出。 mount -a 会忽略所有已经完成的操作,也就是开机时 fstab 已经挂载后,而且你没有修改 fstab 。你再运行 mount -a ,他会自动忽略全部 fstab 内容

三、扩容-parted >2G

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a597b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@localhost ~]# part
parted     partprobe  partx      
[root@localhost ~]# part
parted     partprobe  partx      
[root@localhost ~]# parted /dev/sdb
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) mkpart                                                           
Partition name?  []? sdb1                                                 
File system type?  [ext2]?                                                
Start? 0                                                                  
End? 100%                                                                 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdb1

(parted) toggle 1 lvm                                                     
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdb1  lvm

(parted) q                                                                
Information: You may need to update /etc/fstab.

[root@localhost ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <9.00 GiB
  PE Size               4.00 MiB
  Total PE              2303
  Alloc PE / Size       2303 / <9.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               BP6Pfn-Ft5e-fwqV-2E1M-Srkm-ckzc-1dv7lD
   
[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended
[root@localhost ~]# lvdis[lay
> ^C
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                We7rNW-MicQ-SiYp-e3ge-Ls6x-Xu9K-H6xS5W
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                OfMRMu-zrIr-pxxn-HVP0-WSgB-4Uio-cfft1P
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost ~]# lvextend -l +100%free /dev/centos/root 
  Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 17.99 GiB (4606 extents).
  Logical volume centos/root successfully resized.
[root@localhost ~]# mkfs
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost ~]# xfs_growfs /dev/centos/root 
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=524032 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2096128, 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 2096128 to 4716544
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   18G  1.3G   17G   7% /
/dev/sda1               1014M  151M  864M  15% /boot
tmpfs                    1.6G     0  1.6G   0% /run/user/0

四、挂载-parted >2G

[root@localhost ~]# fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a597b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    20971519     9436160   8e  Linux LVM
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: 6DE0E303-988A-4007-AA55-BFB4B61746A8


#         Start          End    Size  Type            Name
 1           34     20971486     10G  Linux LVM       sdb1

Disk /dev/sdc: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 19.3 GB, 19318964224 bytes, 37732352 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@localhost ~]# parted /dev/sdc
GNU Parted 3.1
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
(parted) mkpart                                                           
Partition name?  []? sdc1                                                 
File system type?  [ext2]?                                                
Start? 0                                                                  
End? 100%                                                                 
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? i                                                          
(parted) p
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdc1

(parted) toggle 1 lvm                                                     
(parted) p                                                                
Model: VMware Virtual disk (scsi)
Disk /dev/sdc: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      17.4kB  10.7GB  10.7GB               sdc1  lvm

(parted) q                                                                
Information: You may need to update /etc/fstab.

[root@localhost ~]# pvcreate /dev/sdc1                                    
  Physical volume "/dev/sdc1" successfully created.
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  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               18.99 GiB
  PE Size               4.00 MiB
  Total PE              4862
  Alloc PE / Size       4862 / 18.99 GiB
  Free  PE / Size       0 / 0   
  VG UUID               BP6Pfn-Ft5e-fwqV-2E1M-Srkm-ckzc-1dv7lD
   
[root@localhost ~]# vgcreate test /dev/sdc1 
  Volume group "test" successfully created
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                We7rNW-MicQ-SiYp-e3ge-Ls6x-Xu9K-H6xS5W
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 2
  LV Size                1.00 GiB
  Current LE             256
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                OfMRMu-zrIr-pxxn-HVP0-WSgB-4Uio-cfft1P
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2023-05-25 14:59:25 +0800
  LV Status              available
  # open                 1
  LV Size                17.99 GiB
  Current LE             4606
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
[root@localhost ~]# lvcreate -l +100%free test -n data
  Logical volume "data" created.
[root@localhost ~]# mkfs
mkfs         mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs     
[root@localhost ~]# mkfs.xfs /dev/test/data
meta-data=/dev/test/data         isize=512    agcount=4, agsize=655104 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2620416, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/test/data /data/
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   18G  1.3G   17G   7% /
/dev/sda1               1014M  151M  864M  15% /boot
tmpfs                    1.6G     0  1.6G   0% /run/user/0
/dev/mapper/test-data     10G   33M   10G   1% /data
[root@localhost ~]# vim /etc/fstab 
-bash: vim: command not found
[root@localhost ~]# vi /etc/fstab

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Linux 磁盘扩容是一项非常重要的任务,可以帮助我们扩展存储容量,满足应用程序和数据的需求。下面是一个关于Linux磁盘扩容的综合指南。 首先,我们需要了解磁盘的基本概念和术语。在Linux中,磁盘被分为多个分区,每个分区都有自己的文件系统。我们需要考虑的主要问题是如何扩展已有分区的大小或添加新的磁盘。 对于已有分区的扩容,我们可以使用文件系统工具如resize2fs来增加分区的大小。首先,我们需要确保分区上没有挂载任何文件系统,然后运行resize2fs命令指定新的大小。这样,我们就可以在不丢失任何数据的情况下扩展分区的大小。 如果想要添加新的磁盘,我们需要对磁盘进行分区、格式化和挂载。首先,我们使用fdiskparted等工具来分区。接下来,我们使用mkfs命令来格式化分区为所需的文件系统类型。最后,我们可以使用mount命令将新的分区挂载到目标目录下,使其能够被访问。 另外,我们还可以通过逻辑卷管理器(LVM)来管理磁盘。LVM可以将多个物理磁盘划分为一个逻辑卷组,并在其上创建逻辑卷。通过调整逻辑卷组和逻辑卷的大小,我们可以实现磁盘扩容和管理。 除了硬盘扩容,我们还可以使用网络文件系统(NFS)或分布式文件系统(如GlusterFS或Ceph)来实现磁盘扩容和共享。这些文件系统可以将多个磁盘上的空间合并为一个逻辑存储空间,并提供给多个计算机共享使用。 在进行磁盘扩容操作之前,我们需要备份重要数据,并确保系统和应用程序的正常运行。此外,我们还应该仔细阅读相关文档和教程,并根据实际情况选择最适合的扩容方案。 总之,Linux磁盘扩容是一项重要的技术任务,需要仔细规划和执行。通过合理使用文件系统工具、LVM和网络文件系统,我们可以有效地扩展和管理磁盘空间,满足系统和应用程序的需求。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值