当前位置:   article > 正文

Linux磁盘管理实例

逻辑卷名为mylv,属于myvg卷组,大小为50个pe 2)卷组myvg中的逻辑卷的pe大小应当为1

Linux磁盘管理实例

1、调整逻辑卷大小

  1. 预先创建2GiB的分区/dev/vdb1,并用于创建卷组testvg
  2. 创建大小为200MiB的逻辑卷/dev/testvg/vo,格式化为xfs文件系统,并挂载在/mnt/vo上
  3. 将逻辑卷/dev/testvg/vo及其文件系统大小调整到300MiB,确保文件系统内容保持不变
  1. // 准备工作
  2. [root@jlin ~]# fdisk /dev/vdb
  3. Welcome to fdisk (util-linux 2.32.1).
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6. Device does not contain a recognized partition table.
  7. Created a new DOS disklabel with disk identifier 0xae75bf0a.
  8. Command (m for help): n
  9. Partition type
  10. p primary (0 primary, 0 extended, 4 free)
  11. e extended (container for logical partitions)
  12. Select (default p):
  13. Using default response p.
  14. Partition number (1-4, default 1):
  15. First sector (2048-10485759, default 2048):
  16. Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +2G
  17. Created a new partition 1 of type 'Linux' and of size 2 GiB.
  18. Command (m for help): w
  19. The partition table has been altered.
  20. Calling ioctl() to re-read partition table.
  21. Syncing disks.
  22. [root@jlin ~]# pvcreate /dev/vdb1 #创建物理卷
  23. [root@jlin ~]# vgcreate testvg /dev/vdb1 #创建卷组并将vdb1加入到卷组
  24. [root@jlin ~]# lvcreate -n vo -L 200M testvg #在卷组中分出逻辑卷
  25. [root@jlin ~]# mkfs.xfs /dev/testvg/vo #格式化为xfs
  26. [root@jlin ~]# blkid /dev/testvg/vo #查看uuid
  27. /dev/testvg/vo: UUID="fe323058-93db-428d-883c-2c0210cd10c6" TYPE="xfs"
  28. [root@jlin ~]# mkdir /mnt/vo
  29. [root@jlin ~]# vim /etc/fstab
  30. UUID="fe323058-93db-428d-883c-2c0210cd10c6" /mnt/vo xfs defaults 0 0
  31. [root@jlin ~]# mount -a
  32. // 扩展操作
  33. [root@jlin ~]# df -hT /dev/testvg/vo # 查看文件系统的类型和大小
  34. Filesystem Type Size Used Avail Use% Mounted on
  35. /dev/mapper/testvg-vo xfs 195M 12M 183M 6% /mnt/vo
  36. [root@jlin ~]# lvextend -L 300M /dev/testvg/vo
  37. [root@jlin ~]# lvs
  38. // 扩展文件系统,ext类型的文件系统用resize2fs /dev/testvg/vo ,后面接的是逻辑卷的路径。
  39. [root@jlin ~]# xfs_growfs /mnt/vo # 后面接的是挂载点的路径
  40. [root@jlin ~]# df -hT /dev/testvg/vo
  41. Filesystem Type Size Used Avail Use% Mounted on
  42. /dev/mapper/testvg-vo xfs 295M 13M 283M 5% /mnt/vo

2、添加交换分区

在系统上添加⼀个512MiB的交换分区,设置交换分区应在系统启动时自动挂载,不要删除或修改系统 上已存在的交换分区

  1. [root@jlin ~]# fdisk /dev/vdb
  2. Welcome to fdisk (util-linux 2.32.1).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Command (m for help): n
  6. Partition type
  7. p primary (1 primary, 0 extended, 3 free)
  8. e extended (container for logical partitions)
  9. Select (default p):
  10. Using default response p.
  11. Partition number (2-4, default 2):
  12. First sector (4196352-10485759, default 4196352):
  13. Last sector, +sectors or +size{K,M,G,T,P} (4196352-10485759, default 10485759):
  14. +512M
  15. Created a new partition 2 of type 'Linux' and of size 512 MiB.
  16. Command (m for help) : t
  17. Partition number ( 1,2,default 2):
  18. Hex code (type L to list all codes) : 82
  19. Changed type of partition 'Linux' to 'Linux swap / Solaris '.
  20. Command (m for help): w
  21. The partition table has been altered.
  22. Syncing disks.
  23. [root@jlin ~]# mkswap /dev/vdb2
  24. [root@jlin ~]# blkid /dev/vdb2
  25. /dev/vdb2: UUID="f626f11c-4363-4caf-aba6-5a418ea04079" TYPE="swap"
  26. PARTUUID="ae75bf0a-02"
  27. [root@jlin ~]# vim /etc/fstab
  28. UUID=f626f11c-4363-4caf-aba6-5a418ea04079 swap swap defaults 0 0
  29. [root@jlin ~]# swapon -a
  30. [root@jlin ~]# swapon -s
  31. Filename Type Size Used Priority
  32. /dev/vdb2 partition 524284 0 -2

