Linux主机lv操作篇-新增homelv
16lz
2021-05-18
记录一些自己的心得以及方法,本着共同学习,互相进步为目的。本次总结了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 homeroot@xuhs:/>ls -ltrtotal 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 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes......
3、开始创建分区表,因为是把整个sdb划homelv,所以第一个选项选择n后,后面选项默认即可,操作完成后,选择w保存退出,操作如下:
root@xuhs:/>fdisk /dev/sdbWelcome 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 tableBuilding a new DOS disklabel with disk identifier 0x47cd845b.Command (m for help): nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): Using default response pPartition number (1-4, default 1): First sector (2048-20971519, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519Partition 1 of type Linux and of size 10 GiB is setCommand (m for help): wThe 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.00groot@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.00groot@xuhs:/root>
6、创建vg:
root@xuhs:/>vgcreate dbvg /dev/sdb1 Volume group "dbvg" successfully createdroot@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/homelvmeta-data=/dev/dbvg/homelv isize=512 agcount=4, agsize=524288 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0data = bsize=4096 blocks=2097152, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0
9、写入fstab配置:
root@xuhs:/>root@xuhs:/>cat>>/etc/fstab/dev/dbvg/homelv /home xfs defaults 1 2^Croot@xuhs:/>
10、挂载分区:
root@xuhs:/>mount -aroot@xuhs:/>df -hFilesystem 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.gzroot@xuhs:/>cd /homeroot@xuhs:/home>ls -ltrtotal 0drwx------ 4 xuhs users 127 May 15 15:51 xuhsroot@xuhs:/home>
12、测试验证,创建一个文件或者新建一个账号:
root@xuhs:/root>useradd -g users -d /home/test testecho '1qaz@WSX' | passwd --stdin testroot@xuhs:/root>echo '1qaz@WSX' | passwd --stdin testChanging password for user test.passwd: all authentication tokens updated successfully.root@xuhs:/root>cd /homeroot@xuhs:/home>ls -ltrdrwx------ 3 test users 78 May 17 15:16 testroot@xuhs:/home>
©著作权归作者所有:来自51CTO博客作者徐洪升的原创作品,如需转载,请注明出处,否则将追究法律责任好知识,才能预见未来
赞赏
0人进行了赞赏支持
更多相关文章
- 微软开源Scalar,提升操作巨型Git仓库的速度
- BlueStore checksum机制
- 【PHP文件操作】文件目录操作基本操作及文件的上传和下载
- K8S CronJob简单入门,和手动重复操作Say Goodbye!
- PHP:MySQL常用DDL数据定义语言, DML数据库操作语言,PDO连接数据
- 【PHP 面向对象】面向对象(OOP)编程之PDO对象操作数据库知识点归
- 面向对象的相关操作
- MySQL数据库基本操作常用命令详解
- 4-29数组系统函数的操作