闲暇时也许会更新吧

0%

LVM的基本使用方法

LVM是Logical Volume Manager,逻辑卷管理器,逻辑卷类似Windows下的跨区卷吧。

原先我一直觉得LVM用处有限,自己没用上,一直没用,也就一直没写怎么用,后来发现还是挺有用的,尤其是搭配RAID来使用。

有几个概念先了解一下:

名称 英文 缩写 解释
物理存储介质 - - 在系统里一般是硬盘,也可以是块存储设备
物理卷 PhysicalVolume PV 磁盘的分区转化来的
卷组 VolumeGroup VG 物理卷组成的组,在LVM里等同于虚拟磁盘的意思
逻辑卷 LogicalVolume LV 建立于卷组之上,在LVM里等同于虚拟分区的意思
- PhysicalExtents PE -
- LogicalExtents LE -

LVM大致上的概念就是把一个或多个物理磁盘的一个或多个分区合并在一起,称作卷组,也可以理解为变成了一块更大的虚拟磁盘。

但是物理磁盘的分区不能直接合并到卷组里,需要转化,而转化之后的分区就称为物理卷。

然后再创建逻辑卷,就相当于在这块更大的虚拟磁盘上划分分区。

然后逻辑卷就可以格式化,挂载等基本操作。

而PE和LE相当于卷组和逻辑卷的块,卷组大小=PE的大小xPE的数量,同理,逻辑卷的大小=LE的大小xLE的数量,PE默认4M,LE大小不知道是继承PE还是不继承,反正PE默认4M的情况下,LE默认也是4M。小了影响性能,大了占空间,没有专一用途,还是默认不设最好。

逻辑卷的创建与使用

首先创建要加入逻辑卷的分区,这里是新添加的sdb盘,整盘分一个分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
linux-wugz:/home/lengqing # fdisk /dev/sdb

Welcome to fdisk (util-linux 2.33.1).
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.
Created a new DOS disklabel with disk identifier 0x2f5191a8.

Command (m for help): g
Created a new GPT disklabel (GUID: 8B7DFDAA-0514-0146-9F52-1FDCF9F3D6E5).

Command (m for help): n
Partition number (1-128, default 1): 1
First sector (2048-41943006, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006):

Created a new partition 1 of type 'Linux filesystem' and of size 20 GiB.

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): L

Partition type (type L to list all types): 31
Changed type of partition 'Linux filesystem' to 'Linux LVM'.

Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 8B7DFDAA-0514-0146-9F52-1FDCF9F3D6E5

Device Start End Sectors Size Type
/dev/sdb1 2048 41943006 41940959 20G Linux LVM

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

然后将sdb1分区转化为物理卷

1
2
linux-wugz:/home/lengqing # pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.

使用物理卷/dev/sdb1创建名为VG1的卷组

1
2
linux-wugz:/home/lengqing # vgcreate VG1 /dev/sdb1
Volume group "VG1" successfully created

然后可以查看已有的卷组,我这里装系统就用了LVM,所以有个系统默认的system卷组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
linux-wugz:/home/lengqing # vgs
VG #PV #LV #SN Attr VSize VFree
VG1 1 0 0 wz--n- 20.00g 20.00g
system 1 1 0 wz--n- 15.99g 0
linux-wugz:/home/lengqing # vgdisplay
--- Volume group ---
VG Name system
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4093
Alloc PE / Size 4093 / 15.99 GiB
Free PE / Size 0 / 0
VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L

--- Volume group ---
VG Name VG1
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 20.00 GiB
PE Size 4.00 MiB
Total PE 5119
Alloc PE / Size 0 / 0
Free PE / Size 5119 / 20.00 GiB
VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc

这里是4M的PE,总共5119个PE,离显示的20.00GiB还差4MiB

然后在VG1上创建名为LV1的逻辑卷

1
2
linux-wugz:/home/lengqing # lvcreate -l 5119 -n LV1 VG1
Logical volume "LV1" created.

这里使用-l的参数,直接分配PE数量,也可以使用-L的参数,直接分配空间大小。但是实际可分配的空间不足以分配,比如显示20.00GiB,实际可分配空间只有5119x4MiB=20476MiB=19.996GiB,直接分配20G就会报错。

