1、创建一个 2G 的文件系统,块大小为 2048byte,预留 1% 可用空间,文件系统 ext4,卷标为 TEST,要求此分区开机后自动挂载至 /test 目录,且默认有 acl 挂载选项;
# 1、先准备有空余空间的硬盘,此处为 /dev/sdb ,可用空间20G# 2、用fdisk创建分区
[root@centos7 data]# fdisk -l /dev/sdbDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes[root@centos7 data]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).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
Building a new DOS disklabel with disk identifier 0x6f11fc49.Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6f11fc49Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     4196351     2097152   83  LinuxCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.# 3、格式化分区,指定块大小、预留空间、卷标
[root@centos7 data]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 1048576 blocks
10485 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=269484032
64 block groups
16384 blocks per group, 16384 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done # 4、将挂载信息添加到 /etc/fstab ,挂载为acl
[root@centos7 data]# echo UUID=`blkid | sed -nr 's/^\/dev\/sdb1.*"(.*)" T.*$/\1/p'` /test ext4 acl 0 0 >> /etc/fstab# 5、创建挂载目录,立即生效挂载信息,查看挂载信息
[root@centos7 data]# mkdir /test
[root@centos7 data]# mount -a remount
[root@centos7 data]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
devtmpfs                         894M     0  894M   0% /dev
tmpfs                            910M     0  910M   0% /dev/shm
tmpfs                            910M   11M  900M   2% /run
tmpfs                            910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos_centos7-root   50G  5.4G   45G  11% /
/dev/mapper/centos_centos7-home   47G   39M   47G   1% /home
/dev/sda1                       1014M  193M  822M  20% /boot
tmpfs                            182M   12K  182M   1% /run/user/42
tmpfs                            182M     0  182M   0% /run/user/1003
tmpfs                            182M     0  182M   0% /run/user/0
/dev/sdb1                        2.0G  9.1M  1.9G   1% /test
2、写一个脚本,完成如下功能:

(1) 列出当前系统识别到的所有磁盘设备

(2) 如磁盘数量为1,则显示其空间使用信息

否则,则显示最后一个磁盘上的空间使用信息

