Debian配置动态LVM卷1-lnxserver2

赛题

2.2.3、配置动态LVM卷,允许动态调整磁盘空间大小;

l lnxserver2上安装lvm2组件,并配置如下信息:

l 在已经安装好的虚拟机上,增加一块新的硬盘,空间大小为10GB;挂载到系统上;定义为:sdb;

l 创建两个逻辑卷,大小都为4GB,/dev/sdb1,/dev/sdb2;Hex code:2d;加入到一个卷组中;默认PE SIZE:4M;分割5GB空间到逻辑卷lvdata01;剩余空间用于后期不够用后调整;

l 磁盘格式化为ext4分区;挂载到系统的lvdata下,设置成开启自动挂载;

l 在lvdata文件下生成二个大小为2.5GB和2GB大小的文件;文件名“01”,“02”;文件在文件系统中的显示大小为对应大小,但是并不实际占用block;

1.安装服务,添加磁盘

在这里插入图片描述

开机状态下添加硬盘,需要重启下虚拟机

root@lnxserver2:~# apt install -y lvm2
root@lnxserver2:~# reboot
root@lnxserver2:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk 
├─sda1   8:1    0   19G  0 part /
├─sda2   8:2    0    1K  0 part 
└─sda5   8:5    0  975M  0 part [SWAP]
sdb      8:16   0   10G  0 disk 
sr0     11:0    1 45.1G  0 rom  
root@lnxserver2:~# 

2.创建2个逻辑卷

root@lnxserver2:~# fdisk /dev/sdb
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-20971519, default 2048): 
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): +4G

    Created a new partition 1 of type 'Linux' and of size 4 GiB.

    Command (m for help): n
    Partition type
       p   primary (1 primary, 0 extended, 3 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (2-4, default 2): 2
    First sector (8390656-20971519, default 8390656): 
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (8390656-20971519, default 20971519): +4G

    Created a new partition 2 of type 'Linux' and of size 4 GiB.

    Command (m for help): p
    Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
    Disk model: VMware Virtual S
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0xec6b45eb

    Device     Boot   Start      End Sectors Size Id Type
    /dev/sdb1          2048  8390655 8388608   4G 83 Linux
    /dev/sdb2       8390656 16779263 8388608   4G 83 Linux
    Command (m for help): w

3.创建LVM卷

root@lnxserver2:~# vgcreate vg /dev/sdb[1,2]
  Physical volume "/dev/sdb1" successfully created.
  Physical volume "/dev/sdb2" successfully created.
  Volume group "vg" successfully created
root@lnxserver2:~# lvcreate -L +5G -n lv vg
  Logical volume "lv" created.

4.格式化,开机自动挂载

格式化

root@lnxserver2:~# mkfs.ext4 /dev/vg/lv
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: 4b10c074-d349-4953-8800-e782e66ddfcd
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

root@lnxserver2:~# 

创建文件夹挂载

root@lnxserver2:~# mkdir /lvdata
root@lnxserver2:~# mount /dev/vg/lv /lvdata/
root@lnxserver2:~# df -Th
/dev/mapper/vg-lv ext4      4.9G   20M  4.6G   1% /lvdata

开机自动挂载

root@lnxserver2:~# vim /etc/fstab 
/dev/vg/lv      /lvdata ext4    defaults        0       0

5.生成2个GB大小文件

只能用方法1,2和3会占用磁盘空间

方法1

root@lnxserver2:/lvdata# truncate -s 2560M 01
root@lnxserver2:/lvdata# truncate -s 2048M 02
root@lnxserver2:/lvdata# ls -lh
total 16K
-rw-r--r-- 1 root root 2.5G Feb 16 20:55 01
-rw-r--r-- 1 root root 2.0G Feb 16 20:55 02
drwx------ 2 root root  16K Feb 16 20:27 lost+found
root@lnxserver2:/lvdata# df -Th
Filesystem        Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg-lv ext4      4.9G   20M  4.6G   1% /lvdata
root@lnxserver2:/lvdata# 

方法2

root@lnxserver2:~# cd /lvdata/
root@lnxserver2:/lvdata# dd if=/dev/zero of=01 bs=1M count=2560
2560+0 records in
2560+0 records out
2684354560 bytes (2.7 GB, 2.5 GiB) copied, 2.81672 s, 953 MB/s
root@lnxserver2:/lvdata# dd if=/dev/zero of=02 bs=1M count=2048 
2048+0 records in
2048+0 records out
2147483648 bytes (2.1 GB, 2.0 GiB) copied, 2.1628 s, 993 MB/s
root@lnxserver2:/lvdata# ls -l
total 4718616
-rw-r--r-- 1 root root 2684354560 Feb 16 20:46 01
-rw-r--r-- 1 root root 2147483648 Feb 16 20:46 02
drwx------ 2 root root      16384 Feb 16 20:27 lost+found
root@lnxserver2:/lvdata# df -Th
Filesystem        Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg-lv ext4      4.9G  4.6G   76M  99% /lvdata

方法3

root@lnxserver2:/lvdata# fallocate -l 2.5G 01
root@lnxserver2:/lvdata# fallocate -l 2G 02 
root@lnxserver2:/lvdata# ls -lh
total 4.5G
-rw-r--r-- 1 root root 2.5G Feb 16 20:49 01
-rw-r--r-- 1 root root 2.0G Feb 16 20:49 02
drwx------ 2 root root  16K Feb 16 20:27 lost+found
root@lnxserver2:/lvdata# df -Th
Filesystem        Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg-lv ext4      4.9G  4.6G   76M  99% /lvdata
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

新时代先锋

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

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

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

打赏作者

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

抵扣说明:

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

余额充值