到这里就已经创建好逻辑卷了,查看一下,这里还是有一个是系统创建的逻辑卷,叫root

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
linux-wugz:/home/lengqing # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
LV1 VG1 -wi-a----- 20.00g
root system -wi-ao---- 15.99g
linux-wugz:/home/lengqing # lvdisplay
--- Logical volume ---
LV Path /dev/system/root
LV Name root
VG Name system
LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw
LV Write Access read/write
LV Creation host, time install, 2019-10-04 00:06:45 +0800
LV Status available
# open 1
LV Size 15.99 GiB
Current LE 4093
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:0

--- Logical volume ---
LV Path /dev/VG1/LV1
LV Name LV1
VG Name VG1
LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh
LV Write Access read/write
LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800
LV Status available
# open 0
LV Size 20.00 GiB
Current LE 5119
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:1

然后对逻辑卷LV1进行格式化与挂载,需要注意的是xfs只能扩容,不能缩容,建议使用ext4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
linux-wugz:/home/lengqing # mkfs.xfs /dev/VG1/LV1
meta-data=/dev/VG1/LV1 isize=512 agcount=4, agsize=1310464 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=0, rmapbt=0
= reflink=0
data = bsize=4096 blocks=5241856, 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
linux-wugz:/home/lengqing # mkdir /mnt/lvm
linux-wugz:/home/lengqing # mount /dev/VG1/LV1 /mnt/lvm
linux-wugz:/home/lengqing # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 8.0K 2.0G 1% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 9.4M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/system-root 16G 7.5G 8.6G 47% /
tmpfs 394M 16K 394M 1% /run/user/1000
/dev/mapper/VG1-LV1 20G 53M 20G 1% /mnt/lvm

要想开机挂载,在/etc/fstab中加一行就可以了

/dev/mapper/VG1-LV1 /mnt/lvm xfs defaults 0 1

到这里为止,逻辑卷就可以正常用了,往其中添加一份文件,检查卸载逻辑卷后文件是不是不在了,以及后期逻辑卷的调整后此文件是不是还在

1
2
3
linux-wugz:/home/lengqing # echo 'lengqinglvm' > /mnt/lvm/lengqinglvm
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvm
lengqinglvm

逻辑卷的扩容

对新加入的磁盘sdc创建分区sdc1,转化物理卷,并添加到卷组VG1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
linux-wugz:/home/lengqing # fdisk /dev/sdc

Welcome to fdisk (util-linux 2.33.1).
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.
Created a new DOS disklabel with disk identifier 0xe5b9393b.

Command (m for help): g
Created a new GPT disklabel (GUID: F8A76081-C61D-6A41-A62E-F39B89C0D886).

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-41943006, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-41943006, default 41943006):

Created a new partition 1 of type 'Linux filesystem' and of size 20 GiB.

Command (m for help): t
Selected partition 1
Partition type (type L to list all types): 31
Changed type of partition 'Linux filesystem' to 'Linux LVM'.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

linux-wugz:/home/lengqing # fdisk /dev/sdc -l
Disk /dev/sdc: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: F8A76081-C61D-6A41-A62E-F39B89C0D886

Device Start End Sectors Size Type
/dev/sdc1 2048 41943006 41940959 20G Linux LVM
linux-wugz:/home/lengqing # pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
linux-wugz:/home/lengqing # vgextend VG1 /dev/sdc1
Volume group "VG1" successfully extended

此时查看卷组VG1,此时大小已经变为了39.99G,剩余空间20.00G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
linux-wugz:/home/lengqing # vgs
VG #PV #LV #SN Attr VSize VFree
VG1 2 1 0 wz--n- 39.99g 20.00g
system 1 1 0 wz--n- 15.99g 0
linux-wugz:/home/lengqing # vgdisplay
--- Volume group ---
VG Name system
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4093
Alloc PE / Size 4093 / 15.99 GiB
Free PE / Size 0 / 0
VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L

