- [root@server8 ~]# fdisk -cu /dev/vdb
- Command (m for help): n
- Command action
- e extended
- p primary partition (1-4)
- p
- Partition number (1-4): 1
- First sector (2048-10485759, default 2048):
- Using default value 2048
- Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +500M
- Command (m for help): t
- Selected partition 1
- Hex code (type L to list codes): 8e
- Changed system type of partition 1 to 8e (Linux LVM)
- Command (m for help): w
- The partition table has been altered!
- Calling ioctl() to re-read partition table.
- Syncing disks.
- [root@server8 ~]# cat /proc/partitions
- major minor #blocks name
- 252 0 8388608 vda
- 252 1 512000 vda1
- 252 2 7875584 vda2
- 252 16 5242880 vdb
- 252 17 512000 vdb1
- 253 0 6856704 dm-0
- 253 1 1015808 dm-1
- [root@server8 ~]# pvcreate /dev/vdb1 将物理存储打为pv
- [root@server8 ~]# vgcreate newvg /dev/vdb1将PV打为VG
- Volume group "newvg" successfully created
- [root@server8 ~]# lvcreate -n newlv -L 200M newvg -L为最终大小 -n后接LV名字
- Logical volume "newlv" created
- [root@server8 ~]# mkfs -t ext4 /dev/mapper/newvg-newlv 格式化
- [root@server8 ~]# mkdir /lv
- [root@server8 ~]# mount /dev/mapper/newvg-newlv /lv手动挂载
- [root@server8 ~]# vi /etc/fstab 开机自动挂载
- /dev/mapper/newvg-newlv /lv ext4 defaults 0 0
- [root@server8 ~]# umount /lv
- [root@server8 ~]# mount -a
- [root@server8 ~]# df
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6748936 1331260 5074844 21% /
- tmpfs 498072 0 498072 0% /dev/shm
- /dev/vda1 495844 31932 438312 7% /boot
- /dev/mapper/newvg-newlv
- 198337 5646 182451 4% /lv
扩展逻辑卷和 Ext4 文件系统
- [root@server8 ~]# lvextend -L +100M /dev/mapper/newvg-newlv 拉伸LV
- [root@server8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6.5G 1.3G 4.9G 21% /
- tmpfs 487M 0 487M 0% /dev/shm
- /dev/vda1 485M 32M 429M 7% /boot
- /dev/mapper/newvg-newlv
- 194M 5.6M 179M 4% /lv
- [root@server8 ~]# resize2fs -p /dev/mapper/newvg-newlv拉伸文件系统
- resize2fs 1.41.12 (17-May-2010)
- Filesystem at /dev/mapper/newvg-newlv is mounted on /lv; on-line resizing required
- old desc_blocks = 1, new_desc_blocks = 2
- Performing an on-line resize of /dev/mapper/newvg-newlv to 307200 (1k) blocks.
- The filesystem on /dev/mapper/newvg-newlv is now 307200 blocks long.
- [root@server8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6.5G 1.3G 4.9G 21% /
- tmpfs 487M 0 487M 0% /dev/shm
- /dev/vda1 485M 32M 429M 7% /boot
- /dev/mapper/newvg-newlv
- 291M 6.1M 270M 3% /lv
缩减LVS
- [root@server8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6.5G 1.3G 4.9G 21% /
- tmpfs 487M 0 487M 0% /dev/shm
- /dev/vda1 485M 32M 429M 7% /boot
- /dev/mapper/newvg-newlv
- 291M 6.1M 270M 3% /lv
- 1.[root@server8 ~]# umount /lv 卸载
- [root@server8 ~]# lvs
- LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
- newlv newvg -wi-a--- 300.00m
- lv_root vg_server8 -wi-ao-- 6.54g
- lv_swap vg_server8 -wi-ao-- 992.00m
- 2,[root@server8 ~]# fsck -f /dev/mapper/newvg-newlv 以在进行大小调整之前验证所有文件系统数据结构是否都已得到清理
- fsck from util-linux-ng 2.17.2
- e2fsck 1.41.12 (17-May-2010)
- 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/newvg-newlv: 11/77824 files (0.0% non-contiguous), 15979/307200 blocks
- [root@server8 ~]# resize2fs /dev/mapper/newvg-newlv 200M 会将文件系统大小调整为200M ,假设逻辑卷大于 200M 。
- resize2fs 1.41.12 (17-May-2010)
- Resizing the filesystem on /dev/mapper/newvg-newlv to 204800 (1k) blocks.
- The filesystem on /dev/mapper/newvg-newlv is now 204800 blocks long.
- [root@server8 ~]# lvreduce -L 200 /dev/mapper/newvg-newlv 会将逻辑卷减小到200M
- WARNING: Reducing active logical volume to 200.00 MiB
- THIS MAY DESTROY YOUR DATA (filesystem etc.)
- Do you really want to reduce newlv? [y/n]: y
- Reducing logical volume newlv to 200.00 MiB
- Logical volume newlv successfully resized
- [root@server8 ~]# mount -a
- [root@server8 ~]# df
- Filesystem 1K-blocks Used Available Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6748936 1331836 5074268 21% /
- tmpfs 498072 0 498072 0% /dev/shm
- /dev/vda1 495844 31932 438312 7% /boot
- /dev/mapper/newvg-newlv
- 198337 5646 182457 4% /lv
- [root@server8 ~]# df -h
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/vg_server8-lv_root
- 6.5G 1.3G 4.9G 21% /
- tmpfs 487M 0 487M 0% /dev/shm
- /dev/vda1 485M 32M 429M 7% /boot
- /dev/mapper/newvg-newlv
- 194M 5.6M 179M 4% /lv