[[email protected] ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 7月 22 13:47 /dev/sda
brw-rw----. 1 root disk 8, 1 7月 22 13:47 /dev/sda1
brw-rw----. 1 root disk 8, 2 7月 22 13:47 /dev/sda2
brw-rw----. 1 root disk 8, 16 7月 22 13:47 /dev/sdb
brw-rw----. 1 root disk 8, 32 7月 22 13:47 /dev/sdc
brw-rw----. 1 root disk 8, 48 7月 22 13:47 /dev/sdd
-----------------------------------------------------------------------
[[email protected] ~]# fdisk /dev/sdb 硬盘分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklab el
Building a new DOS disklabel with disk identifier 0x2f62d036.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won‘t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).
Command (m for help): n 设定新的硬盘分割区
Command action
e extended
p primary partition (1-4)
p 输入p硬盘位[主要]分割区
Partition number (1-4): 1
First cylinder (1-130, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): 130
Using default value 130
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f62d036
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
------------------------------------------------------------------------
[[email protected] ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 7月 22 13:47 /dev/sda
brw-rw----. 1 root disk 8, 1 7月 22 13:47 /dev/sda1
brw-rw----. 1 root disk 8, 2 7月 22 13:47 /dev/sda2
brw-rw----. 1 root disk 8, 16 7月 22 14:13 /dev/sdb
brw-rw----. 1 root disk 8, 17 7月 22 14:13 /dev/sdb1
brw-rw----. 1 root disk 8, 32 7月 22 13:47 /dev/sdc
brw-rw----. 1 root disk 8, 48 7月 22 13:47 /dev/sdd
-----------------------------------------------------------------------
[[email protected] ~]# fdisk -l /dev/sdb 查看第二块硬盘分区情况
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f62d036
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
--------------------------------------------------------------
[[email protected] ~]# mkfs.ext4 /dev/sdb1 把第二块硬盘的第一个主分区格式化为ext4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65280 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
------------------------------------------------------------------------------
[[email protected] ~]# mkdir /dir01 建立dir01的目录
-----------------------------------------------------------------------------
[[email protected] ~]# mount /dev/sdb1 /dir01 挂载sdb1到dir01目录
-----------------------------------------------------------------------------
[[email protected] ~]# df -h 查看sdb1的容量
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.0G 4.2G 42% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/sdb1 1004M 18M 936M 2% /dir01
------------------------------------------------------------------------------
[[email protected] ~]# yes > /dir01/file01 输入YES到file01文件下
yes: 标准输出: 设备上没有空间
yes: 写入错误
-------------------------------------------------------------------------------
[[email protected] ~]# df -h 查看容量已满
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/sdb1 1004M 1004M 0 100% /dir01
-----------------------------------------------------------
[[email protected] ~]# rm -rf /file01 删除file01文件夹下内容
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/sdb1 1004M 18M 936M 2% /dir01
--------------------------------------------------------------------
[[email protected] ~]# umount /dir01 撤销挂载
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
---------------------------------------------------------------------
[[email protected] ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f62d036
Device Boot Start End Blocks Id System
/dev/sdb1 1 130 1044193+ 83 Linux
----------------------------------------------------------------------------
[[email protected] ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).
Command (m for help): d 删除硬盘分区
Selected partition 1
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
-------------------------------------------------------------------------------
[[email protected] ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2f62d036
Device Boot Start End Blocks Id System
[[email protected] ~]# pvcreate /dev/s
scd0 sda2 sdd sg2 shm/ stderr systty
sda sdb sg0 sg3 snapshot stdin
sda1 sdc sg1 sg4 sr0 stdout
-------------------------------------------------------------------------------
[[email protected] ~]# pvcreate /dev/sdb /dev/sdc /dev/sdd 建立物理卷
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
Physical volume "/dev/sdd" successfully created
[[email protected] ~]# pvdisplay /dev/sdb 显示物理卷的属性
"/dev/sdb" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID ATCWs5-vhlt-GPe2-xhCM-QtOi-6NbW-bYYdzs
[[email protected] ~]# pvscan 列出找到的物理卷
PV /dev/sda2 VG VolGroup lvm2 [11.51 GiB / 0 free]
PV /dev/sdb lvm2 [1.00 GiB]
PV /dev/sdc lvm2 [1.00 GiB]
PV /dev/sdd lvm2 [1.00 GiB]
Total: 4 [14.51 GiB] / in use: 1 [11.51 GiB] / in no VG: 3 [3.00 GiB]
-----------------------------------------------------------------------------
[[email protected] ~]# vgcreate vg01 /dev/sdb /dev/sdc 创建LVM卷组
Volume group "vg01" successfully created
[[email protected] ~]# vgdisplay vg01 显示LVM卷的信息
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0 / 0
Free PE / Size 510 / 1.99 GiB
VG UUID ZV5CW4-Vt4o-nFnV-zvDI-a5p4-fwHg-nuyX5I
[[email protected] ~]# vgscan 列出LVM物理卷
Reading all physical volumes. This may take a while...
Found volume group "vg01" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2
-----------------------------------------------------------------------
[[email protected] ~]# lvcreate -L 550M -n lv01 vg01 创建LVM的逻辑卷划分550M容量
Rounding up size to full physical extent 552.00 MiB
Logical volume "lv01" created
[[email protected] ~]# lvdisplay vg01/lv01 显示逻辑卷属性
--- Logical volume ---
LV Path /dev/vg01/lv01
LV Name lv01
VG Name vg01
LV UUID oF7dp3-DtFH-QdYB-yLOt-riys-36hX-lhySS1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-22 15:58:25 +0800
LV Status available
# open 0
LV Size 552.00 MiB
Current LE 138
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
[[email protected] ~]# lvscan 列出逻辑卷内容
ACTIVE ‘/dev/vg01/lv01‘ [552.00 MiB] inherit
ACTIVE ‘/dev/VolGroup/lv_root‘ [7.57 GiB] inherit
ACTIVE ‘/dev/VolGroup/lv_swap‘ [3.94 GiB] inherit
----------------------------------------------------------------------
[[email protected] ~]# mkfs.ext4 /dev/vg01/lv01 把第逻辑卷主分区格式化为ext4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
35360 inodes, 141312 blocks
7065 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=146800640
5 block groups
32768 blocks per group, 32768 fragments per group
7072 inodes per group
Superblock backups stored on blocks:
32768, 98304
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
---------------------------------------------------------------------------
[[email protected] ~]# mount /dev/vg01/lv01 /dir01 挂载逻辑卷到/dir目录
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/mapper/vg01-lv01
544M 17M 500M 4% /dir01
---------------------------------------------------------------------------------
[[email protected] ~]# lvextend -L +1G /dev/vg01/lv01 在LVM卷组的逻辑卷中增加1G容量
Extending logical volume lv01 to 1.54 GiB
Logical volume lv01 successfully resized
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/mapper/vg01-lv01
544M 17M 500M 4% /dir01
[[email protected] ~]# lvdisplay /dev/vg01/lv01
--- Logical volume ---
LV Path /dev/vg01/lv01
LV Name lv01
VG Name vg01
LV UUID oF7dp3-DtFH-QdYB-yLOt-riys-36hX-lhySS1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-22 15:58:25 +0800
LV Status available
# open 1
LV Size 1.54 GiB
Current LE 394
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
[[email protected] ~]# resize2fs -f /dev/vg01/lv01 动态修改逻辑卷分区的大小
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg01/lv01 is mounted on /dir01; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg01/lv01 to 403456 (4k) blocks.
The filesystem on /dev/vg01/lv01 is now 403456 blocks long.
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/mapper/vg01-lv01
1.6G 17M 1.5G 2% /dir01
---------------------------------------------------------------------------
[[email protected] ~]# vgextend vg01 /dev/sdd 把物理卷sdd加入到vg01卷组中
Volume group "vg01" successfully extended
[[email protected] ~]# vgdisplay vg01
--- Volume group ---
VG Name vg01
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 2.99 GiB
PE Size 4.00 MiB
Total PE 765
Alloc PE / Size 394 / 1.54 GiB
Free PE / Size 371 / 1.45 GiB
VG UUID ZV5CW4-Vt4o-nFnV-zvDI-a5p4-fwHg-nuyX5I
[[email protected] ~]# lvextend -L +1G /dev/vg01/lv01 在LVM卷组的逻辑卷中增加1G容量
Extending logical volume lv01 to 2.54 GiB
Logical volume lv01 successfully resized
[[email protected] ~]# lvdisplay /dev/vg01/lv01
--- Logical volume ---
LV Path /dev/vg01/lv01
LV Name lv01
VG Name vg01
LV UUID oF7dp3-DtFH-QdYB-yLOt-riys-36hX-lhySS1
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-22 15:58:25 +0800
LV Status available
# open 1
LV Size 2.54 GiB
Current LE 650
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:2
[[email protected] ~]# resize2fs -f /dev/vg01/lv01
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg01/lv01 is mounted on /dir01; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/vg01/lv01 to 665600 (4k) blocks.
The filesystem on /dev/vg01/lv01 is now 665600 blocks long.
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
/dev/mapper/vg01-lv01
2.6G 17M 2.4G 1% /dir01
[[email protected] ~]# umount /dir01 取消逻辑卷的挂载,可以用在/dir01中取消挂载,也可以在/dev/mapper/vg01-lv01路径中取消
[[email protected] ~]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.5G 3.1G 4.1G 43% /
tmpfs 1004M 260K 1004M 1% /dev/shm
/dev/sda1 485M 55M 405M 12% /boot
----------------------------------------------------------
[[email protected] ~]# lvremove /dev/mapper/vg01-lv01 删除逻辑卷
Do you really want to remove active logical volume lv01? [y/n]: y
Logical volume "lv01" successfully removed
---------------------------------------------------------------------
[[email protected] ~]# vgremove /dev/vg01 删除卷组
Volume group "vg01" successfully removed