--- Volume group ---
VG Name VG1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 5119 / 20.00 GiB
Free PE / Size 5119 / 20.00 GiB
VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc

将剩余空间分配到逻辑卷LV1,注意+不能省,加号代表加空间,而不带加号代表就分配这么多

1
2
3
linux-wugz:/home/lengqing # lvextend -l +5119 /dev/VG1/LV1
Size of logical volume VG1/LV1 changed from 20.00 GiB (5119 extents) to 39.99 GiB (10238 extents).
Logical volume VG1/LV1 successfully resized.

此时逻辑卷文件系统仍然是20G,需要调整文件系统大小才会改变

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
linux-wugz:/home/lengqing # xfs_growfs /mnt/lvm/
meta-data=/dev/mapper/VG1-LV1 isize=512 agcount=4, agsize=1310464 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1 spinodes=0 rmapbt=0
= reflink=0
data = bsize=4096 blocks=5241856, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 5241856 to 10483712
linux-wugz:/home/lengqing # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 8.0K 2.0G 1% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 9.4M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/system-root 16G 7.1G 8.9G 45% /
tmpfs 394M 12K 394M 1% /run/user/1000
/dev/mapper/VG1-LV1 40G 74M 40G 1% /mnt/lvm

需要注意的是xfs扩容只能在挂载的情况下,命令后面只能跟挂载点,不能直接跟设备名,例如这样

1
2
linux-wugz:/home/lengqing # xfs_growfs /dev/mapper/VG1-LV1
xfs_growfs: /dev/mapper/VG1-LV1 is not a mounted XFS filesystem

之前创建的文件仍然正常

1
2
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvm
lengqinglvm

逻辑卷的缩容

由于xfs不能缩容,所以还得换ext4来演示((⊙﹏⊙)早知道就不用xfs了)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
linux-wugz:/home/lengqing # umount /mnt/lvm
linux-wugz:/home/lengqing # mkfs.ext4 /dev/mapper/VG1-LV1
mke2fs 1.43.8 (1-Jan-2018)
/dev/mapper/VG1-LV1 contains a xfs file system
Proceed anyway? (y,N) y
Creating filesystem with 10483712 4k blocks and 2621440 inodes
Filesystem UUID: cb51dc65-ffb4-4180-b886-ddec1a723a3b
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done

linux-wugz:/home/lengqing # mount /dev/mapper/VG1-LV1 /mnt/lvm/

要开机挂载的还得改一下/etc/fstab

/dev/mapper/VG1-LV1 /mnt/lvm ext4 defaults 0 1

然后还是添加一份文件,检查缩容后文件是否正常

1
2
3
linux-wugz:/home/lengqing # echo 'lengqinglvmext4' > /mnt/lvm/lengqinglvmext4
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvmext4
lengqinglvmext4

卸载分区并检查文件系统,卸载时工作目录不能在挂载点内

