运维开发网
广告位招商联系QQ:123077622
 
广告位招商联系QQ:123077622

Linux主机lv操作篇-新增homelv

运维开发网 https://www.qedev.com 2021-05-18 14:36 出处:51CTO 作者:徐洪升
Linux主机lv操作篇-新增homelv,记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux主机新增homelv的方法,欢迎大家评论留言。最近资源池新分配一批虚机,发现没有homelv,fdisk-l查看分了500G不到的存储,本次操作就是把500G的存储全部用来划homelv(以下是新增homelv的操作,均在试验机上操作,并且在实际工程环境中有验证过,目前配置过的OS有centos7.7)。一、主机环境:1

记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了Linux主机新增homelv的方法,欢迎大家评论留言。最近资源池新分配一批虚机,发现没有homelv,fdisk -l查看分了500G不到的存储,本次操作就是把500G的存储全部用来划homelv(以下是新增homelv的操作,均在试验机上操作,并且在实际工程环境中有验证过,目前配置过的OS有centos7.7)。

一、主机环境:

1、系统版本:

[email protected]:/root>cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
[email protected]:/root>

二、操作

1、进入根目录下,备份home目录:

[email protected]:/>cd /
[email protected]:/>tar zcvf home.tar.gz home
[email protected]:/>ls -ltr
total 14428
........
-rw-r--r--    1 root root 14744919 May 17 14:27 home.tar.gz
........
[email protected]:/>

2、fdisk -l查看分区表路径,如下:

[email protected]:/>fdisk -l 
......
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
......

3、开始创建分区表,因为是把整个sdb划homelv,所以第一个选项选择n后,后面选项默认即可,操作完成后,选择w保存退出,操作如下:

[email protected]:/>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 0x47cd845b.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[email protected]:/>

4、生效分区配置:

[email protected]:/>partprobe 
[email protected]:/>

5、创建pv:

[email protected]:/>pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created.
[email protected]:/>pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sda2  hdvg lvm2 a--  <18.97g      0 
  /dev/sdb1       lvm2 ---  <10.00g <10.00g
[email protected]:/root>pvs
  PV         VG   Fmt  Attr PSize   PFree 
  /dev/sda2  hdvg lvm2 a--  <18.97g     0 
  /dev/sdb1  dbvg lvm2 a--  <10.00g <2.00g
[email protected]:/root> 

6、创建vg:

[email protected]:/>vgcreate dbvg /dev/sdb1
  Volume group "dbvg" successfully created
[email protected]:/>vgs
  VG   #PV #LV #SN Attr   VSize   VFree  
  dbvg   1   0   0 wz--n- <10.00g <10.00g
  hdvg   1   6   0 wz--n- <18.97g      0 

7、创建homelv:

[email protected]:/>lvcreate -L 8G -n homelv /dev/dbvg
  Logical volume "homelv" created.
[email protected]:/>lvs
  LV       VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  homelv   dbvg -wi-a-----   8.00g                                                    
  homelv   hdvg -wi-ao----  <1.19g                                                    
  rootlv   hdvg -wi-ao---- <12.22g                                                    
  swaplv   hdvg -wi-ao----   2.00g                                                    
  tmplv    hdvg -wi-ao----  <1.19g                                                    
  varloglv hdvg -wi-ao----  <1.19g                                                    
  varlv    hdvg -wi-ao----  <1.19g 

8、格式化磁盘,对homelv进行格式化:

[email protected]:/>mkfs.xfs  /dev/dbvg/homelv
meta-data=/dev/dbvg/homelv       isize=512    agcount=4, agsize=524288 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2097152, 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

9、写入fstab配置:

[email protected]:/>
[email protected]:/>cat>>/etc/fstab
/dev/dbvg/homelv /home                   xfs    defaults        1 2
^C
[email protected]:/>

10、挂载分区:

[email protected]:/>mount -a
[email protected]:/>df -h
Filesystem                 Size  Used Avail Use% Mounted on
......
/dev/mapper/dbvg-homelv    8.0G   33M  8.0G   1% /home
......

11、恢复备份,即可完成新建homelv

[email protected]:/home>cd /
[email protected]:/>tar xvzf home.tar.gz
[email protected]:/>cd /home
[email protected]:/home>ls -ltr
total 0
drwx------ 4 xuhs users 127 May 15 15:51 xuhs
[email protected]:/home>

12、测试验证,创建一个文件或者新建一个账号:

[email protected]:/root>useradd -g users -d /home/test  test
echo [email protected]' | passwd --stdin [email protected]:/root>echo [email protected]' | passwd --stdin test
Changing password for user test.
passwd: all authentication tokens updated successfully.
[email protected]:/root>cd /home
[email protected]:/home>ls -ltr
drwx------ 3 test users  78 May 17 15:16 test
[email protected]:/home>

扫码领视频副本.gif

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号