3、创建逻辑卷

根据以下要求,创建新的逻辑卷:

  1. 逻辑卷的名字为mylv,属于myvg卷组,大小为50个pe
  2. 卷组myvg中的逻辑卷的pe大小应当为16MiB
  3. 使用vfat文件系统将逻辑卷mylv格式化
  4. 此逻辑卷应当在系统启动时自动挂载到/mnt/mydata目录下
  1. [root@jlin ~]# fdisk /dev/vdb
  2. Welcome to fdisk (util-linux 2.32.1).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Command (m for help): n
  6. Partition type
  7. p primary (2 primary, 0 extended, 2 free)
  8. e extended (container for logical partitions)
  9. Select (default p):
  10. Using default response p.
  11. Partition number (3,4, default 3):
  12. First sector (5244928-10485759, default 5244928):
  13. Last sector, +sectors or +size{K,M,G,T,P} (5244928-10485759, default 10485759):
  14. +1G
  15. Created a new partition 3 of type 'Linux' and of size 1 GiB.
  16. Command (m for help) : t
  17. Partition number ( i-3,default 3):
  18. Hex code (type L to list all codes) : 8e
  19. Changed type of partition 'Linux' to 'Linux LVM' .
  20. Command (m for help): w
  21. The partition table has been altered.
  22. Syncing disks.
  23. [root@jlin ~]# pvcreate /dev/vdb3
  24. [root@jlin ~]# vgcreate -s 16M myvg /dev/vdb3
  25. [root@jlin ~]# lvcreate -l 50 -n mylv myvg
  26. [root@jlin ~]# mkfs.vfat /dev/myvg/mylv
  27. [root@jlin ~]#blkid /dev/ myvg/mylv
  28. /dev/myvg/mylv: UUID="5AA3-4EB3" TYPE="vfat"
  29. [root@jlin ~]# vim /etc/fstab
  30. UUID="5AA3-4EB3" /mnt/mydata vfat defaults 0 0
  31. [root@jlin ~]# mkdir /mnt/mydata
  32. [root@jlin ~]# mount -a
  33. [root@jlin ~]# df -h /mnt/mydata/
  34. Filesystem Size Used Avail Use% Mounted on
  35. /dev/myvg/mylv 799M 4.0K 799M 1% /mnt/mydata

4、创建VDO卷

根据如下要求,创建新的VDO卷:

  1. 使⽤未分区的磁盘(/dev/vdc)
  2. 此VDO卷的名称为myvdo
  3. 此VDO卷的逻辑大小为50G
  4. 此VDO卷使用xfs文件系统格式化
  5. 此VDO卷在系统启动自动挂载到/vblock目录下
  1. [root@jlin ~]# vdo create --name=myvdo --device=/dev/vdc --vdoLogicalSize=50G
  2. // 命令man vdo 找example
  3. Creating VDO myvdo
  4. Starting VDO myvdo
  5. Starting compression on VDO myvdo
  6. VDO instance 0 volume is ready at /dev/mapper/myvdo
  7. [root@jlin ~]# mkfs.xfs /dev/mapper/myvdo
  8. [root@jlin ~]# blkid /dev/ mapper/myvdo
  9. /dev/mapper/myvdo: UUID="0alf2efd-141b-4e7c-98ff-e75ff73515a3" TYPE="xfs"
  10. [root@jlin ~]# vim /etc/fstab
  11. UUID="0alf2efd-141b-4e7c-98ff-e75ff73515a3" /vblock xfs defaults,x-systemd.requires=vdo.service 0 0
  12. [root@jlin ~]# mkdir /vblock
  13. [root@jlin ~]# mount -a
  14. [root@jlin ~]# df -h /vblock
  15. Filesystem Size Used Avail Use% Mounted on
  16. /dev/mapper/myvdo 50G 390M 50G 1% /vblock
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/319407
推荐阅读
相关标签
  

闽ICP备14008679号