ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux主机lv操作篇-新增homelv

2021-05-18 12:08:27  阅读:226  来源: 互联网

标签:homelv xuhs dev lv Linux home 512 root


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

root@xuhs:/root>cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)
root@xuhs:/root>

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

root@xuhs:/>cd /
root@xuhs:/>tar zcvf home.tar.gz home
root@xuhs:/>ls -ltr
total 14428
........
-rw-r--r--    1 root root 14744919 May 17 14:27 home.tar.gz
........
root@xuhs:/>

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

root@xuhs:/>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保存退出,操作如下:

root@xuhs:/>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.
root@xuhs:/>

4、生效分区配置:

root@xuhs:/>partprobe 
root@xuhs:/>

5、创建pv:

root@xuhs:/>pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created.
root@xuhs:/>pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sda2  hdvg lvm2 a--  <18.97g      0 
  /dev/sdb1       lvm2 ---  <10.00g <10.00g
root@xuhs:/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
root@xuhs:/root> 

6、创建vg:

root@xuhs:/>vgcreate dbvg /dev/sdb1
  Volume group "dbvg" successfully created
root@xuhs:/>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:

root@xuhs:/>lvcreate -L 8G -n homelv /dev/dbvg
  Logical volume "homelv" created.
root@xuhs:/>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进行格式化:

root@xuhs:/>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配置:

root@xuhs:/>
root@xuhs:/>cat>>/etc/fstab
/dev/dbvg/homelv /home                   xfs    defaults        1 2
^C
root@xuhs:/>

10、挂载分区:

root@xuhs:/>mount -a
root@xuhs:/>df -h
Filesystem                 Size  Used Avail Use% Mounted on
......
/dev/mapper/dbvg-homelv    8.0G   33M  8.0G   1% /home
......

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

root@xuhs:/home>cd /
root@xuhs:/>tar xvzf home.tar.gz
root@xuhs:/>cd /home
root@xuhs:/home>ls -ltr
total 0
drwx------ 4 xuhs users 127 May 15 15:51 xuhs
root@xuhs:/home>

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

root@xuhs:/root>useradd -g users -d /home/test  test
echo '1qaz@WSX' | passwd --stdin testroot@xuhs:/root>echo '1qaz@WSX' | passwd --stdin test
Changing password for user test.
passwd: all authentication tokens updated successfully.
root@xuhs:/root>cd /home
root@xuhs:/home>ls -ltr
drwx------ 3 test users  78 May 17 15:16 test
root@xuhs:/home>

标签:homelv,xuhs,dev,lv,Linux,home,512,root
来源: https://blog.51cto.com/u_15182035/2782987

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有