Centos7磁盘挂载/扩容分区 /dev/mapper/centos-root

一、添加硬盘

1、关机虚拟机新增硬盘后开机

2、重启虚拟机后,使用lsblk命令查看磁盘情况

发现已经成功添加新硬盘sdb

3、使用fdisk /dev/sdb命令创建新分区


[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9533fd55.

Command (m for help):
磁盘分区完成

二、使用mkfs.ext4命令进行格式化

1、先使用lsblk命令查看分区表

[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   40G  0 disk
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   39G  0 part
  ├─centos-root 253:0    0   37G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0   60G  0 disk
└─sdb1            8:17   0   60G  0 part
sr0              11:0    1  973M  0 rom

2、发现新分区是sdb1(我只分了一个主分区,所以是sdb1。)然后我们对sdb1使用mkfs.ext4 /dev/sdb1命令进行格式化

[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3932160 inodes, 15728384 blocks
786419 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2164260864
480 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, 7962624, 11239424

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
至此格式化完成

三、挂载磁盘到某个目录

1、我以挂载到根分区的data目录为例:新建/data目录,挂载分区到/data目录(mount临时挂载,关机失效)

[root@localhost ~]# mkdir data
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/sdb1 /data

2、查看磁盘使用情况


[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   37G  4.9G   33G  14% /
/dev/sda1               1014M  194M  821M  20% /boot
overlay                   37G  4.9G   33G  14% /var/lib/docker/overlay2/9856e4fb9e727eee69b32053f8f5f0d23b9fd137a4ab7f5a1e26cde0c5473605/merged
overlay                   37G  4.9G   33G  14% /var/lib/docker/overlay2/478f1bbc15f47cb5f43988a340b0abe8a4580ec4980e22c080081e3617721c5e/merged
overlay                   37G  4.9G   33G  14% /var/lib/docker/overlay2/026263a05440f37b8a13ec0455748b9da2b23433330139ab6e43fecafc70f103/merged
overlay                   37G  4.9G   33G  14% /var/lib/docker/overlay2/065bbf81a0e1bc7b24ad11ddbb03bae20c5aa13068fbfdde58271c5c5ae1deb5/merged
overlay                   37G  4.9G   33G  14% /var/lib/docker/overlay2/a9bd39fc34004486ee69e62bff06b04d649a137aca9a45cd32bfcee80ba5a53b/merged
tmpfs                    378M     0  378M   0% /run/user/0
/dev/sdb1                 59G   53M   56G   1% /data
[root@localhost ~]#
虚拟机挂载磁盘操作结束

3、如果需要开机自动挂载可以vi /etc/fstab新增一条代码使挂载永久生效

/dev/sdb1 /data xfs defaults 0 0

四、新硬盘扩容到/dev/mapper/centos-root根分区

扩容/dev/mapper/centos-root,前八步相同,将第九步骤换成第十步骤就可以了

1、创建pv(给刚刚新建的分区 /dev/sdb1)

[root@localhost ~]# pvcreate /dev/sdb1
WARNING: ext4 signature detected on /dev/sdb1 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sdb1.
  Physical volume "/dev/sdb1" successfully created.

2、把pv加入vg中,相当于扩充vg的大小,先使用vgs查看vg组,然后扩展vg,使用vgextend命令

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree
  centos   1   2   0 wz--n- <39.00g 4.00m
[root@localhost ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

3、我们成功把vg卷扩展了,在用vgs查看一下

[root@localhost ~]# vgs
  VG     #PV #LV #SN Attr   VSize  VFree
  centos   2   2   0 wz--n- 98.99g 60.00g

4、扩展lv,使用lvextend命令,查看lv大小,df -h 发现centos-root空间没有变化


[root@localhost ~]# lvextend -L +60G /dev/mapper/centos-root
  Size of logical volume centos/root changed from 56.99 GiB (14590 extents) to 96.99 GiB (24830 extents).
  Logical volume centos/root successfully resized.
[root@localhost ~]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 96.99g
  swap centos -wi-ao----  2.00g

5、那么我们要使用命令使系统重新读取大小,再使用df -h查看

root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2424320 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9697280, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4735, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9697280 to 25425920

到这里我们就成功扩展了

Centos7磁盘挂载/扩容分区 /dev/mapper/centos-root
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