Linux Create disk and disk partition management
View disk Information
[Email protected] ~]# fdisk-l
disk/dev/sda:42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk label Type:dos
Disk identifier:0x000af460
Device Boot Start End Blocks Id System
/DEV/SDA1 * 2048 1026047 512000 Linux
/dev/sda2 1026048 83886079 41430016 8e Linux LVM
disk/dev/mapper/centos_zzsrv1-swap:2181 MB, 2181038080 bytes, 4259840 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
disk/dev/mapper/centos_zzsrv1-root:40.2 GB, 40240152576 bytes, 78594048 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Rescan disks after adding a piece of disk does not require a restart
[Email protected] ~]# echo "---" >/sys/class/scsi_host/host0/scan
[Email protected] ~]# echo "---" >/sys/class/scsi_host/host1/scan
[Email protected] ~]# echo "---" >/sys/class/scsi_host/host2/scan
[[email protected] ~]# fdisk-l to view the disk information again, you will see the newly added disk SDB
disk/dev/sda:42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk label Type:dos
Disk identifier:0x000af460
Device Boot Start End Blocks Id System
/DEV/SDA1 * 2048 1026047 512000 Linux
/dev/sda2 1026048 83886079 41430016 8e Linux LVM
disk/dev/mapper/centos_zzsrv1-swap:2181 MB, 2181038080 bytes, 4259840 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
disk/dev/mapper/centos_zzsrv1-root:40.2 GB, 40240152576 bytes, 78594048 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
disk/dev/sdb:21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Partition the disk (this is where the disk is divided into a zone)
[Email protected] ~]# Fdisk/dev/sdb
Welcome to Fdisk (Util-linux 2.23.2).
Changes'll remain in memory only, until the 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 0X7D9737A7.
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): → Here are some areas where you can divide the disk
First sector (2048-41943039, default 2048):
Using Default Value 2048
Last sector, +sectors or +size{k,m,g} (2048-41943039, default 41943039): → the size of the partition cannot exceed the size of the disk
Using Default Value 41943039
Partition 1 of type Linux and of size GiB is set
Command (M for help): P
disk/dev/sdb:21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * MB = bytes
Sector size (logical/physical): bytes/512 bytes
I/O size (minimum/optimal): bytes/512 bytes
Disk label Type:dos
Disk Identifier:0x7d9737a7
Device Boot Start End Blocks Id System
/DEV/SDB1 2048 41943039 20970496-up Linux
Command (M for help): W
The partition table has been altered!
Calling IOCTL () to re-read partition table.
Syncing disks.
Create PV
[Email protected] ~]# Pvscan
Pv/dev/sda2 VG centos_zzsrv1 lvm2 [39.51 gib/0 Free]
Total:1 [39.51 Gib]/in use:1 [39.51 GIB]/in no vg:0 [0]
[Email protected] ~]# PVCREATE/DEV/SDB1
Physical volume "/DEV/SDB1" successfully created
[Email protected] ~]# Pvscan
Pv/dev/sda2 VG centos_zzsrv1 lvm2 [39.51 gib/0 Free]
PV/DEV/SDB1 lvm2 [20.00 GiB]
Total:2 [59.51 GIB]/in use:1 [39.51 GIB]/In no vg:1 [20.00 GIB]
Create VG
[Email protected] ~]# Vgscan
Reading all physical volumes. This is a while ...
Found Volume Group "CENTOS_ZZSRV1" using metadata type LVM2
[Email protected] ~]# vgcreate VG/DEV/SDB1
Volume Group "VG" successfully created
[Email protected] ~]# Vgscan
Reading all physical volumes. This is a while ...
Found Volume Group "VG" using metadata type LVM2
Found Volume Group "CENTOS_ZZSRV1" using metadata type LVM2
[Email protected] ~]# Vgdisplay VG
---Volume Group---
VG Name VG
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 → remember this number.
Alloc pe/size 0/0
Free Pe/size 5119/20.00 GiB
VG UUID QHPCWT-MJRD-XCST-QBAC-XM94-B1H4-P2NQDF
Create a LV, using all of the VG's PE
[Email protected] ~]# Lvscan
ACTIVE '/dev/centos_zzsrv1/swap ' [2.03 GiB] Inherit
ACTIVE '/dev/centos_zzsrv1/root ' [37.48 GiB] Inherit
The name of the LV is LV1
[Email protected] ~]# lvcreate-n lv1-l 5119 VG
Logical volume "LV1" created
[Email protected] ~]# Lvscan
ACTIVE '/dev/vg/lv1 ' [20.00 GiB] Inherit
ACTIVE '/dev/centos_zzsrv1/swap ' [2.03 GiB] Inherit
ACTIVE '/dev/centos_zzsrv1/root ' [37.48 GiB] Inherit
[Email protected] ~]# LVDISPLAY/DEV/VG/LV1
---Logical volume---
LV PATH/DEV/VG/LV1
LV Name LV1
VG Name VG
LV UUID 2OHUKM-6WYJ-7TFR-LJCT-ZFZH-OCKD-F6OLR8
LV Write Access Read/write
LV Creation Host, Time Zzsrv2.localdomain, 2014-08-20 10:31: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 8192
Block Device 253:2
[Email protected] ~]# Vgdisplay VG
---Volume Group---
VG Name VG
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 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 5119/20.00 GiB
Free pe/size 0/0 → Note here, there is no space left, indicating that all the space has been used
VG UUID QHPCWT-MJRD-XCST-QBAC-XM94-B1H4-P2NQDF