linux 磁盘分区挂载-LVM-物理卷PV,卷组VG,逻辑卷LV
题外话:如果是数据磁盘,建议都使用LVM 这样避免出现空间不足,进行迁移。 部分云服务器就可以不考虑这个问题。1.磁盘分区
具体详见:linux 磁盘分区挂载-fdisk
fdisk -l 查看磁盘分区情况
2.创建物理卷PV
pvcreate 设备名称
# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
pvdisplay 产看详细物理卷信息
root@localhost Desktop]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID aK2Fc8-CdE3-fNm5-HvD4-OYNf-efGB-EZGjiQ
--- Physical volume ---
PV Name /dev/sdb1
VG Name vgnew
PV Size 200.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 49
Free PE 40
Allocated PE 9
PV UUID ukTCyL-09v8-Bs6C-tDYs-JpNQ-vrG3-2iRUDG
--- Physical volume ---
PV Name /dev/sdb2
VG Name vgnew
PV Size 120.00 MiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 29
Free PE 29
Allocated PE 0
PV UUID fVstso-ytGO-Y7Qw-ndkJ-E1Pt-aR65-aViPdz
"/dev/sdb3" is a new physical volume of "20.00 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 20.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 1Tyiu2-xzt0-3Kw6-9Gmg-5CSl-1mHT-kIq5k2
pvscan/pvs 查看物理卷信息
# pvs
PV VG FmtAttr PSize PFree
/dev/sda2rhellvm2 a-- 19.51g 0
/dev/sdb1vgnew lvm2 a--196.00m 160.00m
/dev/sdb2vgnew lvm2 a--116.00m 116.00m
/dev/sdb3 lvm2 a-- 20.00m20.00m
可以看到设备sdb3 没有VG ,没有卷组,下面来创建卷组
3.创建卷组 vgcreate
# vgcreate vg001 /dev/sdb3
Volume group "vg001" successfully created
# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n-19.51g 0
vg001 1 0 0 wz--n-16.00m16.00m
vgnew 2 1 0 wz--n- 312.00m 276.00m
vgcreat-s xxM 指定PE值大小,默认为4M 。
4.创建逻辑卷 lvcreate
# lvcreate -n lv001 -L 4M vg001
Logical volume "lv001" created
# lvs
LV VG Attr LSizePool Origin Data%Move Log Cpy%Sync Convert
rootrhel-wi-ao---- 17.51g
swaprhel-wi-ao----2.00g
lv001 vg001 -wi-a-----4.00m
newlv vgnew -wi-ao---- 36.00mmk
lvcreate -n 逻辑卷名 -L xxM 逻辑卷大小 卷组
5.挂载逻辑卷,只有挂载之后才能使用逻辑卷
挂载之前先要对逻辑券进行格式化,这里先格式化成为ext4格式
# mkfs.ext4 /dev/vg001/lv001
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
1024 inodes, 4096 blocks
204 blocks (4.98%) reserved for the super user
First data block=1
Maximum filesystem blocks=4194304
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group
Allocating group tables: done
Writing inode tables: done
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
# mkdir /mkd //新建文件夹
# mount /dev/vg001/lv001 /mkd //挂载
mkfs.xfs -f /dev/vg001/lv001
# df -h//产看挂载信息
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root 18G3.3G 15G19% /
devtmpfs 905M 0905M 0% /dev
tmpfs 914M144K914M 1% /dev/shm
tmpfs 914M8.9M905M 1% /run
tmpfs 914M 0914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M204K9.6M 3% /media
/dev/sda1 497M119M379M24% /boot
/dev/sr0 3.5G3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv0012.9M 45K2.6M 2% /mkd
# vim /etc/fstab //编辑/etc/fstab 文件设置开机自动挂载
6.扩展逻辑卷
# vgdisplay vg001 ----查看逻辑卷所在的卷组信息
--- Volume group ---
VG Name vg001
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No6
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 16.00 MiB
PE Size 4.00 MiB
Total PE 4
Alloc PE / Size 1 / 4.00 MiB
FreePE / Size 3 / 12.00 MiB
VG UUID 0IGKxv-NQRG-PNue-UbR3-1O7S-yW4K-f10I3E
卷组还有剩余 12M 可以直接扩展
首先在 /mkd文件夹下建立一个简单的文件,测试文件会不会丢失,建立文件省略。。。。
# ll
total 14
drwx------. 2 root root 12288 May 30 02:26 lost+found
-rw-r--r--. 1 root root 8 May 30 03:15 test.txt
# lvextend -l +1 /dev/vg001/lv001---扩展加1个PE大小的值
Extending logical volume lv001 to 8.00 MiB
Logical volume lv001 successfully resized
# df -h--查看逻辑卷 ,可以看到该逻辑卷并没有增加,
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root 18G3.3G 15G19% /
devtmpfs 905M 0905M 0% /dev
tmpfs 914M144K914M 1% /dev/shm
tmpfs 914M9.0M905M 1% /run
tmpfs 914M 0914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M204K9.6M 3% /media
/dev/sda1 497M119M379M24% /boot
/dev/sr0 3.5G3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv0012.9M 47K2.6M 2% /mkd
# resize2fs /dev/vg001/lv001---使逻辑卷扩展生效
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg001/lv001 is mounted on /mkd; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg001/lv001 is now 8192 blocks long.
# df -h ---重新查看逻辑卷大小,成功扩展
Filesystem SizeUsed Avail Use% Mounted on
/dev/mapper/rhel-root 18G3.3G 15G19% /
devtmpfs 905M 0905M 0% /dev
tmpfs 914M144K914M 1% /dev/shm
tmpfs 914M9.0M905M 1% /run
tmpfs 914M 0914M 0% /sys/fs/cgroup
/dev/mapper/vgnew-newlv 11M204K9.6M 3% /media
/dev/sda1 497M119M379M24% /boot
/dev/sr0 3.5G3.5G 0 100% /run/media/new/RHEL-7.0 Server.x86_64
/dev/mapper/vg001-lv0016.9M 47K6.6M 1% /mkd
文件无损坏
7.逻辑卷缩减
首先需要卸载挂载点
# umount /mkd --卸载挂载点
# resize2fs /dev/vg001/lv001 4M--调整文件系统大小
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg001/lv001' first.
# e2fsck -f /dev/vg001/lv001 --先执行这个
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/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/8192 blocks
# resize2fs /dev/vg001/lv001 4M --重新调整文件系统大小
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg001/lv001 to 4096 (1k) blocks.
The filesystem on /dev/vg001/lv001 is now 4096 blocks long.
# e2fsck -f /dev/vg001/lv001--重新检查文件系统
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/vg001/lv001: 12/1024 files (8.3% non-contiguous), 1204/4096 blocks
# lvreduce -l -1 /dev/vg001/lv001 --缩减一个逻辑卷为1个PE值大小
WARNING: Reducing active logical volume to 4.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv001? : y
Reducing logical volume lv001 to 4.00 MiB
Logical volume lv001 successfully resized
8.删除逻辑卷 lvremove
# lvremove /dev/vg001/lv001
Do you really want to remove active logical volume lv001? : y
Logical volume "lv001" successfully removed
9.删除卷组,缩减卷组
vgreduce 若一个卷组包含多个PV,缩减是删除PV得到的
vgremove 删除一个卷组
10.删除物理卷
pvremove
游戏是我的全部图景,我将演绎所有的游戏角色,我是每个活着角色的传奇。 --沐清娴
http://blog.itpub.net/29494175/viewspace-2913762/
页:
[1]