linux硬盘不够,格式化新加的硬盘并且设置开机挂载

在vmware,virtualbox等虚拟化软件中,可以模拟硬盘扩展, 当空间不足时,可以添加一块新的硬盘,然后分区,格式化,并且挂载使用

1, 硬盘分区, 格式化, 挂载

[root@s101 ~]#  history

  739  fdisk -l      #查看新增的硬盘
  740  fdisk /dev/sdb   #分区 ,p ,1 , w 
  741  fdisk -l             # 查看是否分区成功: /dev/sdb1

  742  mkfs.ext4 /dev/sdb1  # 格式化分区

  743  mkdir /mysdb    #创建目录,挂载到该分区
  744  du -h  /mysdb   #检查此目录可用空间,是否等于该硬盘大小
  745  mount /dev/sdb1 /mysdb  #可设置开机挂载: echo "/dev/sdb1 /mysdb ext4 defaults 0 0" >> /etc/fstab

2, 硬盘分区, 格式化,扩展/分区

上面说的是把硬盘挂载到某个新创建的目录中, 然后进行使用, 有时候的需求是为了解决已有的分区磁盘不够用,所以可以进行如下操作

[root@s101 ~]# pvcreate /dev/sdb
  Can't open /dev/sdb1 exclusively.  Mounted filesystem?
[root@s101 ~]# umount /dev/sdb
[root@s101 ~]# pvcreate /dev/sdb      						   #####1,物理卷:使用新增的分区,创建为物理卷
  Physical volume "/dev/sdb" successfully created
  
  
[root@s101 ~]# vgscan 
  Reading all physical volumes.  This may take a while...
  Found volume group "vg_test" using metadata type lvm2
  
[root@s101 ~]# vgextend vg_test /dev/sdb           		    #####2,卷组:扩容指定卷组
  Volume group "vg_test" successfully extended
[root@s101 ~]# lvextend -L +118G /dev/mapper/vg_test-lv_root   
[root@s101 ~]##lvextend -l +100%FREE  /dev/mapper/vg_test-lv_root    #####3,逻辑卷:扩容指定分区   
  Size of logical volume vg_test/lv_root changed from 50.00 GiB (12800 extents) to 168.00 GiB (43008 extents).
  Logical volume lv_root successfully resized.
  
[root@s101 ~]# resize2fs -f /dev/mapper/vg_test-lv_root 	    #####4,ext4/ext3 文件系统:扩容文件系统
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_test-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 11
Performing an on-line resize of /dev/mapper/vg_test-lv_root to 44040192 (4k) blocks.
The filesystem on /dev/mapper/vg_test-lv_root is now 44040192 blocks long.

#错误补充:resize2fs -f /dev/cl/root 执行报错   ===》cent7默认使用xfs文件系统
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.
#执行修复也报错: e2fsck -f /dev/mapper/centos-root  ===》cent7默认使用xfs文件系统
e2fsck 1.42.9 (28-Dec-2013)
/dev/mapper/centos-root is mounted.
e2fsck: Cannot continue, aborting.
#通过xfs扩容磁盘命令解决上述问题: xfs_growfs /dev/cl/root


[root@s101 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_test-lv_root
                      166G   41G  116G  27% /  				    ######5 ,磁盘166G:  【50G】变大了116G
tmpfs                 5.0G  8.0K  5.0G   1% /dev/shm
/dev/sda1             477M   41M  412M   9% /boot
/dev/mapper/vg_test-lv_home
                       45G   52M   43G   1% /home
cm_processes          5.0G  7.2M  5.0G   1% /opt/cm-5.12.0/run/cloudera-scm-agent/process

你可能感兴趣的:(linux系统)