1
2
3
4
5
6
7
8
9
linux-wugz:/home/lengqing #  umount /mnt/lvm
linux-wugz:/home/lengqing # e2fsck -f /dev/mapper/VG1-LV1
e2fsck 1.43.8 (1-Jan-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VG1-LV1: 12/2621440 files (0.0% non-contiguous), 242383/10483712 blocks

测试缩减逻辑卷,-t代表测试,需要注意的是只能按PE的整数倍来缩减,因为PE是最小存储单元,不能分配半个或者零点几个,这里PE是4M,按4M的整数倍都可以,注意不带减号是缩减到15G,而带了-是缩减15G

1
2
3
4
5
6
7
linux-wugz:/home/lengqing # lvreduce -L 15G /dev/VG1/LV1 -t
TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
WARNING: Reducing active logical volume to 15.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce VG1/LV1? [y/n]: y
Size of logical volume VG1/LV1 changed from 39.99 GiB (10238 extents) to 15.00 GiB (3840 extents).
Logical volume VG1/LV1 successfully resized.

测试没有毛病,这里逻辑卷仍然是39.99G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
linux-wugz:/home/lengqing # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
LV1 VG1 -wi-ao---- 39.99g
root system -wi-ao---- 15.99g
linux-wugz:/home/lengqing # lvdisplay
--- Logical volume ---
LV Path /dev/system/root
LV Name root
VG Name system
LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw
LV Write Access read/write
LV Creation host, time install, 2019-10-04 00:06:45 +0800
LV Status available
# open 1
LV Size 15.99 GiB
Current LE 4093
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:0

--- Logical volume ---
LV Path /dev/VG1/LV1
LV Name LV1
VG Name VG1
LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh
LV Write Access read/write
LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800
LV Status available
# open 1
LV Size 39.99 GiB
Current LE 10238
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:1

首先调整文件系统,先缩减逻辑卷到比文件系统小,文件系统大概也保不住

1
2
3
4
linux-wugz:/home/lengqing # resize2fs /dev/mapper/VG1-LV1 15G
resize2fs 1.43.8 (1-Jan-2018)
Resizing the filesystem on /dev/mapper/VG1-LV1 to 3932160 (4k) blocks.
The filesystem on /dev/mapper/VG1-LV1 is now 3932160 (4k) blocks long.

挂载分区并查看,文件系统已经是15G,之前的文件也没有问题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
linux-wugz:/home/lengqing # mount -a
linux-wugz:/home/lengqing # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 8.0K 2.0G 1% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 9.4M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/system-root 16G 7.1G 8.9G 45% /
tmpfs 394M 12K 394M 1% /run/user/1000
/dev/mapper/VG1-LV1 15G 41M 14G 1% /mnt/lvm
linux-wugz:/home/lengqing # cat /mnt/lvm/l
lengqinglvmext4 lost+found/
linux-wugz:/home/lengqing # cat /mnt/lvm/l
lengqinglvmext4 lost+found/
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvmext4
lengqinglvmext4

重新卸载分区并检查文件系统,缩减逻辑卷至15G,这次没有-t的参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
linux-wugz:/home/lengqing # umount /mnt/lvm
linux-wugz:/home/lengqing # e2fsck -f /dev/mapper/VG1-LV1
e2fsck 1.43.8 (1-Jan-2018)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VG1-LV1: 12/983040 files (0.0% non-contiguous), 137494/3932160 blocks
linux-wugz:/home/lengqing # lvreduce -L 15G /dev/VG1/LV1
WARNING: Reducing active logical volume to 15.00 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce VG1/LV1? [y/n]: y
Size of logical volume VG1/LV1 changed from 39.99 GiB (10238 extents) to 15.00 GiB (3840 extents).
Logical volume VG1/LV1 successfully resized.

此时查看逻辑卷,LV1已经变成了15G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
linux-wugz:/home/lengqing # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
LV1 VG1 -wi-a----- 15.00g
root system -wi-ao---- 15.99g
linux-wugz:/home/lengqing # lvdisplay
--- Logical volume ---
LV Path /dev/system/root
LV Name root
VG Name system
LV UUID fsZvJJ-NCk9-rHvR-rSOh-80tK-9GxZ-H5BRSw
LV Write Access read/write
LV Creation host, time install, 2019-10-04 00:06:45 +0800
LV Status available
# open 1
LV Size 15.99 GiB
Current LE 4093
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:0

--- Logical volume ---
LV Path /dev/VG1/LV1
LV Name LV1
VG Name VG1
LV UUID xAccOh-PRJd-jtuR-jx7F-F9Qr-N3nw-Cxm7yh
LV Write Access read/write
LV Creation host, time linux-wugz, 2019-12-02 02:22:10 +0800
LV Status available
# open 0
LV Size 15.00 GiB
Current LE 3840
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 1024
Block device 254:1

查看卷组VG1,已分配空间变成了15G,剩余空间还有24.99G

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
linux-wugz:/home/lengqing # vgdisplay
--- Volume group ---
VG Name system
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 15.99 GiB
PE Size 4.00 MiB
Total PE 4093
Alloc PE / Size 4093 / 15.99 GiB
Free PE / Size 0 / 0
VG UUID BfPwXl-TBTe-N6Rd-NaJT-xU2T-Ce0V-HqIN8L

--- Volume group ---
VG Name VG1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 39.99 GiB
PE Size 4.00 MiB
Total PE 10238
Alloc PE / Size 3840 / 15.00 GiB
Free PE / Size 6398 / 24.99 GiB
VG UUID ojpEne-jsFm-uB6R-azHU-zJmt-wP46-JvFeNc

挂载查看,文件系统正常,文件也还在

1
2
3
4
5
6
7
8
9
10
11
12
linux-wugz:/home/lengqing # mount -a
linux-wugz:/home/lengqing # df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 2.0G 8.0K 2.0G 1% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 9.4M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/system-root 16G 7.1G 8.9G 45% /
tmpfs 394M 12K 394M 1% /run/user/1000
/dev/mapper/VG1-LV1 15G 41M 14G 1% /mnt/lvm
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvmext4
lengqinglvmext4

移除物理磁盘

移除之前,需要移除的磁盘不能有数据,所以需要将数据转移到其它磁盘上,其它磁盘需要足够大能容纳已分配的空间,然后转移完成就可以移除了。

这里移除先添加的磁盘sdb,因为数据肯定在它上面。(我猜的,管它在哪个上面,我就是要移除这块)

将物理卷sdb1上的数据转移到物理卷sdc1上

1
2
3
linux-wugz:/home/lengqing # pvmove /dev/sdb1 /dev/sdc1
/dev/sdb1: Moved: 4.90%
/dev/sdb1: Moved: 100.00%

完成之后,从卷组VG1中移除物理卷/dev/sdb1

1
2
linux-wugz:/home/lengqing # vgreduce VG1 /dev/sdb1
Removed "/dev/sdb1" from volume group "VG1"

检查挂载以及文件,看起来完全正常

1
2
3
4
5
6
7
8
9
10
11
linux-wugz:/home/lengqing # df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 2.0G 8.0K 2.0G 1% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 9.4M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/system-root xfs 16G 7.1G 8.9G 45% /
tmpfs tmpfs 394M 12K 394M 1% /run/user/1000
/dev/mapper/VG1-LV1 ext4 15G 41M 14G 1% /mnt/lvm
linux-wugz:/home/lengqing # cat /mnt/lvm/lengqinglvmext4
lengqinglvmext4

其实可以先查看物理卷的占用(我这里已经移除了sdb1,但也能看出来sdc1现在总共20G,用了15G,5G剩余)

1
2
3
4
5
linux-wugz:/home/lengqing # pvscan
PV /dev/sda2 VG system lvm2 [15.99 GiB / 0 free]
PV /dev/sdc1 VG VG1 lvm2 [20.00 GiB / 5.00 GiB free]
PV /dev/sdb1 lvm2 [20.00 GiB]
Total: 3 [55.98 GiB] / in use: 2 [35.98 GiB] / in no VG: 1 [20.00 GiB]

替换物理磁盘

替换磁盘=先加入磁盘,再移除磁盘。

方法和步骤前面都有。

注意留意服务器组件的温度,手动控制可能导致高温过热,但是11G服务器的ipmi功能太过简单,无法获取温度,无法通过脚本获取温度自动调节转速。
重启服务器需要重新设置。

0. 安装ipmitool

Debian下

1
apt-get install ipmitool

1. 关闭自动风扇控制

1
ipmitool -I lanplus -U idrac用户名 -P idrac密码 -H idarc地址 raw 0x30 0x30 0x01 0x00

2. 调节风扇转速,其中最后一位为转速百分比的16进制,例如0x14代表20%,0x32为50%,0x64为100%

1
ipmitool -I lanplus -U idrac用户名 -P idrac密码 -H idarc地址 raw 0x30 0x30 0x02 0xff 0x14

3. 如果不想手动控制可以重新打开自动风扇控制

1
ipmitool -I lanplus -U idrac用户名 -P idrac密码 -H idarc地址 raw 0x30 0x30 0x01 0x01

1. 启动KMS服务 端口就不要改了,免得激活时office找不到端口

1
./vlmcsd-x64-musl-static  -L 0.0.0.0:1688 -Dev

2. 激活windows , 以管理员身份打开power shell,然执行下列命令, 激活成功会弹窗提示的

1
2
3
slmgr /skms VPS的IP或者绑定的域名
slmgr /ato
slmgr /xpr

3. 激活office , 激活成功会弹窗提示的

以管理员身份打开命令提示符,进入软件安装目录, 比如说 office 2016 64位 ,装在D盘
安装目录:D:\Program Files\Microsoft Office\Office16,执行如下:

1
2
3
cscript ospp.vbs /sethst:VPS的IP或者绑定的域名
cscript ospp.vbs /act
cscript ospp.vbs /dstatus

参考文档:[git]使用GPG签名你的commit

上一篇文章中创建了GPG密钥之后

0 Github端

首先在 https://github.com/settings/keys 点击绿色的New GPG key

将GPG密钥的公钥内容输入进去,然后点击绿色的Add GPG Key

1 本地端

添加GPG密钥

1
git config --global user.signingkey FD88ED069146EA37

全局启用

1
2
git config --global commit.gpgsign true #开启
git config --global commit.gpgsign false #关闭

仅在单个仓库中开启,进入仓库目录,然后运行

1
2
git config commit.gpgsign true #开启
git config commit.gpgsign false #关闭

然后commit之后push之后即可在远程仓库的commits中看到绿色的”Verified”标记

参考文档:GPG入门GPG密钥的生成与使用

0 安装GPG软件

一般Linux发行版都自带了的,就不讲了,

我目前使用的OpenSuSE Leap 15.1的KDE Plasma环境自带了Kleopatra,Kleopatra是一个能用的图形化GPG密钥管理器,可用于导出绝密密钥。

命令行GPG的用法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
gpg --help
gpg (GnuPG) 2.2.5
libgcrypt 1.8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /home/lengqing/.gnupg
支持的算法:
公钥:RSA, ELG, DSA, ECDH, ECDSA, EDDSA
对称加密:IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256,
TWOFISH, CAMELLIA128, CAMELLIA192, CAMELLIA256
散列:SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
压缩:不压缩, ZIP, ZLIB, BZIP2

Syntax: gpg [options] [files]
Sign, check, encrypt or decrypt
Default operation depends on the input data

指令:

-s, --sign make a signature
--clear-sign make a clear text signature
-b, --detach-sign 生成一份分离的签名
-e, --encrypt 加密数据
-c, --symmetric 仅使用对称加密
-d, --decrypt 解密数据(默认)
--verify 验证签名
-k, --list-keys 列出密钥
--list-signatures 列出密钥和签名
--check-signatures 列出并检查密钥签名
--fingerprint 列出密钥和指纹
-K, --list-secret-keys 列出私钥
--generate-key 生成一副新的密钥对
--quick-generate-key quickly generate a new key pair
--quick-add-uid quickly add a new user-id
--quick-revoke-uid quickly revoke a user-id
--quick-set-expire quickly set a new expiration date
--full-generate-key full featured key pair generation
--generate-revocation 生成一份吊销证书
--delete-keys 从公钥钥匙环里删除密钥
--delete-secret-keys 从私钥钥匙环里删除密钥
--quick-sign-key quickly sign a key
--quick-lsign-key quickly sign a key locally
--sign-key 为某把密钥添加签名
--lsign-key 为某把密钥添加本地签名
--edit-key 编辑某把密钥或为其添加签名
--change-passphrase change a passphrase
--export 导出密钥
--send-keys 把密钥导出到某个公钥服务器上
--receive-keys 从公钥服务器上导入密钥
--search-keys 在公钥服务器上搜寻密钥
--refresh-keys 从公钥服务器更新所有的本地密钥
--import 导入/合并密钥
--card-status 打印卡状态
--edit-card 更改卡上的数据
--change-pin 更改卡的 PIN
--update-trustdb 更新信任度数据库
--print-md print message digests
--server run in server mode
--tofu-policy VALUE set the TOFU policy for a key

选项:

-a, --armor 输出经 ASCII 封装
-r, --recipient USER-ID encrypt for USER-ID
-u, --local-user USER-ID use USER-ID to sign or decrypt
-z N set compress level to N (0 disables)
--textmode 使用标准的文本模式
-o, --output FILE write output to FILE
-v, --verbose 详细模式
-n, --dry-run 不做任何改变
-i, --interactive 覆盖前先询问
--openpgp 行为严格遵循 OpenPGP 定义

(请参考在线说明以获得所有命令和选项的完整清单)

Examples:

-se -r Bob [file] sign and encrypt for user Bob
--clear-sign [file] make a clear text signature
--detach-sign [file] make a detached signature
--list-keys [names] show keys
--fingerprint [names] show fingerprints

请向 <https://bugs.gnupg.org> 报告程序缺陷。
请向 <zuxyhere@eastday.com> 反映简体中文翻译的问题。

1 生成GPG密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
gpg --full-generate-key
gpg (GnuPG) 2.2.5; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

请选择您要使用的密钥种类:
(1) RSA and RSA (default)
(2) DSA and Elgamal
(3) DSA (仅用于签名)
(4) RSA (仅用于签名)
您的选择?
RSA 密钥长度应在 1024 位与 4096 位之间。
您想要用多大的密钥尺寸?(2048)
您所要求的密钥尺寸是 2048 位
请设定这把密钥的有效期限。
0 = 密钥永不过期
<n> = 密钥在 n 天后过期
<n>w = 密钥在 n 周后过期
<n>m = 密钥在 n 月后过期
<n>y = 密钥在 n 年后过期
密钥的有效期限是?(0)
密钥永远不会过期
以上正确吗?(y/n)y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"

真实姓名:lengqing5977
电子邮件地址:root@lengqing.org
注释:
您选定了这个用户标识:
“lengqing5977 <root@lengqing.org>”

更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)?O
我们需要生成大量的随机字节。这个时候您可以多做些琐事(像是敲打键盘、移动
鼠标、读写硬盘之类的),这会让随机数字发生器有更好的机会获得足够的熵数。
我们需要生成大量的随机字节。这个时候您可以多做些琐事(像是敲打键盘、移动
鼠标、读写硬盘之类的),这会让随机数字发生器有更好的机会获得足够的熵数。
gpg: 密钥 FD88ED069146EA37 被标记为绝对信任
gpg: revocation certificate stored as '/home/lengqing/.gnupg/openpgp-revocs.d/EE93CE1B2035C64A60914333FD88ED069146EA37.rev'
公钥和私钥已经生成并经签名。

