Linux作業系統中分割槽格式轉換LVM格式及多磁碟建立PV、VG、LV
在工作中,經常遇到兩種情況: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 ~]#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31520497/viewspace-2701478/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- linux 磁碟分割槽掛載-LVM-物理卷PV,卷組VG,邏輯卷LVLinuxLVM
- Linux 新增LVM分割槽及LVM分割槽擴容LinuxLVM
- LVM原理及PV、VG、LV、PE、LE關係圖【轉】LVM
- linux 磁碟自動化分割槽掛載-LVM-物理卷PV,卷組VG,邏輯卷LV-shellLinuxLVM
- Linux中的建立PV-VG-LVLinux
- LVM原理及PV、VG、LV、PE、LE關係圖LVM
- Linux LVM 擴充套件磁碟分割槽LinuxLVM套件
- 在 Linux 中建立 LVM 分割槽的分步指南LinuxLVM
- Virtualbox中Linux新增一個新磁碟->建立分割槽->格式化->掛載分割槽Linux
- linux下磁碟分割槽與格式化Linux
- 在Linux中,如何格式化一個磁碟分割槽?Linux
- AIX系統LVM管理PV/VG/LV常用命令總結與實戰AILVM
- Linux作業系統邏輯盤卷管理LVM建立步驟(轉)Linux作業系統LVM
- linux 中的分割槽與格式化(轉)Linux
- linux磁碟分割槽格式化-fdisk命令工具Linux
- 分割槽欄位VALUES LESS THAN時間格式及轉換
- Linux中lvm分割槽是什麼?LVM優缺點有哪些?LinuxLVM
- [Linux] PV,VG,LV相關Linux
- Linux 磁碟分割槽及檔案系統管理Linux
- 【LINUX】磁碟格式化 建立檔案系統Linux
- LVM分割槽恢復LVM
- AIX中PV,VG,LV及FS常用相關命令AI
- linux磁碟結構及分割槽(轉)Linux
- (轉)管理LVM2邏輯分割槽LVM
- lvm增加分割槽容量LVM
- 談linux磁碟結構及分割槽(轉)Linux
- 【Linux】Linux檔案系統管理1 磁碟分割槽、格式化、掛載-卷標掛載Linux
- 【Linux】Linux檔案系統管理2 磁碟分割槽、格式化、掛載-UUID掛載LinuxUI
- Linux 分割槽和格式化Linux
- AIX PV VG LV詳解AI
- Win7系統如何建立何建立、刪除或格式化硬碟分割槽Win7硬碟
- 大盤分割槽格式化及掛載
- LINUX中的分割槽,格式化,掛載安全(中)Linux
- LVM 管理linux磁碟LVMLinux
- linux 訪問 windows NTFS 格式分割槽LinuxWindows
- aix lvm big vgAILVM
- Virtualbox中Linux新增新磁碟並建立分割槽Linux
- linux新增新磁碟和建立分割槽Linux