[Linux] Exercise---VLM logical volume + swap partition

Experiment 1: Create a logical volume

   Please create a new logical volume according to the following requirements: create a volume group named datastore, the size of the volume group is 4G , the name of the logical volume is database, the volume group to which it belongs is datastore, and the size of the logical volume is 3G .

 1. View disk partition information

[root@localhost ~]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   10G  0 disk           //将要分区的磁盘
sr0            11:0    1  6.6G  0 rom  
nvme0n1       259:0    0   30G  0 disk 
├─nvme0n1p1   259:1    0  500M  0 part /boot
└─nvme0n1p2   259:2    0   19G  0 part 
  ├─rhel-root 253:0    0   15G  0 lvm  /
  └─rhel-swap 253:1    0    4G  0 lvm  [SWAP]

2. Disk partition

[root@localhost ~]# fdisk /dev/sda 

欢迎使用 fdisk (util-linux 2.32.1)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

设备不包含可识别的分区表。
创建了一个磁盘标识符为 0x2b992fe2 的新 DOS 磁盘标签。

命令(输入 m 获取帮助):n                      //创建新的分区
分区类型
   p   主分区 (0个主分区,0个扩展分区,4空闲)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):p                              //选择分区类型
分区号 (1-4, 默认  1): 1
第一个扇区 (2048-20971519, 默认 2048):        
上个扇区,+sectors 或 +size{K,M,G,T,P} (2048-20971519, 默认 20971519): +2G    //大小为2G

创建了一个新分区 1,类型为“Linux”,大小为 2 GiB。

命令(输入 m 获取帮助):n
分区类型
   p   主分区 (1个主分区,0个扩展分区,3空闲)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):p
分区号 (2-4, 默认  2): 
第一个扇区 (4196352-20971519, 默认 4196352): 
上个扇区,+sectors 或 +size{K,M,G,T,P} (4196352-20971519, 默认 20971519): +2G

创建了一个新分区 2,类型为“Linux”,大小为 2 GiB。



命令(输入 m 获取帮助):w         //保存退出
分区表已调整。
将调用 ioctl() 来重新读分区表。
正在同步磁盘。

3. Modify the file system type

[root@localhost ~]# fdisk /dev/sda

欢迎使用 fdisk (util-linux 2.32.1)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):t
分区号 (1-3, 默认  3): 1
Hex 代码(输入 L 列出所有代码):8e

已将分区“Linux”的类型更改为“Linux LVM”。

命令(输入 m 获取帮助):t
分区号 (1-3, 默认  3): 2  
Hex 代码(输入 L 列出所有代码):8e

已将分区“Linux”的类型更改为“Linux LVM”。

命令(输入 m 获取帮助):w
分区表已调整。
正在同步磁盘。

4. Create physical volumes (/etc/sda1 and /etc/sda2)

[root@localhost ~]# pvcreate /dev/sda1 /dev/sda2                 //创建逻辑卷
  Physical volume "/dev/sda1" successfully created.
  Physical volume "/dev/sda2" successfully created.
[root@localhost ~]# pvs                                          //查看物理卷
  PV             VG   Fmt  Attr PSize  PFree
  /dev/nvme0n1p2 rhel lvm2 a--  19.00g 4.00m
  /dev/sda1           lvm2 ---   2.00g 2.00g
  /dev/sda2           lvm2 ---   2.00g 2.00g

5. Create a volume group named datastore

[root@localhost ~]# vgcreate datastore /dev/sda1 /dev/sda2         //创建卷组
  Volume group "datastore" successfully created
[root@localhost ~]# vgs                                            //查看卷组
  VG        #PV #LV #SN Attr   VSize  VFree
  datastore   2   0   0 wz--n-  3.99g 3.99g
  rhel        1   2   0 wz--n- 19.00g 4.00m

6. Create a logical volume named database

[root@localhost ~]# lvcreate -L 3G -n database datastore  //逻辑卷大小为3G,属于datastore卷组
  Logical volume "database" created.
