在工作中,經(jīng)常遇到兩種情況:1、系統(tǒng)盤與數(shù)據(jù)盤在同一個Raid組; 2、系統(tǒng)盤與數(shù)據(jù)盤分離(不同Raid組);
網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)建站!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、成都小程序開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了林周免費(fèi)建站歡迎大家使用!
有時可能因公司要求按某基本安裝OS,則需要對已安裝好的OS中利用空余空間或增加空余空間使用,此時
將涉及分區(qū)格式轉(zhuǎn)換,當(dāng)前以轉(zhuǎn)換為: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): 默認(rèn)回車
First sector (2048-104857599, default 2048): 默認(rèn)回車
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +25600M ——指定分區(qū)大小
Partition 1 of type Linux and of size 25 GiB is set
Command (m for help): t ——列出所需要轉(zhuǎn)換分區(qū)
Selected partition 1
Hex code (type Lto list all codes): l ——查看需要轉(zhuǎn)換的分區(qū)序號
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 ——對就分區(qū)格式查看8e則我們當(dāng)前所需要轉(zhuǎn)換的:LVM格式
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p ——p(print)查看已轉(zhuǎn)換分區(qū)
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 ——保存分區(qū)表
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@ihmp ~]# ls -l /dev/sdb1 ——若查看沒有對應(yīng)的分區(qū)磁盤存在時可以嘗試重啟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): 默認(rèn)回車 ——若不是默認(rèn)可以自指定分區(qū)號
First sector (52430848-104857599, default 52430848): 默認(rèn)回車
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): 默認(rèn)回車 ——若不是默認(rèn)可以自指定分區(qū)號
Hex code (type L to list all codes): l ——查看需要轉(zhuǎn)換的分區(qū)序號
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 ~]#
創(chuàng)建PV
[root@ihmp ~]#
[root@ihmp ~]# pvcreate /dev/sdb[1-2] ——批量創(chuàng)建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]
創(chuàng)建VG
[root@ihmp ~]# vgcreate vgapp /dev/sdb[1-2] ——多盤VG創(chuàng)建
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 ~]#
創(chuàng)建LV
[root@ihmp ~]# lvcreate -l100%FREE -n lvapp vgapp 或lv指定大小創(chuàng)建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 ~]#
創(chuàng)建掛接點(diǎn)
[root@ihmp ~]# mkdir -p /app
[root@ihmp ~]#
格式化分區(qū)
[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 ~]#
設(shè)置掛接點(diǎn)開啟啟動
[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啟動時檢查分區(qū);1 1則OS啟動時永不檢查,根據(jù)自己需求選擇
~
"/etc/fstab" 14L, 700C written
[root@ihmp ~]#
測試所配置掛接點(diǎn)是否正常
[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 ~]#