在工作中,经常遇到两种情况:1、系统盘与数据盘在同一个Raid组; 2、系统盘与数据盘分离(不同Raid组);
有时可能因公司要求按某基本安装OS,则需要对已安装好的OS中利用空余空间或增加空余空间使用,此时
将涉及分区格式转换,当前以转换为:LVM格式为例:
[root@ihmp ~]# fdisk /dev/sdb ——有时可能是同Raid组,一块几个T的硬盘
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 0x6e84979f.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 默认回车
First sector (2048-104857599, default 2048): 默认回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +25600M ——指定分区大小
Partition 1 of type Linux and of size 25 GiB is set
Command (m for help): t ——列出所需要转换分区
Selected partition 1
Hex code (type L to list all codes): l ——查看需要转换的分区序号
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes):
Hex code (type L to list all codes): 8e ——对就分区格式查看8e则我们当前所需要转换的:LVM格式
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p ——p(print)查看已转换分区
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x6e84979f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 52430847 26214400 8e Linux LVM
Command (m for help): w ——保存分区表
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ihmp ~]# ls -l /dev/sdb1 ——若查看没有对应的分区磁盘存在时可以尝试重启OS,再次查看;
brw-rw---- 1 root disk 8, 17 Jun 30 21:28 /dev/sdb1
[root@ihmp ~]#
[root@ihmp ~]# 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.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2): 默认回车 ——若不是默认可以自指定分区号
First sector (52430848-104857599, default 52430848): 默认回车
Using default value 52430848
Last sector, +sectors or +size{K,M,G} (52430848-104857599, default 104857599):
Using default value 104857599
Partition 2 of type Linux and of size 25 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 默认回车 ——若不是默认可以自指定分区号
Hex code (type L to list all codes): l ——查看需要转换的分区序号
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help):
Command (m for help): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 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
Disk label type: dos
Disk identifier: 0x6e84979f
Device Boot Start End Blocks Id System
/dev/sdb1 2048 52430847 26214400 8e Linux LVM
/dev/sdb2 52430848 104857599 26213376 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ihmp ~]# ls -l /dev/sd*
brw-rw---- 1 root disk 8, 0 Jun 30 21:24 /dev/sda
brw-rw---- 1 root disk 8, 1 Jun 30 21:24 /dev/sda1
brw-rw---- 1 root disk 8, 2 Jun 30 21:24 /dev/sda2
brw-rw---- 1 root disk 8, 16 Jun 30 21:30 /dev/sdb
brw-rw---- 1 root disk 8, 17 Jun 30 21:33 /dev/sdb1
brw-rw---- 1 root disk 8, 18 Jun 30 21:33 /dev/sdb2
[root@ihmp ~]#
创建PV
[root@ihmp ~]#
[root@ihmp ~]# pvcreate /dev/sdb[1-2] ——批量创建PV
Physical volume "/dev/sdb1" successfully created.
Physical volume "/dev/sdb2" successfully created.
[root@ihmp ~]#
[root@ihmp ~]# pvscan ——查看pv
PV /dev/sda2 VG vgihmp lvm2 [<99.00 GiB / 32.00 MiB free]
PV /dev/sdb2 lvm2 [<25.00 GiB]
PV /dev/sdb1 lvm2 [25.00 GiB]
Total: 3 [<149.00 GiB] / in use: 1 [<99.00 GiB] / in no VG: 2 [<50.00 GiB]
创建VG
[root@ihmp ~]# vgcreate vgapp /dev/sdb[1-2] ——多盘VG创建
Volume group "vgapp" successfully created
[root@ihmp ~]#
[root@ihmp ~]# vgscan ——VG查看
Reading volume groups from cache.
Found volume group "vgapp" using metadata type lvm2
Found volume group "vgihmp" using metadata type lvm2
[root@ihmp ~]#
创建LV
[root@ihmp ~]# lvcreate -l100%FREE -n lvapp vgapp 或lv指定大小创建lvcreate -L 99g vg_racdb_app -n lv_racapp
Logical volume "lvapp" created.
[root@ihmp ~]#
[root@ihmp ~]# lvscan
ACTIVE '/dev/vgapp/lvapp' [49.99 GiB] inherit
ACTIVE '/dev/vgihmp/lvswap' [8.00 GiB] inherit
ACTIVE '/dev/vgihmp/lvroot' [60.96 GiB] inherit
ACTIVE '/dev/vgihmp/lvihmp' [10.00 GiB] inherit
ACTIVE '/dev/vgihmp/lvmysqldb' [20.00 GiB] inherit
[root@ihmp ~]#
创建挂接点
[root@ihmp ~]# mkdir -p /app
[root@ihmp ~]#
格式化分区
[root@ihmp ~]# mkfs.xfs /dev/mapper/vgapp-lvapp
meta-data=/dev/mapper/vgapp-lvapp isize=512 agcount=4, agsize=3276288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=13105152, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=6399, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ihmp ~]#
设置挂接点开启启动
[root@ihmp ~]# vi /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Sep 7 09:09:56 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vgihmp-lvroot / xfs defaults 0 0
UUID=034666be-8906-4c9a-8ab7-9d0bae68494b /boot xfs defaults 0 0
/dev/mapper/vgihmp-lvihmp /ihmp xfs defaults 0 0
/dev/mapper/vgihmp-lvmysqldb /mysqldb xfs defaults 0 0
/dev/mapper/vgihmp-lvswap swap swap defaults 0 0
/dev/mapper/vgapp-lvapp /app xfs defaults 0 0
#0 0表示OS启动时检查分区;1 1则OS启动时永不检查,根据自己需求选择
~
"/etc/fstab" 14L, 700C written
[root@ihmp ~]#
测试所配置挂接点是否正常
[root@ihmp ~]# mount -a
[root@ihmp ~]#
[root@ihmp ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vgihmp-lvroot 61G 9.5G 52G 16% /
devtmpfs 979M 0 979M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 1014M 133M 882M 14% /boot
/dev/mapper/vgihmp-lvmysqldb 20G 363M 20G 2% /mysqldb
/dev/mapper/vgihmp-lvihmp 10G 630M 9.4G 7% /ihmp
tmpfs 199M 0 199M 0% /run/user/0
/dev/mapper/vgapp-lvapp 50G 33M 50G 1% /app
[root@ihmp ~]#
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。