[root@localhost ~]# lvs                     //查看逻辑卷
  LV       VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  database datastore -wi-a-----  3.00g                                                    
  root     rhel      -wi-ao---- 15.00g                                                    
  swap     rhel      -wi-ao----  4.00g          

 7. Modify the file system to ext4

[root@localhost ~]# mkfs.ext4 /dev/datastore/database   //database逻辑卷文件系统类型修改为ext4
mke2fs 1.44.3 (10-July-2018)
创建含有 786432 个块(每块 4k)和 196608 个inode的文件系统
文件系统UUID:c6e58dc5-3d77-4510-a16e-a54a1983d13e
超级块的备份存储于下列块: 
	32768, 98304, 163840, 229376, 294912

正在分配组表: 完成                            
正在写入inode表: 完成                            
创建日志(16384 个块)完成
写入超级块和文件系统账户统计信息: 已完成

8. Create a mount point directory

[root@localhost ~]# mkdir /data

9. Mount

[root@localhost ~]# mount /dev/datastore/database  /data
[root@localhost ~]# df -h
文件系统                        容量  已用  可用 已用% 挂载点
devtmpfs                        889M     0  889M    0% /dev
tmpfs                           904M     0  904M    0% /dev/shm
tmpfs                           904M  8.7M  895M    1% /run
tmpfs                           904M     0  904M    0% /sys/fs/cgroup
/dev/mapper/rhel-root            15G  1.5G   14G   10% /
/dev/nvme0n1p1                  495M  153M  343M   31% /boot
tmpfs                           181M     0  181M    0% /run/user/0

 

 

Experiment 2: Add a swap partition

   Add a new swap partition to your system and meet the following requirements: The swap partition has a capacity of 512 MiB . When your system starts, the swap partition should be automatically mounted on boot . Do not remove or modify other existing ones. Swap partition in the system .

 1. Create a new partition

[root@localhost ~]# fdisk /dev/sda
命令(输入 m 获取帮助):n
分区类型
   p   主分区 (2个主分区,0个扩展分区,2空闲)
   e   扩展分区 (逻辑分区容器)
选择 (默认 p):p
分区号 (3,4, 默认  3): 
第一个扇区 (8390656-20971519, 默认 8390656): 
上个扇区,+sectors 或 +size{K,M,G,T,P} (8390656-20971519, 默认 20971519): +512M

创建了一个新分区 3,类型为“Linux”,大小为 512 MiB。


命令(输入 m 获取帮助):t
分区号 (1-3, 默认  3): 3
Hex 代码(输入 L 列出所有代码):82

已将分区“Linux”的类型更改为“Linux swap / Solaris”。

命令(输入 m 获取帮助):p
Disk /dev/sda:10 GiB,10737418240 字节,20971520 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x2b992fe2

设备       启动    起点    末尾    扇区  大小 Id 类型
/dev/sda1          2048 4196351 4194304    2G 83 Linux
/dev/sda2       4196352 8390655 4194304    2G 83 Linux
/dev/sda3       8390656 9439231 1048576  512M 82 Linux swap / Solaris

命令(输入 m 获取帮助):w
分区表已调整。
正在同步磁盘。

2. Format

[root@localhost ~]# mkswap /dev/sda3
正在设置交换空间版本 1,大小 = 512 MiB (536866816  个字节)
无标签,UUID=1dd09371-9ab9-4979-8368-03cd6d38ab8f

3. Activate the swap partition

[root@localhost ~]# swapon /dev/sda3
[root@localhost ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1806         222        1308           8         275        1420
Swap:          4607           0        4607

4. Automatically mount and write configuration files at boot

[root@localhost ~]# vim /etc/fstab 
# 
# /etc/fstab
# Created by anaconda on Sat Oct  3 14:51:25 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                         xfs     defaults        0 0
UUID=ee99667b-d8d2-4bac-adf1-9e0f76d3cd5f /boot   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                      swap    defaults        0 0
/dev/mapper/datastore-database  /data             xfs     defaults        0 0
UUID=1dd09371-9ab9-4979-8368-03cd6d38ab8f  swap   swap    defaults        0 0    //新写入的

 

Guess you like

Origin blog.csdn.net/trichloromethane/article/details/109315676