pub rsa2048 2019-08-28 [SC]
EE93CE1B2035C64A60914333FD88ED069146EA37
uid lengqing5977 <root@lengqing.org>
sub rsa2048 2019-08-28 [E]

2 查看GPG密钥

1
2
3
4
5
6
7
gpg --list-keys
/home/lengqing/.gnupg/pubring.kbx
---------------------------------
pub rsa2048 2019-08-28 [SC]
EE93CE1B2035C64A60914333FD88ED069146EA37
uid [ 绝对 ] lengqing5977 <root@lengqing.org>
sub rsa2048 2019-08-28 [E]
1
2
3
4
5
6
7
gpg --list-keys --keyid-format long
/home/lengqing/.gnupg/pubring.kbx
---------------------------------
pub rsa2048/FD88ED069146EA37 2019-08-28 [SC]
EE93CE1B2035C64A60914333FD88ED069146EA37
uid [ 绝对 ] lengqing5977 <root@lengqing.org>
sub rsa2048/1F62C16D9F3F386F 2019-08-28 [E]

其中上面的FD88ED069146EA37可以用来代替ID,下面就会用到了。

3 导出GPG密钥

导出公钥

1
gpg --armor --output public.asc --export FD88ED069146EA37

导出私钥

1
gpg --armor --output private.asc --export-secret-keys FD88ED069146EA37

