Linux磁盘管理实例

Linux磁盘管理实例

1、调整逻辑卷大小

  1. 预先创建2GiB的分区/dev/vdb1,并用于创建卷组testvg
  2. 创建大小为200MiB的逻辑卷/dev/testvg/vo,格式化为xfs文件系统,并挂载在/mnt/vo上
  3. 将逻辑卷/dev/testvg/vo及其文件系统大小调整到300MiB,确保文件系统内容保持不变
// 准备工作
[root@jlin ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xae75bf0a.

Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-10485759, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

[root@jlin ~]# pvcreate /dev/vdb1	#创建物理卷
[root@jlin ~]# vgcreate testvg /dev/vdb1	#创建卷组并将vdb1加入到卷组
[root@jlin ~]# lvcreate -n vo -L 200M testvg	#在卷组中分出逻辑卷
[root@jlin ~]# mkfs.xfs /dev/testvg/vo	#格式化为xfs
[root@jlin ~]# blkid /dev/testvg/vo	#查看uuid
/dev/testvg/vo: UUID="fe323058-93db-428d-883c-2c0210cd10c6" TYPE="xfs"
[root@jlin ~]# mkdir /mnt/vo
[root@jlin ~]# vim /etc/fstab
UUID="fe323058-93db-428d-883c-2c0210cd10c6" /mnt/vo xfs defaults 0 0
[root@jlin ~]# mount -a

// 扩展操作
[root@jlin ~]# df -hT /dev/testvg/vo # 查看文件系统的类型和大小
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/testvg-vo xfs 195M 12M 183M 6% /mnt/vo
[root@jlin ~]# lvextend -L 300M /dev/testvg/vo
[root@jlin ~]# lvs
// 扩展文件系统,ext类型的文件系统用resize2fs /dev/testvg/vo ,后面接的是逻辑卷的路径。
[root@jlin ~]# xfs_growfs /mnt/vo # 后面接的是挂载点的路径
[root@jlin ~]# df -hT /dev/testvg/vo
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/testvg-vo xfs 295M 13M 283M 5% /mnt/vo

2、添加交换分区

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

[root@jlin ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.32.1).
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 (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (4196352-10485759, default 4196352):
Last sector, +sectors or +size{K,M,G,T,P} (4196352-10485759, default 10485759):
+512M
Created a new partition 2 of type 'Linux' and of size 512 MiB.

Command (m for help) : t
Partition number ( 1,2,default 2):
Hex code (type L to list all codes) : 82
Changed type of partition 'Linux' to 'Linux swap / Solaris '.

Command (m for help): w
The partition table has been altered.
Syncing disks.

[root@jlin ~]# mkswap /dev/vdb2
[root@jlin ~]# blkid /dev/vdb2
/dev/vdb2: UUID="f626f11c-4363-4caf-aba6-5a418ea04079" TYPE="swap"
PARTUUID="ae75bf0a-02"
[root@jlin ~]# vim /etc/fstab
UUID=f626f11c-4363-4caf-aba6-5a418ea04079 swap swap defaults 0 0
[root@jlin ~]# swapon -a
[root@jlin ~]# swapon -s
Filename Type Size Used Priority
/dev/vdb2 partition 524284 0 -2

3、创建逻辑卷

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

  1. 逻辑卷的名字为mylv,属于myvg卷组,大小为50个pe
  2. 卷组myvg中的逻辑卷的pe大小应当为16MiB
  3. 使用vfat文件系统将逻辑卷mylv格式化
  4. 此逻辑卷应当在系统启动时自动挂载到/mnt/mydata目录下
[root@jlin ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.32.1).
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 (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (3,4, default 3):
First sector (5244928-10485759, default 5244928):
Last sector, +sectors or +size{K,M,G,T,P} (5244928-10485759, default 10485759):
+1G
Created a new partition 3 of type 'Linux' and of size 1 GiB.

Command (m for help) : t
Partition number ( i-3,default 3):
Hex code (type L to list all codes) : 8e
Changed type of partition 'Linux' to 'Linux LVM' .

Command (m for help): w
The partition table has been altered.
Syncing disks.

[root@jlin ~]# pvcreate /dev/vdb3
[root@jlin ~]# vgcreate -s 16M myvg /dev/vdb3
[root@jlin ~]# lvcreate -l 50 -n mylv myvg
[root@jlin ~]# mkfs.vfat /dev/myvg/mylv
[root@jlin ~]#blkid /dev/ myvg/mylv
/dev/myvg/mylv: UUID="5AA3-4EB3" TYPE="vfat"
[root@jlin ~]# vim /etc/fstab
UUID="5AA3-4EB3" /mnt/mydata vfat defaults 0 0
[root@jlin ~]# mkdir /mnt/mydata
[root@jlin ~]# mount -a
[root@jlin ~]# df -h /mnt/mydata/
Filesystem Size Used Avail Use% Mounted on
/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目录下
[root@jlin ~]# vdo create --name=myvdo --device=/dev/vdc --vdoLogicalSize=50G
// 命令man vdo 找example
Creating VDO myvdo
Starting VDO myvdo
Starting compression on VDO myvdo
VDO instance 0 volume is ready at /dev/mapper/myvdo
[root@jlin ~]# mkfs.xfs /dev/mapper/myvdo
[root@jlin ~]# blkid /dev/ mapper/myvdo
/dev/mapper/myvdo: UUID="0alf2efd-141b-4e7c-98ff-e75ff73515a3" TYPE="xfs"
[root@jlin ~]# vim /etc/fstab
UUID="0alf2efd-141b-4e7c-98ff-e75ff73515a3" /vblock xfs defaults,x-systemd.requires=vdo.service 0 0
[root@jlin ~]# mkdir /vblock
[root@jlin ~]# mount -a
[root@jlin ~]# df -h /vblock
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/myvdo 50G 390M 50G 1% /vblock
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汉只只

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值