一、主机环境:
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>