需要注意的是,这里导出的私钥公钥在其它系统导入之后依旧不能将密钥信任等级提升至“绝密”等级(也就是自己的密钥/绝对信任),将有使用限制,需要利用其它途径导出“绝密密钥”

4 编辑GPG密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
gpg --edit-key FD88ED069146EA37
gpg (GnuPG) 2.2.5; Copyright (C) 2018 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

私钥可用。

sec rsa2048/FD88ED069146EA37
创建于:2019-08-28 有效至:永不过期 可用于:SC
信任度:绝对 有效性:绝对
ssb rsa2048/1F62C16D9F3F386F
创建于:2019-08-28 有效至:永不过期 可用于:E
[ 绝对 ] (1). lengqing5977 <root@lengqing.org>

gpg> help
quit 离开这个菜单
save 保存并离开
help 显示这份在线说明
fpr 显示密钥指纹
grip show the keygrip
list 列出密钥和用户标识
uid 选择用户标识 N
key 选择子钥 N
check 检查签名
sign 为所选用户标识添加签名[* 参见下面的相关命令]
lsign 为所选用户标识添加本地签名
tsign 为所选用户标识添加信任签名
nrsign 为所选用户标识添加不可吊销签名
adduid 增加一个用户标识
addphoto 增加一个照片标识
deluid 删除选定的用户标识
addkey 添加一个子钥
addcardkey 在智能卡上添加一把密钥
keytocard 将一把密钥移动到智能卡上
bkuptocard 将备份密钥转移到卡上
delkey 删除选定的子钥
addrevoker 增加一把吊销密钥
delsig 删除所选用户标识上的签名
expire 变更密钥或所选子钥的使用期限
primary 将所选的用户标识设为首选用户标识
pref 列出首选项(专家模式)
showpref 列出首选项(详细模式)
setpref 设定所选用户标识的首选项
keyserver 设定所选用户标识的首选公钥服务器的 URL
notation 为所选用户标识的设定注记
passwd 更改密码
trust 更改信任度
revsig 吊销所选用户标识上的签名
revuid 吊销选定的用户标识
revkey 吊销密钥或选定的子钥
enable 启用密钥
disable 禁用密钥
showphoto 显示选定的照片标识
clean 压缩不可用的用户标识并删除不可用的签名
minimize 压缩不可用的用户标识并删除所有签名

