虚拟机默认磁盘类型
scsi硬盘
分区符MBR(512字节)
三部分组成:
引导程序: 446字节(bootloader)
分区表: 64字节
魔数: 2字节(55AA)
分区:
主分区+扩展分区(扩展分区之上建立了逻辑分区)
1. 即扩展分区是逻辑分区的资源池,逻辑分区的总大小即扩展分区大小
2. 扩展分区不能直接使用,扩展分区必须首先创建成逻辑分区才能使用
查看磁盘:
ls /dev/sd*
例子1:/dev/sda1
表示第一块系统识别到scsi硬盘的第一个分区
文件系统:
EXT4:是centos6默认的文件系统
XFS: 是centos7系统默认的文件系统
fdisk分区演示–创建主分区
第一步:关机添加磁盘
略
第二步:查看磁盘
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb
第三步:fdisk创建主分区
[root@ken ~]# 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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe140b235.
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-41943039, default 2048): #分区磁盘起始位,默认值,回车即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G #磁盘大小选择,加号不能省略,回车即可
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): P #查看分区是否建立
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe140b235
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
Command (m for help): W #w保存退出,q是不保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第四步:查看磁盘
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
第五步:格式化,安装文件系统
[root@ken ~]# mkfs.xfs /dev/sdb1 #格式化成centos7系统默认的文件系统类型XFS
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=327680 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1310720, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第六步:挂载磁盘至本地目录
[root@ken ~]# mkdir /xfs_ken #创建本地目录
[root@ken ~]# mount /dev/sdb1 /xfs_ken #使用mount进行挂载
第七步:查看挂载信息
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 5.0G 33M 5.0G 1% /xfs_ken
第八步:开机自动挂载
方法一:系统容易起不来
echo “/dev/sdb1 /xfs_ken xfs defaults 0 0” >> /etc/fstab
方法二:
[root@ken ~]# echo “mount /dev/sdb1 /xfs_ken” >> /etc/rc.local
[root@ken ~]# chmod +x /etc/rc.d/rc.local
fdisk分区演示–创建逻辑分区
第一步:fdisk添加扩展分区
[root@ken ~]# 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): e #选择扩展分区
Partition number (2-4, default 2):
First sector (10487808-41943039, default 10487808):
Using default value 10487808
Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G #5G大小
Partition 2 of type Extended and of size 5 GiB is set
Command (m for help): P #查看分区
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe140b235
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 5 Extended
Command (m for help): w #保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第二步:创建逻辑分区
[root@ken ~]# 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, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): l #创建逻辑分区
Adding logical partition 5
First sector (10489856-20973567, default 10489856):
Using default value 10489856
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +10G #逻辑分区大小不能超过扩展分区大小
Value out of range.
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2g
Unsupported suffix: ‘g’.
Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte)
2^N: K (KibiByte), M (MebiByte), G (GibiByte)
Last sector, +sectors or +size{K,M,G} (10489856-20973567, default 20973567): +2G
Partition 5 of type Linux and of size 2 GiB is set
Command (m for help): P
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe140b235
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 5 Extended
/dev/sdb5 10489856 14684159 2097152 83 Linux
Command (m for help): W
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
第三步:创建文件系统
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5
[root@ken ~]# mkfs.xfs /dev/sdb5
meta-data=/dev/sdb5 isize=512 agcount=4, agsize=131072 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524288, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第四步:开机自动挂载
[root@ken ~]# echo “mount /dev/sdb5 /xfs_ken” >> /etc/rc.local
验证写入位置
第一步:挂载磁盘
[root@ken ~]# vim /etc/fstab
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@ken ~]# mount -a #可以吧文件fsta里面未挂载的磁盘进行挂载
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 5.0G 33M 5.0G 1% /xfs_ken
第二步:写入内容
[root@ken ~]# touch /xfs_ken/{1..100}.txt
[root@ken ~]# ls /xfs_ken/
100.txt 17.txt 24.txt 31.txt 39.txt 46.txt 53.txt 60.txt 68.txt 75.txt 82.txt 8.txt 97.txt
10.txt 18.txt 25.txt 32.txt 3.txt 47.txt 54.txt 61.txt 69.txt 76.txt 83.txt 90.txt 98.txt
11.txt 19.txt 26.txt 33.txt 40.txt 48.txt 55.txt 62.txt 6.txt 77.txt 84.txt 91.txt 99.txt
12.txt 1.txt 27.txt 34.txt 41.txt 49.txt 56.txt 63.txt 70.txt 78.txt 85.txt 92.txt 9.txt
13.txt 20.txt 28.txt 35.txt 42.txt 4.txt 57.txt 64.txt 71.txt 79.txt 86.txt 93.txt
14.txt 21.txt 29.txt 36.txt 43.txt 50.txt 58.txt 65.txt 72.txt 7.txt 87.txt 94.txt
15.txt 22.txt 2.txt 37.txt 44.txt 51.txt 59.txt 66.txt 73.txt 80.txt 88.txt 95.txt
16.txt 23.txt 30.txt 38.txt 45.txt 52.txt 5.txt 67.txt 74.txt 81.txt 89.txt 96.txt
[root@ken ~]#
[root@ken ~]#
[root@ken ~]#
[root@ken ~]#
[root@ken ~]#
[root@ken ~]# umount /xfs_ken/
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
[root@ken ~]# ls /xfs_ken/
[root@ken ~]#
第三步:再次挂载磁盘
[root@ken ~]# mkdir /kenken
[root@ken ~]# mount /dev/sdb1 /kenken
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 5.0G 33M 5.0G 1% /kenken
[root@ken ~]# ls /kenken
100.txt 17.txt 24.txt 31.txt 39.txt 46.txt 53.txt 60.txt 68.txt 75.txt 82.txt 8.txt 97.txt
10.txt 18.txt 25.txt 32.txt 3.txt 47.txt 54.txt 61.txt 69.txt 76.txt 83.txt 90.txt 98.txt
11.txt 19.txt 26.txt 33.txt 40.txt 48.txt 55.txt 62.txt 6.txt 77.txt 84.txt 91.txt 99.txt
12.txt 1.txt 27.txt 34.txt 41.txt 49.txt 56.txt 63.txt 70.txt 78.txt 85.txt 92.txt 9.txt
13.txt 20.txt 28.txt 35.txt 42.txt 4.txt 57.txt 64.txt 71.txt 79.txt 86.txt 93.txt
14.txt 21.txt 29.txt 36.txt 43.txt 50.txt 58.txt 65.txt 72.txt 7.txt 87.txt 94.txt
15.txt 22.txt 2.txt 37.txt 44.txt 51.txt 59.txt 66.txt 73.txt 80.txt 88.txt 95.txt
16.txt 23.txt 30.txt 38.txt 45.txt 52.txt 5.txt 67.txt 74.txt 81.txt 89.txt 96.txt
创建交换分区SWAP–磁盘
第一步:创建分区
[root@ken ~]# 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, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p): p
Partition number (3,4, default 3):
First sector (20973568-41943039, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +2G
Partition 3 of type Linux and of size 2 GiB is set
Command (m for help): P
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0xe140b235
Device Boot Start End Blocks Id System
/dev/sdb1 2048 10487807 5242880 83 Linux
/dev/sdb2 10487808 20973567 5242880 5 Extended
/dev/sdb3 20973568 25167871 2097152 83 Linux
/dev/sdb5 10489856 14684159 2097152 83 Linux
/dev/sdb6 14686208 18880511 2097152 83 Linux
/dev/sdb7 18882560 20973567 1045504 83 Linux
Command (m for help): W
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
第二步:识别新创建的分区
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb5 /dev/sdb6 /dev/sdb7
[root@ken ~]# partprobe #加载薪建分区
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 /dev/sdb5 /dev/sdb6 /dev/sdb7
第三步:格式化为swap类型
[root@ken ~]# mkswap /dev/sdb3
Setting up swapspace version 1, size = 2097148 KiB
no label, UUID=b184f890-2ec4-417d-9aef-1ac87a78464b
第四步:启动swap
[root@ken ~]# free -h
total used free shared buff/cache available
Mem: 974M 89M 751M 7.6M 133M 733M
Swap: 2.0G 0B 2.0G
[root@ken ~]# swapon /dev/sdb3
[root@ken ~]# free -h
total used free shared buff/cache available
Mem: 974M 90M 750M 7.6M 133M 732M
Swap: 4.0G 0B 4.0G
[root@ken ~]#
第五步:开机自启
方法一:
echo “/dev/sdb3 swap swap defaults 0 0” >> /etc/fstab
方法二:
echo “swapon /dev/sdb3” >> /etc/rc.local
创建交换分区SWAP–本地文件
第一步:创建目录
[root@ken ~]# mkdir /swap
第二步:创建文件
[root@ken ~]# dd if=/dev/zero of=/swap/swap bs=2M count=2014
2014+0 records in
2014+0 records out
4223664128 bytes (4.2 GB) copied, 29.3039 s, 144 MB/s
第三步:格式化
[root@ken ~]# mkswap /swap/swap
Setting up swapspace version 1, size = 4124668 KiB
no label, UUID=211cb23a-49b5-46fc-b568-f167d4b6d06a
第四步:写入文件
[root@ken ~]# echo “/swap/swap swap swap defaults 0 0” >> /etc/fstab
[root@ken ~]#
[root@ken ~]#
[root@ken ~]#
[root@ken ~]# mount -a
[root@ken ~]# free -h
total used free shared buff/cache available
Mem: 974M 85M 69M 7.6M 819M 712M
Swap: 4.0G 0B 4.0G
[root@ken ~]# swapon -a
swapon: /swap/swap: insecure permissions 0644, 0600 suggested.
[root@ken ~]# free -h
total used free shared buff/cache available
Mem: 974M 88M 66M 7.6M 819M 709M
Swap: 7.9G 0B 7.9G
第五步:修改权限
[root@ken ~]# chmod 0600 /swap/swap
关掉交换分区
[root@ken ~]# swapoff -a
[root@ken ~]# free -h
total used free shared buff/cache available
Mem: 974M 83M 70M 7.6M 820M 714M
Swap: 0B 0B 0B
LVM逻辑卷管理
LVM: logical volumes manager
LVM逻辑卷部署
物理卷–》卷组–》逻辑卷
第一步;添加磁盘
l略
第二步:查看磁盘
[root@ken ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc
第三步:创建物理卷
[root@ken ~]# pvcreate /dev/sd{b,c}
Physical volume “/dev/sdb” successfully created.
Physical volume “/dev/sdc” successfully created.
第四步:创建卷组
[root@ken ~]# vgcreate vg_ken /dev/sd{b,c} #卷组名为vg_ken,物理卷/dev/sd{b,c}
Volume group “vg_ken” successfully created
第五步:逻辑卷创建
方式一:使用L进行容量指定
[root@ken ~]# lvcreate -L 500M -n lv_ken1 vg_ken
Logical volume “lv_ken1” created.
方式二:使用 l 指定PE数量
[root@ken ~]# lvcreate -l 125 -n lv_ken2 vg_ken
Logical volume “lv_ken2” created.
第六步:格式化逻辑卷
[root@ken ~]# mkfs.xfs /dev/vg_ken/lv_ken1
meta-data=/dev/vg_ken/lv_ken1 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@ken ~]# mkfs.xfs /dev/vg_ken/lv_ken2
meta-data=/dev/vg_ken/lv_ken2 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
第七步:挂载使用
[root@ken ~]# mkdir /ken1
[root@ken ~]# mkdir /ken2
[root@ken ~]# mount /dev/vg_ken/lv_ken1 /ken1
[root@ken ~]# mount /dev/vg_ken/lv_ken2 /ken2
第八步:查看挂载信息
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 497M 26M 472M 6% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
第九步:开机自启
方法一: 写入/etc/fstab
[root@ken ~]# echo “/dev/mapper/vg_ken-lv_ken1 /ken1 xfs defaults 0 0” >> /etc/fstab
方法二:写入rc.local
echo “mount /dev/vg_ken/lv_ken1 /ken1” >> /etc/rc.local
LVM在线扩容–XFS格式
第一步:直接扩容
[root@ken ~]# lvextend -L 800M /dev/vg_ken/lv_ken1
Size of logical volume vg_ken/lv_ken1 changed from 500.00 MiB (125 extents) to 800.00 MiB (200 extents).
Logical volume vg_ken/lv_ken1 successfully resized.
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 497M 26M 472M 6% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
第二步:xfs_growfs使配置生效
[root@ken ~]# xfs_growfs /dev/vg_ken/lv_ken1
meta-data=/dev/mapper/vg_ken-lv_ken1 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 128000 to 204800
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
[root@ken ~]#
注意:
1. xfs格式的磁盘不需要卸载即可直接在线进行扩容
2. extX格式需要先卸载再进行扩容
3. XFS格式的磁盘类型只支持扩容不支持缩容
LVM扩容–EXT4格式
第一步:创建一个ext4格式的逻辑卷
[root@ken ~]# lvcreate -L 500M -n lv_ext4 vg_ken
Logical volume “lv_ext4” created.
第二步:格式化为ext4格式
[root@ken ~]# mkfs.ext4 /dev/vg_ken/lv_ext4
第三步:挂载
[root@ken ~]# mkdir /ext4
[root@ken ~]# mount /dev/vg_ken/lv_ext4 /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
/dev/mapper/vg_ken-lv_ext4 477M 2.3M 445M 1% /ext4
第四步:开始扩容
卸载
[root@ken ~]# umount /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
第五步:扩容lventend
[root@ken ~]# lvextend -L 800M /dev/vg_ken/lv_ext4
Size of logical volume vg_ken/lv_ext4 changed from 500.00 MiB (125 extents) to 800.00 MiB (200 extents).
Logical volume vg_ken/lv_ext4 successfully resized.
第六步:磁盘检测
[root@ken ~]# e2fsck -f /dev/vg_ken/lv_ext4
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_ken/lv_ext4: 11/128016 files (0.0% non-contiguous), 26684/512000 blocks
第七步:扩容resize2fs
[root@ken ~]# resize2fs //dev/vg_ken/lv_ext4
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on //dev/vg_ken/lv_ext4 to 819200 (1k) blocks.
The filesystem on //dev/vg_ken/lv_ext4 is now 819200 blocks long.
第八步:挂载使用
[root@ken ~]# mount //dev/vg_ken/lv_ext4 /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
/dev/mapper/vg_ken-lv_ext4 767M 2.5M 721M 1% /ext4
LVM缩容–EXT4格式
第一步:卸载
[root@ken ~]# umount /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
第二步:检测
[root@ken ~]# e2fsck -f /dev/vg_ken/lv_ext4
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_ken/lv_ext4: 11/203200 files (0.0% non-contiguous), 36417/819200 blocks
第三步:缩容
[root@ken ~]# resize2fs /dev/vg_ken/lv_ext4 500M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg_ken/lv_ext4 to 512000 (1k) blocks.
The filesystem on /dev/vg_ken/lv_ext4 is now 512000 blocks long.
第四步:执行lvreduce
[root@ken ~]# lvreduce -L 500M /dev/vg_ken/lv_ext4
WARNING: Reducing active logical volume to 500.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg_ken/lv_ext4? [y/n]: y
Size of logical volume vg_ken/lv_ext4 changed from 800.00 MiB (200 extents) to 500.00 MiB (125 extents).
Logical volume vg_ken/lv_ext4 successfully resized.
第五步:挂载使用
[root@ken ~]# mount //dev/vg_ken/lv_ext4 /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg_ken-lv_ken1 797M 26M 772M 4% /ken1
/dev/mapper/vg_ken-lv_ken2 497M 26M 472M 6% /ken2
/dev/mapper/vg_ken-lv_ext4 477M 2.3M 445M 1% /ext4
删除逻辑卷
逻辑卷 –》卷组–》物理卷
第一步:卸载正在使用的逻辑卷
[root@ken ~]# umount /ken1
[root@ken ~]# umount /ken2
[root@ken ~]# umount /ext4
[root@ken ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 17G 1.4G 16G 8% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 488M 0 488M 0% /dev/shm
tmpfs 488M 7.7M 480M 2% /run
tmpfs 488M 0 488M 0% /sys/fs/cgroup
/dev/sda1 1014M 130M 885M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
第二步:删除逻辑卷
[root@ken ~]# lvremove /dev/vg_ken/lv_
lv_ext4 lv_ken1 lv_ken2
[root@ken ~]# lvremove /dev/vg_ken/lv_*
Do you really want to remove active logical volume vg_ken/lv_ken1? [y/n]: y
Logical volume “lv_ken1” successfully removed
Do you really want to remove active logical volume vg_ken/lv_ken2? [y/n]: y
Logical volume “lv_ken2” successfully removed
Do you really want to remove active logical volume vg_ken/lv_ext4? [y/n]: y
Logical volume “lv_ext4” successfully removed
第三步:删除卷组
[root@ken ~]# vgremove vg_ken
Volume group “vg_ken” successfully removed
第四步:删除物理卷
[root@ken ~]# pvremove /dev/sd{b,c}
Labels on physical volume “/dev/sdb” successfully wiped.
Labels on physical volume “/dev/sdc” successfully wiped.
第五步:查看
[root@ken ~]# pvdisplay
— Physical volume —
PV Name /dev/sda2 #只有系统自带的了
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID MDIeKf-Tbul-ST5P-ua57-lCVG-bPWM-o32gdQ