#!/bin/bash
echo "系统中的所有磁盘设备:"
lsblk | grep -o '^sd[[:alpha:]]'
LASTDISK=`lsblk | grep -o '^sd[[:alpha:]]' | tail -1`
echo "最后一块磁盘的空间使用信息:"
lsblk /dev/$LASTDISK
3、将 CentOS6 的 CentOS-6.10-x86_64-bin-DVD1.iso 和 CentOS-6.10-x86_64-bin-DVD2.iso 两个文件,合并成一个 CentOS-6.10-x86_64-Everything.iso 文件,并将其配置为 yum 源。
# 1、在虚拟机添加两个光驱,插入两张光盘,对应的设备为 /dev/sr0 /dev/sr1# 2、创建挂载目录
[root@localhost ~]# mkdir /mnt/cd{1,2}# 3、将挂载到对应的目录
[root@localhost ~]# mount /dev/sr0 /mnt/cd1
[root@localhost ~]# mount /dev/sr1 /mnt/cd2# 4、合并文件
## 创建合并文件夹
[root@localhost ~]# mkdir CentOS-6.10-x86_64-Everything
## 复制 cd1 文件
[root@localhost ~]# cp -a /mnt/cd1/* ./CentOS-6.10-x86_64-Everything/
## 复制 cd2 文件
[root@localhost ~]# cp -a /mnt/cd2/Packages/* ./CentOS-6.10-x86_64-Everything/Packages/## 创建 iso 文件
[root@localhost ~]# mkisofs -r -o CentOS-6.10-x86_64-Everything.iso ./CentOS-6.10-x86_64-Everything/## 挂载
[root@localhost ~]# mount -o loop CentOS-6.10-x86_64-Everything.iso /mnt/centos6/# 5、配置 yum 源
## 创建 local.repo 文件
[root@localhost ~]# vim /etc/yum.repos.d/centos6.repo
### 填入以下内容
[local]
name=local base
baseurl=file:///mnt/centos6/
gpgcheck=0
4、创建一个可用空间为 1G 的 RAID1 设备,文件系统为 ext4,有一个空闲盘,开机可自动挂载至 /backup 目录
# 1、添加三块硬盘 /dev/sdb,/dev/sdc,/dev/sdd,在两块硬盘上分别创建一个1G的分区
## /dev/sdb
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).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
Building a new DOS disklabel with disk identifier 0x867d76df.Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G
Partition 1 of type Linux and of size 1 GiB is setCommand (m for help): pDisk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x867d76dfDevice Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  LinuxCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.## /dev/sdc
[root@localhost ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).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
Building a new DOS disklabel with disk identifier 0x2f2a90c9.Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G
Partition 1 of type Linux and of size 1 GiB is setCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.# /dev/sdd
[root@localhost ~]# fdisk /dev/sdd
Welcome to fdisk (util-linux 2.23.2).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
Building a new DOS disklabel with disk identifier 0x29e81709.Command (m for help): n
Partition type:p   primary (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G
Partition 1 of type Linux and of size 1 GiB is setCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.# 2、创建 RAID
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 /dev/sd{b,c}1 -x 1 /dev/sdd1# 3、格式化分区
[root@localhost ~]# mkfs.ext4 /dev/md0# 添加挂载
[root@localhost ~]# mkdir /backup
[root@localhost ~]# echo /dev/md0 /backup ext4 defaults 0 0  >> /etc/fstab
[root@localhost ~]# mount -a remount
5、创建由三块硬盘组成的可用空间为 2G 的 RAID5 设备,要求其 chunk 大小为 256k,文件系统为 ext4,开机可自动挂载至 /mydata 目录
# 创建3个分区 /dev/sdb2,/dev/sec2,/dev/sdd2,步骤略# 创建 RAID
[root@localhost ~]# mdadm -C /dev/md1 -a yes -l 5 -n 3 -c 256 /dev/sd{b,c,d}2
[root@localhost ~]# mkfs.ext4 /dev/md1
[root@localhost ~]# echo /dev/md1 /mydata ext4 defaults 0 0 >> /etc/fstab
[root@localhost ~]# mount -a remount
6、创建一个至少有两个 PV 组成的大小为 20G 的名为 testvg 的 VG;要求 PE 大小为 16MB, 而后在卷组中创建大小为 5G 的逻辑卷testlv;挂载至 /users 目录
# 1、准备硬盘,此处准备两块 /dev/sdb,/dev/sdc# 2、在 /dev/sdb 创建一个10G的分区,分区ID改为8e
[root@centos7 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).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 (0 primary, 0 extended, 4 free)e   extended
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
Partition 1 of type Linux and of size 10 GiB is setCommand (m for help): t
Selected partition 1
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!Calling ioctl() to re-read partition table.
Syncing disks.# 3、在 /dev/sdc 创建一个10G的分区,分区ID改为8e,操作方法同上
[root@centos7 ~]# fdisk /dev/sdc# 4、查看分区
[root@centos7 ~]# lsblk
NAME                    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                       8:0    0  100G  0 disk
├─sda1                    8:1    0    1G  0 part /boot
└─sda2                    8:2    0   99G  0 part ├─centos_centos7-root 253:0    0   50G  0 lvm  /├─centos_centos7-swap 253:1    0    2G  0 lvm  [SWAP]└─centos_centos7-home 253:2    0   47G  0 lvm  /home
sdb                       8:16   0   20G  0 disk
└─sdb1                    8:17   0   10G  0 part
sdc                       8:32   0   20G  0 disk
└─sdc1                    8:33   0   10G  0 part
sr0                      11:0    1  4.4G  0 rom  # 5、创建 pv
[root@centos7 ~]# pvcreate /dev/sdb1 /dev/sdc1Physical volume "/dev/sdb1" successfully created.Physical volume "/dev/sdc1" successfully created.## 查看 pv 信息
[root@centos7 ~]# pvsPV         VG             Fmt  Attr PSize   PFree/dev/sda2  centos_centos7 lvm2 a--  <99.00g 4.00m/dev/sdb1  testvg         lvm2 a--    9.98g 9.98g/dev/sdc1  testvg         lvm2 a--    9.98g 9.98g# 6、创建 vg
[root@centos7 ~]# vgcreate -s 16M testvg /dev/sdb1 /dev/sdc1Volume group "testvg" successfully created## 查看 vg 信息
[root@centos7 ~]# vgsVG             #PV #LV #SN Attr   VSize   VFree  centos_centos7   1   3   0 wz--n- <99.00g   4.00mtestvg           2   1   0 wz--n- <19.97g <19.97g# 7、创建 lv
[root@centos7 ~]# lvcreate -L 5G -n testlv testvgLogical volume "testlv" created.## 查看 lv 信息
[root@centos7 ~]# lvs
LV     VG             Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
home   centos_centos7 -wi-ao---- 46.99g
root   centos_centos7 -wi-ao---- 50.00g
swap   centos_centos7 -wi-ao----  2.00g
testlv testvg         -wi-a-----  5.00g # 8、格式化分区
[root@centos7 ~]# mkfs.ext4 /dev/testvg/testlv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done # 9、查看分区信息
[root@centos7 ~]# blkid
/dev/mapper/centos_centos7-root: UUID="458d1621-f955-41da-9c61-4cda5b7543b0" TYPE="xfs"
/dev/sda2: UUID="uv2ZRK-hGZh-0Nfa-3yAz-QXqy-ONu1-AbCOIj" TYPE="LVM2_member"
/dev/sda1: UUID="f7cd1056-9888-4bfd-ae48-0eccace210e3" TYPE="xfs"
/dev/sdb1: UUID="ZQiO6V-WdlI-aDYd-FSDP-0kjX-y5tm-2DdY6a" TYPE="LVM2_member"
/dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos_centos7-swap: UUID="a0f7086a-edeb-446b-8c21-377f124045ea" TYPE="swap"
/dev/mapper/centos_centos7-home: UUID="67154c0f-af61-46be-87ae-f0ef0620190a" TYPE="xfs"
/dev/sdc1: UUID="rzKRqQ-qNhx-PCoD-hc7Z-XFD5-xx3b-2OvKDQ" TYPE="LVM2_member"
/dev/mapper/testvg-testlv: UUID="d4c744a0-96b7-4eae-9572-df84a3547379" TYPE="ext4"# 10、将挂载信息写入到 /etc/fstab
echo /dev/testvg/testlv /users ext4 defaults 0 0 >> /etc/fstab# 11、创建挂载目录,立即生效挂载信息,查看挂载信息
[root@centos7 ~]# mkdir /users
[root@centos7 ~]# mount -a remount
[root@centos7 ~]# df -h
Filesystem                       Size  Used Avail Use% Mounted on
devtmpfs                         894M     0  894M   0% /dev
tmpfs                            910M     0  910M   0% /dev/shm
tmpfs                            910M   11M  900M   2% /run
tmpfs                            910M     0  910M   0% /sys/fs/cgroup
/dev/mapper/centos_centos7-root   50G  5.4G   45G  11% /
/dev/sda1                       1014M  193M  822M  20% /boot
/dev/mapper/centos_centos7-home   47G   39M   47G   1% /home
tmpfs                            182M   12K  182M   1% /run/user/42
tmpfs                            182M     0  182M   0% /run/user/1003
tmpfs                            182M     0  182M   0% /run/user/0
/dev/mapper/testvg-testlv        4.8G   20M  4.6G   1% /users
7、新建用户 archlinux,要求其家目录为 /users/archlinux,而后 su 切换至 archlinux 用户,复制 /etc/pam.d 目录至自己的家目录
[root@localhost ~]# useradd -d /users/archlinux archlinux
[root@localhost ~]# su - archlinux
[archlinux@localhost ~]$ cp -r /etc/pam.d/ .
[archlinux@localhost ~]$ ll
total 4
drwxr-xr-x. 2 archlinux archlinux 4096 May 30 17:18 pam.d
8、扩展 testlv 至 7G,要求 archlinux 用户的文件不能丢失
[root@localhost ~]# lvextend -r -L +2G /dev/testvg/testlv
[root@localhost ~]# ll /users/archlinux/
total 4
drwxr-xr-x. 2 archlinux archlinux 4096 May 30 17:18 pam.d
9、收缩 testlv 至 3G,要求 archlinux 用户的文件不能丢失
# 临时取消挂载,如果 umount 失败,可重启一下
[root@localhost ~]# umount /users
[root@localhost ~]# lvresize -r -L -4G /dev/testvg/testlv
[root@localhost ~]# mount -a
[archlinux@localhost ~]$ ll /users/archlinux/
total 4
drwxr-xr-x. 2 archlinux archlinux 4096 May 30 21:21 pam.d
10、对 testlv 创建快照,并尝试基于快照备份数据,验证快照的功能
# 创建快照
[root@localhost ~]# lvcreate -n testlv_snapshot -s -L 1G -p r /dev/testvg/testlv# 挂载快照
[root@localhost ~]# mkdir /mnt/snapshot
[root@localhost ~]# mount -o ro /dev/testvg/testlv_snapshot /mnt/snapshot/
[root@localhost ~]# ll /mnt/snapshot/
total 20
drwx------. 6 archlinux archlinux  4096 May 30 21:23 archlinux
drwx------. 2 root      root      16384 May 30 21:15 lost+found# 恢复快照(如果 umount 失败,可重启一下)
[root@localhost ~]# umount /mnt/snapshot
[root@localhost ~]# umount /users
[root@localhost ~]# lvconvert --merge /dev/testvg/testlv_snapshot2

Linux 练习 - 磁盘存储和文件系统相关推荐

  1. Linux篇 | 磁盘存储和文件系统

    磁盘存储和文件系统 分区 文件系统 挂载设备 管理虚拟内存 RAID管理 LVM管理 我们从一个新硬盘安装到Linux系统,期间的配置,一直到正常使用的角度,来学习磁盘存储和文件系统,过程如下: 选择 ...

  2. Linux磁盘存储和文件系统

    磁盘存储和文件系统 设备文件 I/O Ports: I/O设备地址 一切皆文件:open(), read(), write(), close() 设备类型:块设备:block,存取单位"块& ...

  3. linux下几种文件系统的测试比较

    在linux下对部分文件系统进行测试 一. 我的实验平台 我使用的是vmware workstation7.1.4.16648 虚拟机 安装的操作系统信息 [root@node2 ~]# uname ...

  4. Linux中光盘使用的文件类型,linux下mount命令使用详解---linux挂载光盘等文件系统...

    mount 命令详解 功能:加载指定的文件系统. 语法:mount [-afFhnrvVw] [-L标签] [-o选项] [-t文件系统类型] [设备名] [加载点] 用法说明:mount可将指定设备 ...

  5. FreeBSD和Linux如何互相访问文件系统

    一.如何mount Linux Ext2文件系统 经常有人在问,强大的FreeBSD为什么不能使用牛B的Linux ext文件系统呢?得到的回答通常是:"能,当然能了".可是,太多 ...

  6. linux管理磁盘和文件系统

    linux管理磁盘和文件系统 >管理磁盘及分区     在linux的服务器中,当现有硬盘的分区规划不能满足要求时,就需要对硬盘中的分区进行重新规划和调整,有时候还需要添加新的硬盘设备来扩展存储 ...

  7. 分析Linux磁盘管理与文件系统专题三

    1.前言 紧接着我的上一篇博客进行磁盘管理操作: http://zhangfengzhe.blog.51cto.com/8855103/1430531 我们已经对磁盘进行了分区,信息如下: [root ...

  8. 【AWSL】之Linux磁盘管理与文件系统(fdisk、df、mount、umount、lsblk)

    序言 这里我主要介绍以下Linux的磁盘管理与文件系统的一些操作与概述 磁盘和文件 序言 一.磁盘分区结构 二.文件系统类型 三. 检测并确认新硬盘 1.fdisk命令 2.fdisk -l 3.规划 ...

  9. Linux磁盘管理与文件系统(实验详解,一看就懂)

    磁盘管理与文件系统 一.磁盘管理 1.1 磁盘结构 1.2 MBR与磁盘分区表示 1.2.1 MBR 1.2.2 磁盘分区表示 二.文件系统 2.1 文件系统类型 2.2 检测并确认新硬盘 2.3 管 ...

最新文章

  1. 资源 | 想用Python学机器学习?Google大神替你写好了所有的编程示范代码
  2. 想了解Sleuth+zipkin分布式请求链路追踪,来看看这篇文章吧!
  3. linux系统下的“静态库和动态库”专题之二:库的创建和使用
  4. Eclipse自动生成方法注释 快捷键
  5. Bailian2744 子串【字符串】
  6. 非常易于理解‘类'与'对象’ 间 属性 引用关系,暨《Python 中的引用和类属性的初步理解》读后感...
  7. Centos7.0下MySQL的安装
  8. linux设备驱动程序之时钟管理
  9. tsql 正则_sql 正则表达式匹配
  10. 【如何在12306网站上购买上中下卧铺火车票呢?】
  11. 【Python抢票神器】火车票枪票软件到底靠谱吗?实测—终极攻略。
  12. 怎样压缩ppt的大小?
  13. 社团联合会计算机教程,计算机与信息工程学院学生社团联合会
  14. 计算机芯片级维修包括哪些,计算机芯片级维修1
  15. Vue快速实现通用表单验证
  16. esp32 采集某个路由器信号强度
  17. python提取pdf内容_别再问如何用Python提取PDF内容了!
  18. MFC真的过时了吗?C++是否真的适合做GUI界面?
  19. sql怎么与oracle连接,sql怎么连接oracle数据库
  20. ZigBee组网机制以及数据的发送和接收

热门文章

  1. 列表, 元组, range() 知识总结
  2. Java处理除数为零的情况
  3. 智能小区java_java毕业设计_springboot框架的模式下的智能小区规划系统
  4. 速卖通关键词挖掘工具_速卖通长尾词采集新增断续功能免费体验7天
  5. 关于 海思Hi3516横竖屏Qt使用QGraphicsScene代理窗口强制旋转导致弹窗旋转与阴影不显示的 解决方案
  6. vue.js前端开发技术读书笔记二:vue数据绑定
  7. 微信小程序——选择图片/拍照
  8. 算法题:一个圆环上有100个灯泡,灯泡有打开和关闭两种状态,灯泡的状态随机,按一个灯泡的开关,相邻的两个灯泡的状态也发生一次变化。比如暗-亮-暗,按中间灯泡,变化为亮-暗-亮。问设计一道算法,使得所有
  9. 华硕X43S关闭触控板
  10. 浅谈对信息管理的认识