实训项目3 Linux文件系统与磁盘管理(6)

2019-08-03 14:53

1 physical volume(s) resized / 0 physical volume(s) not resized # vgdisplay | grep \

VG Size 50.50 GiB vg0容量调整完毕。收工!

(2) 逻辑卷容量的调整

先查看lv0的大小

# lvdisplay /dev/vg0/lv0 | grep \

LV Size 128.00 MiB

? 增加lv0的大小

这时,vg0中没有分配的空间还有很多,所以可以放心扩容。 # lvextend -L +10M /dev/vg0/lv0

Rounding up size to full physical extent 32.00 MiB Extending logical volume lv0 to 160.00 MiB Logical volume lv0 successfully resized

观察结果,发现增加了32M,这是因为最小的分配PE(物理扩展块,大小默认是4M)的大小是32M的缘故。

好了,那现在我们能是否能够在linux文件系统中,使用160M的空间(/mnt/mylv)了吧?使用df命令查看一下文件系统的磁盘占用情况: # df

Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda3 19431712 2710648 15733980 15% /

tmpfs 255784 264 255520 1% /dev/shm /dev/sda1 198337 24247 163850 13% /boot

/dev/sdb1 388693 10254 358360 3% /mnt/mountpoint1 /dev/sdb5 641296 4 641292 1% /mnt/mountpoint2 /dev/mapper/vg0-lv0 126931 5647 114731 5% /mnt/mylv

观察最后一行,原来大小还是没有变化!虽然逻辑卷增大了,但是逻辑卷上的文件系统并未获知,还需要调整文件系统。 # resize2fs /dev/vg0/lv0

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg0/lv0 is mounted on /mnt/mylv; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1

Performing an on-line resize of /dev/vg0/lv0 to 163840 (1k) blocks. The filesystem on /dev/vg0/lv0 is now 163840 blocks long. [root@hlinux6 Desktop]# df | grep \

/dev/mapper/vg0-lv0 158667 5647 144831 4% /mnt/mylv

这时,再看,/mnt/mylv下的磁盘空间增加了。我们再来观察一下/mnt/mylv目录下的内容,看看里面的文件也是正常的

需要注意的是,我们整个操作都是在线的,没有把/mnt/mylv从文件系统中卸载(umount)

过。

? 减小lv0的大小

减小卷组的大小与增加卷组大小的操作正好相反,第一步是收缩文件系统的大小,次序千万不能错了。 首先卸载卷组

# umount /mnt/mylv

# resize2fs /dev/vg0/lv0 60M

resize2fs 1.41.12 (17-May-2010)

Please run 'e2fsck -f /dev/vg0/lv0' first. # e2fsck -f /dev/vg0/lv0

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/vg0/lv0: 14/40960 files (0.0% non-contiguous), 10820/163840 blocks # resize2fs /dev/vg0/lv0 64M

resize2fs 1.41.12 (17-May-2010)

Resizing the filesystem on /dev/vg0/lv0 to 65536 (1k) blocks. The filesystem on /dev/vg0/lv0 is now 65536 blocks long. # lvreduce -L -96M /dev/vg0/lv0

WARNING: Reducing active logical volume to 64.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv0? [y/n]: y Reducing logical volume lv0 to 64.00 MiB Logical volume lv0 successfully resized 成功完成,下面将逻辑卷挂载到文件系统中,分别查看逻辑卷本身和其在文件系统中的容量 # lvdisplay | grep \

LV Size 64.00 MiB #mount –a

# df | grep \

/dev/mapper/vg0-lv0 63461 5391 54795 9% /mnt/mylv

总结:扩展先扩展逻辑卷,再扩展文件系统 逻辑卷 而收缩时相反,先缩小文件系统,再 文件系统 收缩逻辑卷(如图)

子项目3.物理卷、卷组和逻辑卷的检查

(1) 物理卷的检查 # pvscan

PV /dev/sdb6 VG vg0 lvm2 [288.00 MiB / 224.00 MiB free] PV /dev/sdh VG vg0 lvm2 [9.97 GiB / 9.97 GiB free] PV /dev/md5 VG vg0 lvm2 [39.97 GiB / 39.97 GiB free] PV /dev/sdb7 VG vg0 lvm2 [288.00 MiB / 288.00 MiB free] Total: 4 [50.50 GiB] / in use: 4 [50.50 GiB] / in no VG: 0 [0 ]

(2) 卷组的检查 # vgscan

Reading all physical volumes. This may take a while... Found volume group \

(3) 逻辑卷的检查 # lvscan

ACTIVE '/dev/vg0/lv0' [64.00 MiB] inherit

子项目4.删除逻辑卷-卷组-物理卷

删除逻辑卷-卷组-物理卷 (必需按照先后顺序来执行删除)

如果说要彻底的来移除LVM的话,你需要把创建的步骤反过来操作。 1、umount

# umount /mnt/mylv/ 2、 移除LV

# lvremove /dev/vg0/lv0

Do you really want to remove active logical volume lv0? [y/n]: y Logical volume \

3、 移除VG # vgremove vg0

Volume group \

4、 移除PV 针对查找出来的,进行清理

# pvdisplay | grep \

PV Name /dev/md5

PV Name /dev/sdb6 PV Name /dev/sdb7 PV Name /dev/sdh

# pvremove /dev/md5 /dev/sdb6 /dev/sdb7 /dev/sdh

Labels on physical volume \ Labels on physical volume \ Labels on physical volume \ Labels on physical volume \

5、 如果是分区的话,使用 fdisk 把 ID 改回来 # 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): p

Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x00023207

Device Boot Start End Blocks Id System /dev/sdb1 1 50 401593+ 83 Linux /dev/sdb2 51 1305 10080787+ 5 Extended /dev/sdb5 51 130 642568+ 83 Linux

/dev/sdb6 131 169 313236 8e Linux LVM /dev/sdb7 170 208 313236 8e Linux LVM /dev/sdb8 209 247 313236 83 Linux

Command (m for help): t Partition number (1-8): 6

Hex code (type L to list codes): 83

Changed system type of partition 6 to 83 (Linux)

Command (m for help): t Partition number (1-8): 7

Hex code (type L to list codes): 83

Changed system type of partition 7 to 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.

6、如果有RAID设备的话,也同样清除掉吧

RAID设备的清除方法,请参考实训项目3-2 中的子项目6。

7、清除了逻辑卷和磁盘阵列后,不要忘了把/etc/fstab和/etc/mdadm.conf文件中的内容删除无用部分。

附加知识点

Mount挂载命令使用方法

语法: mount -t 类型 -o 挂接方式 源路径 目标路径 -t 详细选项:

光盘或光盘镜像:iso9660 DOS fat16文件系统:msdos

Windows 9x fat32文件系统:vfat Windows NT ntfs文件系统:ntfs

Mount Windows文件网络共享:smbfs(需内核支持)推荐cifs UNIX(LINUX) 文件网络共享:nfs -o 详细选项:

loop :用来把一个文件当成硬盘分区挂接上系统 ro :采用只读方式挂接设备 rw :采用读写方式挂接设备

iocharset :指定访问文件系统所用字符集,例如iocharset=utf8 remount :重新挂载 使用实例:

挂载windows文件共享:

mount -t smbfs -o username=admin,password=888888 //192.168.1.2/c$ /mnt/samba


实训项目3 Linux文件系统与磁盘管理(6).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:蚌埠市中小学教师初级职称认定考核实施办法(试行)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: