文章目录
0 背景
因为在装debian系统时,home目录和系统目录都在同一个物理盘sda上(使用LVM安装)。后面新添了物理硬盘sdc,需要做到存储系统和数据的物理硬盘分离。
初始情况:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-var 254:1 0 9.3G 0 lvm
|-HsServer--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:3 0 1.9G 0 lvm /tmp
`-HsServer--vg-home 254:4 0 895.6G 0 lvm /home
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
`-sdc1 8:33 0 500G 0 part
`-Vol1-lvtest 254:5 0 500G 0 lvm /var
结果:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:2 0 1.9G 0 lvm /tmp
`-HsServer--vg-var 254:3 0 300G 0 lvm /var
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
| `-Vol2-lvtest 254:4 0 1T 0 lvm /home
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:4 0 1T 0 lvm /home
结果中还包含了var目录的迁移,迁移回一个已分配逻辑卷的磁盘中。该内容,在下一篇博文中,点击此链接打开。
该篇博文的理论基础在此博文中,本博文为实战篇。
1 准备工作
1.1 查看当前分区情况
root@HsServer:/var# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-var 254:1 0 9.3G 0 lvm
|-HsServer--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:3 0 1.9G 0 lvm /tmp
`-HsServer--vg-home 254:4 0 895.6G 0 lvm /home
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
`-sdc1 8:33 0 500G 0 part
`-Vol1-lvtest 254:5 0 500G 0 lvm /var
1.2 创建物理磁盘分区
root@HsServer:/var# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): p
Disk /dev/sdc: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x97be5b6a
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 1 FAT12
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (1048578048-3907029167, default 1048578048): 1048578048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1048578048-3907029167, default 3907029167): +1024G
Created a new partition 2 of type 'Linux' and of size 1 TiB.
Command (m for help): p
Disk /dev/sdc: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x97be5b6a
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 1 FAT12
/dev/sdc2 1048578048 3196061695 2147483648 1T 83 Linux
Command (m for help): w
The partition table has been altered.
Syncing disks.
1.3 改变分区类型为LVM
root@HsServer:/var# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): p
Disk /dev/sdc: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x97be5b6a
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 1 FAT12
/dev/sdc2 1048578048 3196061695 2147483648 1T 83 Linux
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code or alias (type L to list all):
Hex code or alias (type L to list all): L
00 Empty 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
01 FAT12 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
02 XENIX root 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
03 XENIX usr 40 Venix 80286 85 Linux extended c7 Syrinx
04 FAT16 <32M 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
05 Extended 42 SFS 87 NTFS volume set db CP/M / CTOS / .
06 FAT16 4d QNX4.x 88 Linux plaintext de Dell Utility
07 HPFS/NTFS/exFAT 4e QNX4.x 2nd part 8e Linux LVM df BootIt
08 AIX 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
09 AIX bootable 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
0a OS/2 Boot Manag 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
0b W95 FAT32 52 CP/M a0 IBM Thinkpad hi ea Linux extended
0c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
0e W95 FAT16 (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
0f W95 Ext'd (LBA) 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a9 NetBSD f1 SpeedStor
12 Compaq diagnost 61 SpeedStor ab Darwin boot f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
16 Hidden FAT16 64 Novell Netware b7 BSDI fs f8 EBBR protective
17 Hidden HPFS/NTF 65 Novell Netware b8 BSDI swap fb VMware VMFS
18 AST SmartSleep 70 DiskSecure Mult bb Boot Wizard hid fc VMware VMKCORE
1b Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fd Linux raid auto
1c Hidden W95 FAT3 80 Old Minix be Solaris boot fe LANstep
1e Hidden W95 FAT1 81 Minix / old Lin bf Solaris ff BBT
24 NEC DOS
Aliases:
linux - 83
swap - 82
extended - 05
uefi - EF
raid - FD
lvm - 8E
linuxex - 85
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): p
Disk /dev/sdc: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x97be5b6a
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 1 FAT12
/dev/sdc2 1048578048 3196061695 2147483648 1T 8e Linux LVM
Command (m for help): w
The partition table has been altered.
Syncing disks.
目前分区情况:
root@HsServer:/var# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-var 254:1 0 9.3G 0 lvm
|-HsServer--vg-swap_1 254:2 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:3 0 1.9G 0 lvm /tmp
`-HsServer--vg-home 254:4 0 895.6G 0 lvm /home
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
| `-Vol1-lvtest 254:5 0 500G 0 lvm /var
`-sdc2 8:34 0 1T 0 part
1.4 创建物理卷
root@HsServer:/var# sudo pvcreate /dev/sdc2
Physical volume "/dev/sdc2" successfully created.
注意:pvcreate定义了用于物理卷的物理分区。它只是简单地将分区标记成Linux LVM系统中的分区而已。
1.5 创建卷组
# 创建卷组(vgcreate)
root@HsServer:/var# vgcreate Vol2 /dev/sdc2
Volume group "Vol2" successfully created
1.6 创建逻辑卷
root@HsServer:/var# lvcreate -l 100%FREE -n lvtest Vol2
Logical volume "lvtest" created.
- 1,-l选项定义了要为逻辑卷指定多少可用的卷组空间。注意,你可以按照卷组空闲空间的百分比来指定这个值。本例中为新逻辑卷使用了所有的空闲空间(或者用-L选项以字节、千字节(KB)、兆字节(MB)或吉字节(GB)为单位来指定实际的大小)。
- 2,-n选项允许你为逻辑卷指定一个名称(在本例中称作lvtest)
注意:Linux系统使用逻辑卷来模拟物理分区,并在其中保存文件系统。Linux系统会像处理物理分区一样处理逻辑卷,允许你定义逻辑卷中的文件系统,然后将文件系统挂载到虚拟目录上。
1.7 创建文件系统
root@HsServer:/var# mkfs.ext4 /dev/Vol2/lvtest
mke2fs 1.47.0 (5-Feb-2023)
Creating filesystem with 268434432 4k blocks and 67108864 inodes
Filesystem UUID: 0667b0ac-112e-49b9-b951-b433e559233e
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks):
done
Writing superblocks and filesystem accounting information: done
1.8 挂载文件系统
root@HsServer:/var# mkdir /backHome
root@HsServer:/var# mount /dev/Vol2/lvtest /backHome
root@HsServer:/var# df -hl
Filesystem Size Used Avail Use% Mounted on
udev 11G 0 11G 0% /dev
tmpfs 2.2G 17M 2.2G 1% /run
/dev/mapper/HsServer--vg-root 23G 11G 11G 50% /
tmpfs 11G 84K 11G 1% /dev/shm
tmpfs 5.0M 16K 5.0M 1% /run/lock
/dev/mapper/Vol1-lvtest 492G 9.7G 457G 3% /var
/dev/mapper/HsServer--vg-tmp 1.8G 104K 1.7G 1% /tmp
/dev/sda1 455M 216M 215M 51% /boot
/dev/mapper/HsServer--vg-home 881G 56G 781G 7% /home
tmpfs 2.2G 56K 2.2G 1% /run/user/113
tmpfs 2.2G 44K 2.2G 1% /run/user/0
/dev/mapper/Vol2-lvtest 1007G 28K 956G 1% /backHome
2 备份源文件
cp -r /home/* /backHome/
3 修改文件夹home的挂载磁盘
3.1 查看挂载盘的名字:
root@HsServer:/var# blkid
/dev/mapper/HsServer--vg-var: UUID="dbedb753-dbf4-4aa8-8ef2-49bb55a6acc5" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sdb2: BLOCK_SIZE="512" UUID="D470CFB970CFA09A" TYPE="ntfs" PARTUUID="36e496ea-02"
/dev/sdb5: BLOCK_SIZE="512" UUID="0004A422000CA487" TYPE="ntfs" PARTUUID="36e496ea-05"
/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_M-dM-?M-^]M-gM-^UM-^Y" BLOCK_SIZE="512" UUID="9400C91000C8FA6E" TYPE="ntfs" PARTUUID="36e496ea-01"
/dev/mapper/HsServer--vg-home: UUID="d3663939-4a5f-4faa-b802-71aef68a4b98" BLOCK_SIZE="4096" TYPE="ext4"
/dev/mapper/HsServer--vg-swap_1: UUID="ebdc78fa-f920-47b4-b3ce-4486e0993691" TYPE="swap"
/dev/mapper/HsServer--vg-root: UUID="7117eb71-a277-44b7-a7f8-37418817968d" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sdc1: UUID="roJf0h-R7Bt-tVnm-ml2V-h9ac-fyLZ-jMEa7N" TYPE="LVM2_member" PARTUUID="97be5b6a-01"
/dev/sda5: UUID="W5i2fK-Up60-LCGp-qIrI-e1q1-Ycye-LwEhpl" TYPE="LVM2_member" PARTUUID="b8213fff-05"
/dev/sda1: UUID="de772acf-c0c7-4dbc-b213-2ce826d6e055" BLOCK_SIZE="1024" TYPE="ext2" PARTUUID="b8213fff-01"
/dev/mapper/Vol1-lvtest: UUID="f085a0cc-2c4d-42d1-a8e0-601abbf9a10e" BLOCK_SIZE="4096" TYPE="ext4"
/dev/mapper/HsServer--vg-tmp: UUID="307b0159-746b-4476-866c-ebc2b81632f8" BLOCK_SIZE="4096" TYPE="ext4"
/dev/mapper/Vol2-lvtest: UUID="0667b0ac-112e-49b9-b951-b433e559233e" BLOCK_SIZE="4096" TYPE="ext4"
/dev/sdc2: UUID="IUHj8a-1VcD-ggMn-UzhK-NNBN-ohhT-Zzci3g" TYPE="LVM2_member" PARTUUID="97be5b6a-02"xxxxxxxxxx blkidroot@HsServer:/var# blkid/dev/mapper/HsServer--vg-var: UUID="dbedb753-dbf4-4aa8-8ef2-49bb55a6acc5" BLOCK_SIZE="4096" TYPE="ext4"/dev/sdb2: BLOCK_SIZE="512" UUID="D470CFB970CFA09A" TYPE="ntfs" PARTUUID="36e496ea-02"/dev/sdb5: BLOCK_SIZE="512" UUID="0004A422000CA487" TYPE="ntfs" PARTUUID="36e496ea-05"/dev/sdb1: LABEL="M-gM-3M-;M-gM-;M-^_M-dM-?M-^]M-gM-^UM-^Y" BLOCK_SIZE="512" UUID="9400C91000C8FA6E" TYPE="ntfs" PARTUUID="36e496ea-01"/dev/mapper/HsServer--vg-home: UUID="d3663939-4a5f-4faa-b802-71aef68a4b98" BLOCK_SIZE="4096" TYPE="ext4"/dev/mapper/HsServer--vg-swap_1: UUID="ebdc78fa-f920-47b4-b3ce-4486e0993691" TYPE="swap"/dev/mapper/HsServer--vg-root: UUID="7117eb71-a277-44b7-a7f8-37418817968d" BLOCK_SIZE="4096" TYPE="ext4"/dev/sdc1: UUID="roJf0h-R7Bt-tVnm-ml2V-h9ac-fyLZ-jMEa7N" TYPE="LVM2_member" PARTUUID="97be5b6a-01"/dev/sda5: UUID="W5i2fK-Up60-LCGp-qIrI-e1q1-Ycye-LwEhpl" TYPE="LVM2_member" PARTUUID="b8213fff-05"/dev/sda1: UUID="de772acf-c0c7-4dbc-b213-2ce826d6e055" BLOCK_SIZE="1024" TYPE="ext2" PARTUUID="b8213fff-01"/dev/mapper/Vol1-lvtest: UUID="f085a0cc-2c4d-42d1-a8e0-601abbf9a10e" BLOCK_SIZE="4096" TYPE="ext4"/dev/mapper/HsServer--vg-tmp: UUID="307b0159-746b-4476-866c-ebc2b81632f8" BLOCK_SIZE="4096" TYPE="ext4"/dev/mapper/Vol2-lvtest: UUID="0667b0ac-112e-49b9-b951-b433e559233e" BLOCK_SIZE="4096" TYPE="ext4"/dev/sdc2: UUID="IUHj8a-1VcD-ggMn-UzhK-NNBN-ohhT-Zzci3g" TYPE="LVM2_member" PARTUUID="97be5b6a-02"
3.2 查看配置源文件
root@HsServer:/var# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
# <file system> <mount point> <type> <options> <dump> <pass>
/dev/mapper/HsServer--vg-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sda1 during installation
UUID=de772acf-c0c7-4dbc-b213-2ce826d6e055 /boot ext2 defaults 0 2
/dev/mapper/HsServer--vg-home /home ext4 defaults 0 2
/dev/mapper/HsServer--vg-tmp /tmp ext4 defaults 0 2
#/dev/mapper/HsServer--vg-var /var ext4 defaults 0 2
/dev/mapper/HsServer--vg-swap_1 none swap sw 0 0
/dev/Vol1/lvtest /var ext4 defaults 0 2
3.3 修改配置文件
root@HsServer:/var# vi /etc/fstab
添加如下一句:
/dev/Vol2/lvtest /home ext4 defaults 0 2
3.4 重启计算机
reboot
3.5 查看新的挂载盘的容量
发现home盘从900G更换为1T。
root@HsServer:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 11G 0 11G 0% /dev
tmpfs 2.2G 3.1M 2.2G 1% /run
/dev/mapper/HsServer--vg-root 23G 11G 11G 50% /
tmpfs 11G 0 11G 0% /dev/shm
tmpfs 5.0M 16K 5.0M 1% /run/lock
/dev/mapper/Vol1-lvtest 492G 9.6G 457G 3% /var
/dev/mapper/Vol2-lvtest 1007G 56G 901G 6% /home
/dev/mapper/HsServer--vg-tmp 1.8G 80K 1.7G 1% /tmp
/dev/sda1 455M 216M 215M 51% /boot
tmpfs 2.2G 56K 2.2G 1% /run/user/113
tmpfs 2.2G 44K 2.2G 1% /run/user/0
4 清除原来磁盘的分配的home空间
4.1 查看原home占用的空间
发现原home在sda的HsServer--vg-home
中占用了900G,现在要清除掉这部分内容。
root@HsServer:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:2 0 23.3G 0 lvm /
|-HsServer--vg-var 254:3 0 9.3G 0 lvm
|-HsServer--vg-swap_1 254:4 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:5 0 1.9G 0 lvm /tmp
`-HsServer--vg-home 254:6 0 895.6G 0 lvm
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
| `-Vol1-lvtest 254:1 0 500G 0 lvm /var
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:0 0 1024G 0 lvm /home
查看逻辑卷名:
Command (m for help): cat /etc/fstab
#/dev/mapper/HsServer--vg-home /home ext4 defaults 0 2
4.2 删除LVM分区
删除LVM之前创建的物理卷,卷组,逻辑卷时,删除顺序应该与创建时的顺序相反。也就是卸载文件系统,删除逻辑卷,删除卷组,删除物理卷。卸载文件系统时需要注意:如果之前没有更新/etc/fstab文件
,则需要更新。
# 1,卸载文件系统
umount /dev/mapper/HsServer--vg-home
# 2,删除逻辑卷
lvremove /dev/mapper/HsServer--vg-home
# 3,删除卷组(这里卷组还有其他卷,暂不删除)
vgremove HsServer--vg
# 4,删除物理卷
pvremove /dev/sda{1,2,5}
执行操作:
root@HsServer:~# lvremove /dev/mapper/HsServer--vg-home
Do you really want to remove active logical volume HsServer-vg/home? [y/n]: y
Logical volume "home" successfully removed.
root@HsServer:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:2 0 23.3G 0 lvm /
|-HsServer--vg-var 254:3 0 9.3G 0 lvm
|-HsServer--vg-swap_1 254:4 0 976M 0 lvm [SWAP]
`-HsServer--vg-tmp 254:5 0 1.9G 0 lvm /tmp
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
| `-Vol1-lvtest 254:1 0 500G 0 lvm /var
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:0 0 1024G 0 lvm /home
5 扩展home的逻辑卷
5.1 创建新分区
root@HsServer:~# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.38.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): p
Disk /dev/sdc: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: ST2000DM001-1ER1
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x97be5b6a
Device Boot Start End Sectors Size Id Type
/dev/sdc2 1048578048 3196061695 2147483648 1T 8e Linux LVM
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1,3,4, default 1): 1
First sector (2048-3907029167, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1048578047, default 1048578047): 1048578047
Created a new partition 1 of type 'Linux' and of size 500 GiB.
Partition #1 contains a LVM2_member signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help): t
Partition number (1,2, default 2): 1
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w
The partition table has been altered.
Syncing disks.
查看:
root@HsServer:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:2 0 1.9G 0 lvm /tmp
`-HsServer--vg-var 254:3 0 300G 0 lvm /var
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:4 0 1024G 0 lvm /home
5.2 创建物理卷
root@HsServer:~# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created.
5.3 扩展卷组
root@HsServer:~# vgextend Vol2 /dev/sdc1
Volume group "Vol2" successfully extended
5.4 扩展逻辑卷
root@HsServer:~# lvextend -L +10G /dev/mapper/Vol2-lvtest
Size of logical volume Vol2/lvtest changed from <1024.00 GiB (262143 extents) to <1.01 TiB (264703 extents).
Logical volume Vol2/lvtest successfully resized.
扩展前:
root@HsServer:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:2 0 1.9G 0 lvm /tmp
`-HsServer--vg-var 254:3 0 300G 0 lvm /var
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:4 0 1024G 0 lvm /home
扩展后(多乐10个G):
root@HsServer:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 11G 0 11G 0% /dev
tmpfs 2.2G 3.1M 2.2G 1% /run
/dev/mapper/HsServer--vg-root 23G 11G 11G 50% /
tmpfs 11G 0 11G 0% /dev/shm
tmpfs 5.0M 16K 5.0M 1% /run/lock
/dev/mapper/Vol2-lvtest 1007G 56G 901G 6% /home
/dev/sda1 455M 216M 215M 51% /boot
/dev/mapper/HsServer--vg-tmp 1.8G 80K 1.7G 1% /tmp
/dev/mapper/HsServer--vg-var 295G 9.5G 270G 4% /var
tmpfs 2.2G 56K 2.2G 1% /run/user/113
tmpfs 2.2G 44K 2.2G 1% /run/user/0
root@HsServer:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk
|-sda1 8:1 0 487M 0 part /boot
|-sda2 8:2 0 1K 0 part
`-sda5 8:5 0 931G 0 part
|-HsServer--vg-root 254:0 0 23.3G 0 lvm /
|-HsServer--vg-swap_1 254:1 0 976M 0 lvm [SWAP]
|-HsServer--vg-tmp 254:2 0 1.9G 0 lvm /tmp
`-HsServer--vg-var 254:3 0 300G 0 lvm /var
sdb 8:16 0 111.8G 0 disk
|-sdb1 8:17 0 100M 0 part
|-sdb2 8:18 0 67.9G 0 part
|-sdb3 8:19 0 1K 0 part
`-sdb5 8:21 0 43.8G 0 part
sdc 8:32 0 1.8T 0 disk
|-sdc1 8:33 0 500G 0 part
| `-Vol2-lvtest 254:4 0 1T 0 lvm /home
`-sdc2 8:34 0 1T 0 part
`-Vol2-lvtest 254:4 0 1T 0 lvm /home