s49 磁盘存储文件系统管理详解
第一部分
1、创建一个2G的文件系统
块大小为2048byte,预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
#新添加一块10G磁盘[root@centos8 ~]# scandisk[root@centos8 ~]# alias scandiskalias scandisk='echo '\''- - -'\'' > /sys/class/scsi_host/host0/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host1/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host2/scan'[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 1G 0 part /mnt/sdb1├─sdb2 8:18 0 2G 0 part ├─sdb3 8:19 0 1K 0 part └─sdb5 8:21 0 3G 0 part sdc 8:32 0 10G 0 disk ├─sdc1 8:33 0 1G 0 part └─sdc2 8:34 0 2G 0 part sdd 8:48 0 10G 0 disk #这个是新添加的磁盘sr0 11:0 1 7.7G 0 rom nvme0n1 259:0 0 5G 0 disk [root@centos8 ~]# fdisk /dev/sddWelcome 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 0x0712eaa0.Command (m for help): nPartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1): First sector (2048-20971519, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +2GCreated a new partition 1 of type 'Linux' and of size 2 GiB.Command (m for help): pDisk /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x0712eaa0Device Boot Start End Sectors Size Id Type/dev/sdd1 2048 4196351 4194304 2G 83 LinuxCommand (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 1G 0 part /mnt/sdb1├─sdb2 8:18 0 2G 0 part ├─sdb3 8:19 0 1K 0 part └─sdb5 8:21 0 3G 0 part sdc 8:32 0 10G 0 disk ├─sdc1 8:33 0 1G 0 part └─sdc2 8:34 0 2G 0 part sdd 8:48 0 10G 0 disk └─sdd1 8:49 0 2G 0 part #新建的分区sr0 11:0 1 7.7G 0 rom nvme0n1 259:0 0 5G 0 disk [root@centos8 ~]# mkfs.ext4 -b 2048 -m 1 -L TEST /dev/sdd1#-b 2048 块大小为2048byte -m 1 预留1% -L TEST 卷标名为TESTmke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 1048576 2k blocks and 131072 inodesFilesystem UUID: 0f8a2804-a927-4cde-9d3c-8066d7148386Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# tune2fs -l /dev/sdd1tune2fs 1.45.4 (23-Sep-2019)Filesystem volume name: TEST#卷标名为TEST。Last mounted on: <not available>Filesystem UUID: 0f8a2804-a927-4cde-9d3c-8066d7148386Filesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumFilesystem flags: signed_directory_hash Default mount options: user_xattr acl#centos8 ext4文件系统,默认就有acl功能,不需要单独设置Filesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 131072Block count: 1048576Reserved block count: 10485#预留块大小Free blocks: 1011035Free inodes: 131061First block: 0Block size: 2048#块大小为2048。Fragment size: 2048Group descriptor size: 64Reserved GDT blocks: 512Blocks per group: 16384Fragments per group: 16384Inodes per group: 2048Inode blocks per group: 256Flex block group size: 16Filesystem created: Thu Dec 3 22:58:44 2020Last mount time: n/aLast write time: Thu Dec 3 22:58:44 2020Mount count: 0Maximum mount count: -1Last checked: Thu Dec 3 22:58:44 2020Check interval: 0 (<none>)Lifetime writes: 1058 kBReserved blocks uid: 0 (user root)#预留给谁使用,root。Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 32Desired extra isize: 32Journal inode: 8Default directory hash: half_md4Directory Hash Seed: c99589a0-f6eb-4dd6-a178-b4113c273353Journal backup: inode blocksChecksum type: crc32cChecksum: 0xc13d6cca[root@centos8 ~]# mkdir /test#创建挂载目录[root@centos8 ~]# blkid /dev/sdd1#查看UUID和文件系统类型/dev/sdd1: LABEL="TEST" UUID="0f8a2804-a927-4cde-9d3c-8066d7148386" TYPE="ext4" PARTUUID="0712eaa0-01"[root@centos8 ~]# vim /etc/fstab#添加下面行UUID=0f8a2804-a927-4cde-9d3c-8066d7148386 /test ext4 defaults 0 0 :wq[root@centos8 ~]# mount -a#自动挂载[root@centos8 ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)devtmpfs on /dev type devtmpfs (rw,nosuid,size=905164k,nr_inodes=226291,mode=755)securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)configfs on /sys/kernel/config type configfs (rw,relatime)/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,noquota)systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=34,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=23440)hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)debugfs on /sys/kernel/debug type debugfs (rw,relatime)mqueue on /dev/mqueue type mqueue (rw,relatime)/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,noquota)/dev/sda1 on /boot type ext4 (rw,relatime)tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=184384k,mode=700)/dev/sdb1 on /mnt/sdb1 type ext4 (rw,noatime,nodiratime)/dev/sdd1 on /test type ext4 (rw,relatime)#已经挂载[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part sdb 8:16 0 20G 0 disk ├─sdb1 8:17 0 1G 0 part /mnt/sdb1├─sdb2 8:18 0 2G 0 part ├─sdb3 8:19 0 1K 0 part └─sdb5 8:21 0 3G 0 part sdc 8:32 0 10G 0 disk ├─sdc1 8:33 0 1G 0 part └─sdc2 8:34 0 2G 0 part sdd 8:48 0 10G 0 disk └─sdd1 8:49 0 2G 0 part /test#已经挂载sr0 11:0 1 7.7G 0 rom nvme0n1 259:0 0 5G 0 disk [root@centos8 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 905164 0 905164 0% /devtmpfs 921932 0 921932 0% /dev/shmtmpfs 921932 8940 912992 1% /runtmpfs 921932 0 921932 0% /sys/fs/cgroup/dev/sda2 104806400 2152664 102653736 3% //dev/sda3 52403200 398448 52004752 1% /data/dev/sda1 999320 137644 792864 15% /boottmpfs 184384 0 184384 0% /run/user/0/dev/sdb1 1031836 2821 972491 1% /mnt/sdb1/dev/sdd1 2031306 9236 1992908 1% /test#已经挂载
2、写一个脚本,完成如下功能
(1)列出当前系统识别到的所有磁盘设备
(2)如磁盘数量为1,则显示其空间使用信息
否则,则显示最后一个磁盘上的空间使用信息
[root@centos8 ~]# vim disk_used.sh #!/bin/bash##**********************************************************************************************#Author: Raymond#QQ: 88563128#Date: 2020-12-04#FileName: disk_used.sh#URL: raymond.blog.csdn.net#Description: The test script#Copyright (C): 2021 All rights reserved#*********************************************************************************************disk=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p'`disk_num=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p'| wc -l`disk_end=`lsblk | sed -nr 's/(^sd[[:lower:]]).*/\1/p' | sed -n '$p'`if [ $disk_num -eq 1 ];thendf | grep "/dev/$disk"elsedf | grep "/dev/$disk_end"fi:wq[root@centos8 ~]# bash disk_used.sh /dev/sda2 104806400 4868684 99937716 5% //dev/sda3 52403200 398400 52004800 1% /data/dev/sda1 999320 192580 737928 21% /boot#添加两块硬盘[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 5G 0 disk sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# fdisk /dev/sdbWelcome 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 0x2e83806e.Command (m for help): nPartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): pPartition 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): +2GCreated a new partition 1 of type 'Linux' and of size 2 GiB.Command (m for help): pDisk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x2e83806eDevice Boot Start End Sectors Size Id Type/dev/sdb1 2048 4196351 4194304 2G 83 LinuxCommand (m for help): nPartition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions)Select (default p): pPartition 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): Created a new partition 2 of type 'Linux' and of size 3 GiB.Command (m for help): pDisk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x2e83806eDevice Boot Start End Sectors Size Id Type/dev/sdb1 2048 4196351 4194304 2G 83 Linux/dev/sdb2 4196352 10485759 6289408 3G 83 LinuxCommand (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 5G 0 disk ├─sdb1 8:17 0 2G 0 part └─sdb2 8:18 0 3G 0 part sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# mkfs.ext4 /dev/sdb1mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 524288 4k blocks and 131072 inodesFilesystem UUID: c520fbef-2726-4ab2-b54f-b654bd6c6a1fSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# mkfs.ext4 /dev/sdb2mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 786176 4k blocks and 196608 inodesFilesystem UUID: b5efe116-aec1-41e7-80a2-3791b3ee5669Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# mkdir /mnt/sdb{1,2}[root@centos8 ~]# mount /dev/sdb1 /mnt/sdb1[root@centos8 ~]# mount /dev/sdb2 /mnt/sdb2[root@centos8 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 893740 0 893740 0% /devtmpfs 921916 0 921916 0% /dev/shmtmpfs 921916 9528 912388 2% /runtmpfs 921916 0 921916 0% /sys/fs/cgroup/dev/sda2 104806400 4868932 99937468 5% //dev/sda3 52403200 398400 52004800 1% /data/dev/sda1 999320 192580 737928 21% /boottmpfs 184380 1168 183212 1% /run/user/42tmpfs 184380 4 184376 1% /run/user/0/dev/sdb1 1998672 6144 1871288 1% /mnt/sdb1/dev/sdb2 3029776 9216 2846944 1% /mnt/sdb2[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 5G 0 disk ├─sdb1 8:17 0 2G 0 part /mnt/sdb1└─sdb2 8:18 0 3G 0 part /mnt/sdb2sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# fdisk /dev/sdcWelcome 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 0x2885d32c.Command (m for help): nPartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): pPartition 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): +3GCreated a new partition 1 of type 'Linux' and of size 3 GiB.Command (m for help): pDisk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x2885d32cDevice Boot Start End Sectors Size Id Type/dev/sdc1 2048 6293503 6291456 3G 83 LinuxCommand (m for help): nPartition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions)Select (default p): pPartition number (2-4, default 2): First sector (6293504-10485759, default 6293504): Last sector, +sectors or +size{K,M,G,T,P} (6293504-10485759, default 10485759): Created a new partition 2 of type 'Linux' and of size 2 GiB.Command (m for help): pDisk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x2885d32cDevice Boot Start End Sectors Size Id Type/dev/sdc1 2048 6293503 6291456 3G 83 Linux/dev/sdc2 6293504 10485759 4192256 2G 83 LinuxCommand (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 5G 0 disk ├─sdb1 8:17 0 2G 0 part /mnt/sdb1└─sdb2 8:18 0 3G 0 part /mnt/sdb2sdc 8:32 0 5G 0 disk ├─sdc1 8:33 0 3G 0 part └─sdc2 8:34 0 2G 0 part sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# mkfs.ext4 /dev/sdc1mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 786432 4k blocks and 196608 inodesFilesystem UUID: e4eac13f-f7aa-4cb1-9c72-d492f16231b9Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# mkfs.ext4 /dev/sdc2mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 524032 4k blocks and 131072 inodesFilesystem UUID: 91996752-51a6-42c3-9398-fdc9c58aa39fSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# mkdir /mnt/sdc{1,2}[root@centos8 ~]# mount /dev/sdc1 /mnt/sdc1[root@centos8 ~]# mount /dev/sdc2 /mnt/sdc2[root@centos8 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 893740 0 893740 0% /devtmpfs 921916 0 921916 0% /dev/shmtmpfs 921916 9536 912380 2% /runtmpfs 921916 0 921916 0% /sys/fs/cgroup/dev/sda2 104806400 4868932 99937468 5% //dev/sda3 52403200 398400 52004800 1% /data/dev/sda1 999320 192580 737928 21% /boottmpfs 184380 1168 183212 1% /run/user/42tmpfs 184380 4 184376 1% /run/user/0/dev/sdb1 1998672 6144 1871288 1% /mnt/sdb1/dev/sdb2 3029776 9216 2846944 1% /mnt/sdb2/dev/sdc1 3030800 9216 2847916 1% /mnt/sdc1/dev/sdc2 2030416 6144 1903084 1% /mnt/sdc2[root@centos8 ~]# bash disk_used.sh /dev/sdc1 3030800 9216 2847916 1% /mnt/sdc1/dev/sdc2 2030416 6144 1903084 1% /mnt/sdc2
3、配置为yum源
将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:
先添加一个光驱,把CentOS-6.10-x86_64-bin-DVD1.iso加载到/dev/sr0和把CentOS-6.10-x86_64-bin-DVD2.iso加载到/dev/sr1
[root@centos6 ~]# mkdir /mnt/iso#创建复制DVD1和DVD2的目录[root@centos6 ~]# mkdir /mnt/dvd1#创建挂载DVD1的目录[root@centos6 ~]# mkdir /mnt/dvd2#创建挂载DVD2的目录[root@centos6 ~]# mount /dev/sr0 /mnt/dvd1#挂载DVD1mount: block device /dev/sr0 is write-protected, mounting read-only[root@centos6 ~]# mount /dev/sr1 /mnt/dvd2#挂载DVD2mount: block device /dev/sr1 is write-protected, mounting read-only[root@centos6 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/sda2 100902304 853756 94916260 1% /tmpfs 501508 0 501508 0% /dev/shm/dev/sda1 999320 30712 916180 4% /boot/dev/sda3 51475068 53064 48800564 1% /data/dev/sr0 3897932 3897932 0 100% /mnt/dvd1/dev/sr1 2136278 2136278 0 100% /mnt/dvd2[root@centos6 ~]# ls /mnt/dvd1CentOS_BuildTag images repodata RPM-GPG-KEY-CentOS-Testing-6EFI isolinux RPM-GPG-KEY-CentOS-6 TRANS.TBLEULA Packages RPM-GPG-KEY-CentOS-Debug-6GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6[root@centos6 ~]# ls /mnt/dvd2CentOS_BuildTag Packages RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6EULA RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL[root@centos6 ~]# cp -av /mnt/dvd1/* /mnt/iso#把DVD1复制到/mnt/iso目录[root@centos6 ~]# cp -v /mnt/dvd2/Packages/*.rpm /mnt/iso/Packages/#复制DVD2到/mnt/iso#合并TRANS.TBL#将DVD2中TRANS.TBL的信息追加到DVD1中TRANS.TBL后面, 并排序保存 [root@centos6 ~]# cat /mnt/dvd2/Packages/TRANS.TBL >> /mnt/iso/Packages/TRANS.TBL [root@centos6 ~]# mv /mnt/iso/Packages/{TRANS.TBL,TRANS.TBL.BAK} [root@centos6 ~]# sort /mnt/iso/Packages/TRANS.TBL.BAK > /mnt/iso/Packages/TRANS.TBL[root@centos6 ~]# rm -rf /mnt/iso/Packages/TRANS.TBL.BAK#/mnt/iso已经是合并后的文件了[root@centos6 ~]# du -sh /mnt/iso5.9G/mnt/iso[root@centos6 ~]# mkdir /data/iso#创建iso文件目录[root@centos6 ~]# yum -y install mkisofs#安装创建ISO文件工具[root@centos6 ~]# mkisofs -l -J -L -r -V "CentOS-6.10-x86_64-Everything" -o /data/iso/CentOS-6.10-x86_64-Everything.iso /mnt/iso#创建ISO文件[root@centos6 ~]# ll -h /data/isototal 5.8G-rw-r--r-- 1 root root 5.8G Dec 4 01:38 CentOS-6.10-x86_64-Everything.iso
sz 不支持超过4G的文件传输
用Xftp 把文件传到windows里
#关机移除新添加的光驱,把/dev/sr0挂载成CentOS-6.10-x86_64-Everything.iso[root@centos6 ~]# yum -y install autofs#安装自动挂载光盘工具[root@centos6 ~]# service autofs start;chkconfig autofs on#启动autofs服务,并开机启动Loading autofs4: [ OK ]Starting automount: [ OK ][root@centos6 ~]# ls /misc[root@centos6 ~]# ls /misc/cdCentOS_BuildTag images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6EFI isolinux repodata RPM-GPG-KEY-CentOS-Testing-6EULA lost+found RPM-GPG-KEY-CentOS-6 TRANS.TBLGPL Packages RPM-GPG-KEY-CentOS-Debug-6[root@centos6 ~]# vim /etc/yum.repos.d/test.repo #设置光盘镜像本地源[base]name=basebaseurl=file:///misc/cdcheckgpg=0 :wq[root@centos6 ~]# yum repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilebase | 4.0 kB 00:00 ... repo id repo name statusbase base 6,713repolist: 6,713
方法二:
#先设置光驱加载CentOS-6.10-x86_64-bin-DVD1.iso[root@centos6 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 3.7G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 97.7G 0 part /├─sda3 8:3 0 48.8G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP][root@centos6 ~]# dd if=/dev/sr0 bs=1M of=CentOS-6.10-x86_64-Everything.iso3807+0 records in3807+0 records out3991928832 bytes (4.0 GB) copied, 271.833 s, 14.7 MB/s[root@centos6 ~]# ll CentOS-6.10-x86_64-Everything.iso -h-rw-r--r-- 1 root root 3.8G Dec 4 18:50 CentOS-6.10-x86_64-Everything.iso#把光驱断开连接,设置光驱加载CentOS-6.10-x86_64-bin-DVD2.iso,再连接光驱[root@centos6 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 2G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 97.7G 0 part /├─sda3 8:3 0 48.8G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP][root@centos6 ~]# dd if=/dev/sr0 ibs=1k skip=32 of=CentOS-6.10-x86_64-Everything.iso obs=1M seek=3788#skip=32参考的ISO9660文件头,seek=3788,跳过上个镜像的大小。2136246+0 records in2086+1 records out2187515904 bytes (2.2 GB) copied, 154.047 s, 14.2 MB/s[root@centos6 ~]# ll -h CentOS-6.10-x86_64-Everything.iso -rw-r--r-- 1 root root 5.8G Dec 4 18:56 CentOS-6.10-x86_64-Everything.iso
sz 不支持超过4G的文件传输 用Xftp 把文件传到windows里
#把光驱断开连接,设置CentOS-6.10-x86_64-Everything.iso,再连接光驱[root@centos6 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsr0 11:0 1 5.8G 0 rom sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 97.7G 0 part /├─sda3 8:3 0 48.8G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 2G 0 part [SWAP][root@centos6 ~]# yum -y install autofs#安装自动挂载光盘工具[root@centos6 ~]# service autofs start;chkconfig autofs on#启动autofs服务,并开机启动Loading autofs4: [ OK ]Starting automount: [ OK ][root@centos6 ~]# ls /misc[root@centos6 ~]# ls /misc/cdCentOS_BuildTag images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6EFI isolinux repodata RPM-GPG-KEY-CentOS-Testing-6EULA lost+found RPM-GPG-KEY-CentOS-6 TRANS.TBLGPL Packages RPM-GPG-KEY-CentOS-Debug-6[root@centos6 ~]# vim /etc/yum.repos.d/test.repo #设置光盘镜像本地源[base]name=basebaseurl=file:///misc/cdcheckgpg=0 :wq[root@centos6 ~]# yum repolistLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilebase | 4.0 kB 00:00 ... repo id repo name statusbase base 6,713repolist: 6,713
第二部分 RAID
1、创建一个可用空间为1G的RAID设备
文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录
[root@centos8 ~]# scandisk[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk sdc 8:32 0 1G 0 disk sdd 8:48 0 1G 0 disk sr0 11:0 1 7.7G 0 rom #添加三块新硬盘/dev/sdb、/dev/sdc和/dev/sdd[root@centos8 ~]# dnf -y install mdadm[root@centos8 ~]# mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sd{b,c,d}mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90Continue creating array? (y/n) ymdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md0 started.[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 sdc 8:32 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 sdd 8:48 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# mkfs.ext4 /dev/md0mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 261632 4k blocks and 65408 inodesFilesystem UUID: 5540936f-bfe4-46ff-8fbb-88e071f5499aSuperblock backups stored on blocks: 32768, 98304, 163840, 229376Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: done[root@centos8 ~]# tune2fs -l /dev/md0tune2fs 1.45.4 (23-Sep-2019)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: 5540936f-bfe4-46ff-8fbb-88e071f5499aFilesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumFilesystem flags: signed_directory_hash Default mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 65408Block count: 261632Reserved block count: 13081Free blocks: 252781Free inodes: 65397First block: 0Block size: 4096Fragment size: 4096Group descriptor size: 64Reserved GDT blocks: 127Blocks per group: 32768Fragments per group: 32768Inodes per group: 8176Inode blocks per group: 511Flex block group size: 16Filesystem created: Fri Dec 4 16:56:44 2020Last mount time: n/aLast write time: Fri Dec 4 16:56:44 2020Mount count: 0Maximum mount count: -1Last checked: Fri Dec 4 16:56:44 2020Check interval: 0 (<none>)Lifetime writes: 533 kBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 32Desired extra isize: 32Journal inode: 8Default directory hash: half_md4Directory Hash Seed: d8599d77-afd5-4e2f-80c6-f206e7dc2babJournal backup: inode blocksChecksum type: crc32cChecksum: 0x066b1a44[root@centos8 ~]# mkdir /backup[root@centos8 ~]# blkid /dev/md0/dev/md0: UUID="5540936f-bfe4-46ff-8fbb-88e071f5499a" TYPE="ext4"[root@centos8 ~]# vim /etc/fstab#添加下面内容UUID=5540936f-bfe4-46ff-8fbb-88e071f5499a /backup ext4 defaults 0 0 :wq[root@centos8 ~]# mount -a[root@centos8 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 884M 0 884M 0% /devtmpfs 901M 0 901M 0% /dev/shmtmpfs 901M 8.7M 892M 1% /runtmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/sda2 100G 2.1G 98G 3% //dev/sda3 50G 390M 50G 1% /data/dev/sda1 976M 135M 775M 15% /boottmpfs 181M 0 181M 0% /run/user/0/dev/md0 990M 2.6M 921M 1% /backup[root@centos8 ~]# reboot[root@centos8 ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 884M 0 884M 0% /devtmpfs 901M 0 901M 0% /dev/shmtmpfs 901M 8.7M 892M 1% /runtmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/sda2 100G 2.1G 98G 3% //dev/sda3 50G 390M 50G 1% /data/dev/sda1 976M 135M 775M 15% /boot/dev/md0 990M 2.6M 921M 1% /backuptmpfs 181M 0 181M 0% /run/user/0[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 /backupsdc 8:32 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 /backupsdd 8:48 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 /backupsr0 11:0 1 7.7G 0 rom
2、创建由三块硬盘组成的可用空间为2G的RAID5设备
要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录
[root@centos8 ~]# scandisk[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk sdc 8:32 0 1G 0 disk sdd 8:48 0 1G 0 disk sr0 11:0 1 7.7G 0 rom #添加三块新硬盘/dev/sdb、/dev/sdc和/dev/sdd[root@centos8 ~]# dnf -y install mdadm[root@centos8 ~]# mdadm -C /dev/md1 -a yes -l 5 -n 3 -c 256 /dev/sd{b,c,d}mdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md1 started.[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 sdc 8:32 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 sdd 8:48 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# mkfs.ext4 /dev/md1mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 523264 4k blocks and 130816 inodesFilesystem UUID: d4447cca-1a84-44c3-b3f6-9a7956091233Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# tune2fs -l /dev/md1tune2fs 1.45.4 (23-Sep-2019)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: d4447cca-1a84-44c3-b3f6-9a7956091233Filesystem magic number: 0xEF53Filesystem revision #: 1 (dynamic)Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csumFilesystem flags: signed_directory_hash Default mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 130816Block count: 523264Reserved block count: 26163Free blocks: 505316Free inodes: 130805First block: 0Block size: 4096Fragment size: 4096Group descriptor size: 64Reserved GDT blocks: 255Blocks per group: 32768Fragments per group: 32768Inodes per group: 8176Inode blocks per group: 511RAID stride: 64RAID stripe width: 128Flex block group size: 16Filesystem created: Fri Dec 4 17:24:39 2020Last mount time: n/aLast write time: Fri Dec 4 17:24:40 2020Mount count: 0Maximum mount count: -1Last checked: Fri Dec 4 17:24:39 2020Check interval: 0 (<none>)Lifetime writes: 1045 kBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 32Desired extra isize: 32Journal inode: 8Default directory hash: half_md4Directory Hash Seed: f959b864-fcb7-4eb0-8088-f04be25671fdJournal backup: inode blocksChecksum type: crc32cChecksum: 0x7e59f1b1[root@centos8 ~]# mkdir /mydata[root@centos8 ~]# blkid /dev/md1/dev/md1: UUID="d4447cca-1a84-44c3-b3f6-9a7956091233" TYPE="ext4"[root@centos8 ~]# vim /etc/fstab#添加下面内容UUID=d4447cca-1a84-44c3-b3f6-9a7956091233 /mydata ext4 defaults 0 0 :wq[root@centos8 ~]# mount -a[root@centos8 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 905164 0 905164 0% /devtmpfs 921932 0 921932 0% /dev/shmtmpfs 921932 8900 913032 1% /runtmpfs 921932 0 921932 0% /sys/fs/cgroup/dev/sda2 104806400 2149500 102656900 3% //dev/sda3 52403200 398400 52004800 1% /data/dev/sda1 999320 137584 792924 15% /boottmpfs 184384 0 184384 0% /run/user/0/dev/md1 2027408 6144 1900228 1% /mydata[root@centos8 ~]# reboot[root@centos8 ~]# dfFilesystem 1K-blocks Used Available Use% Mounted ondevtmpfs 905164 0 905164 0% /devtmpfs 921932 0 921932 0% /dev/shmtmpfs 921932 8908 913024 1% /runtmpfs 921932 0 921932 0% /sys/fs/cgroup/dev/sda2 104806400 2148524 102657876 3% //dev/sda3 52403200 398400 52004800 1% /data/dev/sda1 999320 137580 792928 15% /boot/dev/md1 2027408 6144 1900228 1% /mydatatmpfs 184384 0 184384 0% /run/user/0[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 /mydatasdc 8:32 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 /mydatasdd 8:48 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 /mydatasr0 11:0 1 7.7G 0 rom
第三部分 LVM
1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;
需求PE大小为16MB,而后在卷组中的创建大小为5G的逻辑卷testlv;挂载至/users目录
[root@centos8 ~]# scandisk[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 15G 0 disk sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom #添加两块硬盘sdb、sdc[root@centos8 ~]# pvs /dev/sd{b,c}-bash: pvs: command not found[root@centos8 ~]# dnf -y install lvm2[root@centos8 ~]# pvs[root@centos8 ~]# vgs[root@centos8 ~]# lvs[root@centos8 ~]# pvcreate /dev/sd{b,c}#把两块硬盘加到物理卷 Physical volume "/dev/sdb" successfully created. Physical volume "/dev/sdc" successfully created.[root@centos8 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb lvm2 --- 15.00g 15.00g /dev/sdc lvm2 --- 5.00g 5.00g[root@centos8 ~]# vgcreate -s 16M testvg /dev/sd{b,c}#把 /dev/sdb和/dev/sdc加入到卷组,块大小为16M Volume group "testvg" successfully created[root@centos8 ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 0 0 wz--n- <19.97g <19.97g[root@centos8 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb testvg lvm2 a-- 14.98g 14.98g /dev/sdc testvg lvm2 a-- 4.98g 4.98g[root@centos8 ~]# vgdisplay --- Volume group --- VG Name testvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size <19.97 GiB#卷组大小20G PE Size 16.00 MiB#块大小为16M Total PE 1278 Alloc PE / Size 0 / 0 Free PE / Size 1278 / <19.97 GiB VG UUID ICjCEw-pbWT-0jUt-f4hV-lDOJ-YSSq-o3tq5U[root@centos8 ~]# lvcreate -L 5G -n testlv testvg#创建逻辑卷testlv,大小5G Logical volume "testlv" created.[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-a----- 5.00g [root@centos8 ~]# lvdisplay --- Logical volume --- LV Path /dev/testvg/testlv LV Name testlv VG Name testvg LV UUID aPZyRk-7n9N-P7ol-ZwJv-2LHI-aOm2-8tED5j LV Write Access read/write LV Creation host, time centos8.neteagles.cn, 2020-12-06 19:54:00 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 320 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0[root@centos8 ~]# mkfs.ext4 /dev/testvg/testlv#创建逻辑卷文件系统mke2fs 1.45.4 (23-Sep-2019)Creating filesystem with 1310720 4k blocks and 327680 inodesFilesystem UUID: 81a7eb1b-72ae-4d5c-9d0f-44a3daa14610Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done [root@centos8 ~]# mkdir /users[root@centos8 ~]# mount /dev/testvg/testlv /users/#挂载逻辑卷[root@centos8 ~]# df -ThFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 884M 0 884M 0% /devtmpfs tmpfs 901M 0 901M 0% /dev/shmtmpfs tmpfs 901M 8.7M 892M 1% /runtmpfs tmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/sda2 xfs 100G 2.1G 98G 3% //dev/sda3 xfs 50G 390M 50G 1% /data/dev/sda1 ext4 976M 135M 775M 15% /boottmpfs tmpfs 181M 0 181M 0% /run/user/0/dev/mapper/testvg-testlv ext4 4.9G 20M 4.6G 1% /users#已被挂载
2、新建用户archlinux
需求其家目录为/users/archlinux,而后su切换至archlinux用户,复制/etc/pam.d目录至自己的家目录
[root@centos8 ~]# useradd -d /users/archlinux archlinux[root@centos8 ~]# getent passwd archlinuxarchlinux:x:1001:1001::/users/archlinux:/bin/bash[root@centos8 ~]# su archlinux[archlinux@centos8 root]$ cp -r /etc/pam.d ~[archlinux@centos8 root]$ ll -a /users/archlinux/total 28drwx------ 3 archlinux archlinux 4096 Dec 6 19:57 .drwxr-xr-x 4 root root 4096 Dec 6 19:56 ..-rw------- 1 archlinux archlinux 93 Dec 6 19:57 .bash_history-rw-r--r-- 1 archlinux archlinux 18 Nov 9 2019 .bash_logout-rw-r--r-- 1 archlinux archlinux 141 Nov 9 2019 .bash_profile-rw-r--r-- 1 archlinux archlinux 312 Nov 9 2019 .bashrcdrwxr-xr-x 2 archlinux archlinux 4096 Dec 6 19:56 pam.d
3、扩展testlv至7G
需求archlinux用户的文件不能丢失
[archlinux@centos8 root]$ exitexit[root@centos8 ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 1 0 wz--n- <19.97g <14.97g#卷组可用空间为15G[root@centos8 ~]# lvextend -r -L +2G /dev/testvg/testlv Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents). Logical volume testvg/testlv successfully resized.resize2fs 1.45.4 (23-Sep-2019)Filesystem at /dev/mapper/testvg-testlv is mounted on /users; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 1The filesystem on /dev/mapper/testvg-testlv is now 1835008 (4k) blocks long.[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 7.00g [root@centos8 ~]# df -ThFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 884M 0 884M 0% /devtmpfs tmpfs 901M 0 901M 0% /dev/shmtmpfs tmpfs 901M 8.7M 892M 1% /runtmpfs tmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/sda2 xfs 100G 2.1G 98G 3% //dev/sda3 xfs 50G 390M 50G 1% /data/dev/sda1 ext4 976M 135M 775M 15% /boottmpfs tmpfs 181M 0 181M 0% /run/user/0/dev/mapper/testvg-testlv ext4 6.9G 23M 6.5G 1% /users[root@centos8 ~]# ll -a /users/archlinux/total 28drwx------ 3 archlinux archlinux 4096 Dec 6 19:57 .drwxr-xr-x 4 root root 4096 Dec 6 19:56 ..-rw------- 1 archlinux archlinux 93 Dec 6 19:57 .bash_history-rw-r--r-- 1 archlinux archlinux 18 Nov 9 2019 .bash_logout-rw-r--r-- 1 archlinux archlinux 141 Nov 9 2019 .bash_profile-rw-r--r-- 1 archlinux archlinux 312 Nov 9 2019 .bashrcdrwxr-xr-x 2 archlinux archlinux 4096 Dec 6 19:56 pam.d#数据还在
4、收缩testlv至3G
要求archlinux用户的文件不能丢失
[root@centos8 ~]# umount /dev/testvg/testlv #取消挂载[root@centos8 ~]# fsck -f /dev/testvg/testlv #检查文件系统fsck from util-linux 2.32.1e2fsck 1.45.4 (23-Sep-2019)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/mapper/testvg-testlv: 40/458752 files (0.0% non-contiguous), 50972/1835008 blocks[root@centos8 ~]# resize2fs /dev/testvg/testlv 3G#缩减文件系统resize2fs 1.45.4 (23-Sep-2019)Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.The filesystem on /dev/testvg/testlv is now 786432 (4k) blocks long. [root@centos8 ~]# lvreduce -L 3G /dev/testvg/testlv #缩减逻辑卷 WARNING: Reducing active logical volume to 3.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce testvg/testlv? [y/n]: y Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents). Logical volume testvg/testlv successfully resized.[root@centos8 ~]# mount /dev/testvg/testlv /users/#挂载逻辑卷[root@centos8 ~]# df -ThFilesystem Type Size Used Avail Use% Mounted ondevtmpfs devtmpfs 884M 0 884M 0% /devtmpfs tmpfs 901M 0 901M 0% /dev/shmtmpfs tmpfs 901M 8.7M 892M 1% /runtmpfs tmpfs 901M 0 901M 0% /sys/fs/cgroup/dev/sda2 xfs 100G 2.1G 98G 3% //dev/sda3 xfs 50G 390M 50G 1% /data/dev/sda1 ext4 976M 135M 775M 15% /boottmpfs tmpfs 181M 0 181M 0% /run/user/0/dev/mapper/testvg-testlv ext4 2.9G 16M 2.8G 1% /users#现在已经缩减至3G[root@centos8 ~]# ll -a /users/archlinux/total 28drwx------ 3 archlinux archlinux 4096 Dec 6 19:57 .drwxr-xr-x 4 root root 4096 Dec 6 19:56 ..-rw------- 1 archlinux archlinux 93 Dec 6 19:57 .bash_history-rw-r--r-- 1 archlinux archlinux 18 Nov 9 2019 .bash_logout-rw-r--r-- 1 archlinux archlinux 141 Nov 9 2019 .bash_profile-rw-r--r-- 1 archlinux archlinux 312 Nov 9 2019 .bashrcdrwxr-xr-x 2 archlinux archlinux 4096 Dec 6 19:56 pam.d#数据还在
5、对testlv创建快照
并尝试基于快照备份数据,验证快照的功能
[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 3.00g #逻辑卷还有未使用空间[root@centos8 ~]# lvcreate -s -L 1G -n testlv-snapshot -p r /dev/testvg/testlv Logical volume "testlv-snapshot" created.[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg owi-aos--- 3.00g testlv-snapshot testvg sri-a-s--- 1.00g testlv 0.01 [root@centos8 ~]# lvdisplay --- Logical volume --- LV Path /dev/testvg/testlv LV Name testlv VG Name testvg LV UUID aPZyRk-7n9N-P7ol-ZwJv-2LHI-aOm2-8tED5j LV Write Access read/write LV Creation host, time centos8.neteagles.cn, 2020-12-06 19:54:00 +0800 LV snapshot status source of testlv-snapshot [active] LV Status available # open 1 LV Size 3.00 GiB Current LE 192 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0 --- Logical volume --- LV Path /dev/testvg/testlv-snapshot LV Name testlv-snapshot VG Name testvg LV UUID PvdE7T-kJCO-ogxX-bjZ3-jRbT-SwVn-z9KqJ9 LV Write Access read only LV Creation host, time centos8.neteagles.cn, 2020-12-06 20:12:33 +0800 LV snapshot status active destination for testlv LV Status available # open 0 LV Size 3.00 GiB Current LE 192 COW-table size 1.00 GiB COW-table LE 64 Allocated to snapshot 0.01% Snapshot chunk size 4.00 KiB Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:3[root@centos8 ~]# mkdir /mnt/testlv-snapshot[root@centos8 ~]# mount /dev/testvg/testlv-snapshot /mnt/testlv-snapshot/mount: /mnt/testlv-snapshot: WARNING: device write-protected, mounted read-only.[root@centos8 ~]# ls /mnt/testlv-snapshot/archlinux lost+found[root@centos8 ~]# ls /users/archlinux lost+found[root@centos8 ~]# ls /users/archlinux/pam.d[root@centos8 ~]# rm -rf /users/archlinux/pam.d/#删除逻辑卷中的牡蛎[root@centos8 ~]# ls /users/archlinux/#逻辑卷中已经没有了[root@centos8 ~]# ls /mnt/testlv-snapshot/archlinux/pam.d#快照中还在[root@centos8 ~]# rm -rf /mnt/testlv-snapshot/archlinux/pam.d/rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/runuser': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/polkit-1': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/systemd-user': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/passwd': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/password-auth': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vmtoolsd': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/system-auth': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vlock': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/runuser-l': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sssd-shadowutils': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/postlogin': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/remote': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo-i': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/fingerprint-auth': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sshd': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/config-util': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su-l': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/smartcard-auth': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/other': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/login': Read-only file systemrm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/crond': Read-only file system#快照中的文件不能删除[root@centos8 ~]# umount /dev/testvg/testlv#取消挂载逻辑卷[root@centos8 ~]# umount /mnt/testlv-snapshot/#取消挂载快照[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg owi-a-s--- 3.00g testlv-snapshot testvg sri-a-s--- 1.00g testlv 0.01 [root@centos8 ~]# lvconvert --merge /dev/testvg/testlv-snapshot #合并快照 Merging of volume testvg/testlv-snapshot started. testvg/testlv: Merged: 100.00%[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-a----- 3.00g #快照只是一次性的,还原过后就没有了[root@centos8 ~]# mount /dev/testvg/testlv /users/#挂载逻辑卷[root@centos8 ~]# ll /users/total 20drwx------ 3 archlinux archlinux 4096 Dec 6 19:57 archlinuxdrwx------ 2 root root 16384 Dec 6 19:54 lost+found[root@centos8 ~]# ll /users/archlinux/total 4drwxr-xr-x 2 archlinux archlinux 4096 Dec 6 19:56 pam.d#还原成做快照时的文件了
6、删除逻辑卷、卷组、物理卷
[root@centos8 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert testlv testvg -wi-ao---- 3.00g [root@centos8 ~]# umount /dev/testvg/testlv #取消逻辑卷挂载[root@centos8 ~]# lvremove /dev/testvg/testlv #删除逻辑卷Do you really want to remove active logical volume testvg/testlv? [y/n]: y Logical volume "testlv" successfully removed[root@centos8 ~]# lvs[root@centos8 ~]# vgs VG #PV #LV #SN Attr VSize VFree testvg 2 0 0 wz--n- <19.97g <19.97g[root@centos8 ~]# vgremove testvg#删除卷组 Volume group "testvg" successfully removed[root@centos8 ~]# vgs[root@centos8 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb lvm2 --- 15.00g 15.00g /dev/sdc lvm2 --- 5.00g 5.00g[root@centos8 ~]# pvremove /dev/sd{b,c}#删除逻辑卷 Labels on physical volume "/dev/sdb" successfully wiped. Labels on physical volume "/dev/sdc" successfully wiped.[root@centos8 ~]# pvs[root@centos8 ~]# lvblk-bash: lvblk: command not found[root@centos8 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 100G 0 part /├─sda3 8:3 0 50G 0 part /data├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 4G 0 part [SWAP]sdb 8:16 0 15G 0 disk sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom
以上就是s49 磁盘存储文件系统管理详解的详细内容