* The 'sign' command may be prefixed with an 'l' for local signatures (lsign),
a 't' for trust signatures (tsign), an 'nr' for non-revocable signatures
(nrsign), or any combination thereof (ltsign, tnrsign, etc.).

5 将GPG公钥上传到公钥服务器(极不推荐的做法)

上传

1
gpg --keyserver hkp://subkeys.pgp.net --send-keys FD88ED069146EA37

因为上传是永久不可逆的操作,所以还需要创建撤销证书

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
gpg -a -o revocation.cert --gen-revoke FD88ED069146EA37

sec rsa2048/FD88ED069146EA37 2019-08-28 lengqing5977 <root@lengqing.org>

要为这把密钥建立一份吊销证书吗?(y/N)y
请选择吊销的原因:
0 = 未指定原因
1 = 密钥已泄漏
2 = 密钥被替换
3 = 密钥不再使用
Q = 取消
(也许您会想要在这里选择 1)
您的决定是什么?0
请输入描述(可选);以空白行结束:
>
吊销原因:未指定原因
(不给定描述)
这样可以吗? (y/N)y
已建立吊销证书。

请把这个文件转移到一个可隐藏起来的介质(如软盘)上;如果坏人能够取得这
份证书的话,那么他就能让您的密钥无法继续使用。把这份凭证打印出来再藏
到安全的地方也是很好的方法,以免您的保存媒体损毁而无法读取。但是千万
小心:您的机器上的打印系统可能会在打印过程中把这些数据临时在某个其他
人也能够看得到的地方!

6 删除GPG密钥

删除公钥

1
gpg --delete-key FD88ED069146EA37

删除私钥

1
gpg --delete-secret-keys FD88ED069146EA37

由于新装OpenWRT默认IP是192.168.1.1
然而我内网网段不是192.168.1.0/24,初次访问webUI有点不方便
所以直接在控制台修改IP

1
2
3
uci set network.lan.ipaddr=192.168.2.6
uci commit
/etc/init.d/network restart

然后就可以访问修改后的IP了

然后搜索安装下面的软件包可以获得中文翻译

luci-i18n-base-zh-cn