LVM练习
2017-11-15 21:23
120 查看
首先将虚拟机desktop重置
1.
[root@localhost ~]# du -sh
28M .
[root@localhost ~]# df -h ## 查看系统磁盘设备和容量
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.1G 7.0G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 473M 2.3M 442M 1% /home
[root@localhost ~]# umount /home/ ##卸载/dev/mapper/vg0-vo设备
[root@localhost ~]# e2fsck -f /dev/mapper/vg0-vo ##检测/dev/mapper/vg0-vo设备
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/mapper/vg0-vo: 24/126976 files (0.0% non-contiguous), 26573/507904 blocks
[root@localhost ~]# resize2fs /dev/mapper/vg0-vo 250M ##减缩文件系统至250M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vg0-vo to 256000 (1k) blocks.
The filesystem on /dev/mapper/vg0-vo is now 256000 blocks long.
[root@localhost ~]# lvreduce -L 250M /dev/vg0/vo ##J减缩设备
Rounding size to boundary between physical extents: 252.00 MiB
WARNING: Reducing active logical volume to 252.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vo? [y/n]: y
Reducing logical volume vo to 252.00 MiB
Logical volume vo successfully resized
[root@localhost ~]# mount -a ## 自动挂载
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.1G 7.0G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 234M 2.1M 216M 1% /home
[root@localhost ~]#
2.
[root@localhost ~]# dd if=/dev/zero of=/swapfile bs=1M count=512 ##截取大小为512M的文件
512+0 records in
512+0 records out
536870912 bytes (537 MB) copied, 4.45746 s, 120 MB/s
[root@localhost ~]# mkswap /swapfile ##格式化为swp格式
Setting up swapspace version 1, size = 524284 KiB
no label, UUID=e8e3ae0d-3bf0-4c44-a7ae-2ac1bb07df94
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# swapon -s
Filename Type Size Used Priority
/swapfile file 524284 0 -1
3.
[root@localhost ~]# fdisk /dev/vdb ##创建新的分区
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): p
Partition number (2-4, default 2):
First sector (1026048-20971519, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e ##选择逻辑卷分区格式
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x09ee18d7
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 8e Linux LVM
/dev/vdb2 1026048 3123199 1048576 8e Linux LVM
Command (m for help): wq
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@localhost ~]# partprobe ##同步分区
[root@localhost ~]# pvcreate /dev/vdb2 ##把/dev/vdb2加入到PV中
Physical volume "/dev/vdb2" successfully created
[root@localhost ~]# vgcreate -s 8M westos /dev/vdb2 ##把/dev/vdb2加入到VG
Volume group "westos" successfully created
[root@localhost ~]# lvcreate -l 100 -n westoslv0 westos ##
Logical volume "westoslv0" created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 vg0 lvm2 a-- 496.00m 244.00m
/dev/vdb2 westos lvm2 a-- 1016.00m 216.00m
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mkfs.ext4 /dev/mapper/westos-westoslv0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkdir /mnt/westos
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1
a023
10473900 3673720 6800180 36% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 80 942580 1% /dev/shm
tmpfs 942660 17048 925612 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 239527 2083 220549 1% /home
/dev/mapper/westos-westoslv0 789904 1608 730952 1% /mnt/westos
相关文章推荐
- 马哥2016全新Linux+Python高端运维班-Linux bash脚本练习,及软RAID,LVM逻辑卷管理
- 关于LVM的练习
- 实现LVM逻辑卷实例练习
- RHCE关于软RAID,LVM的练习笔记
- sql上机练习1
- c++ primer 17.4.1节练习
- java代码----方法类练习中~~~未领会
- 【编程练习】收集的一些c++代码片,算法排序,读文件,写日志,快速求积分等等
- python简单练习2
- 20111109编程练习1:洗牌和发牌
- 指针练习-19
- python game练习4
- Python练习-- iterator
- 线段树练习(4)poj2828 Buy Tickets
- table练习
- 练习: 用脚本实现自动建立swap分区,并自动激活
- 《学习OpenCV(中文版)》第4章 练习3b
- Java编程思想第四版*第七章*个人练习
- oracle语法练习汇总
- LVM逻辑卷分区笔记