s49 磁盘存储文件系统管理详解
Raymond_Operations 人气:0第一部分
1、创建一个2G的文件系统
块大小为2048byte,预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项
#新添加一块10G磁盘 [root@centos8 ~]# scandisk [root@centos8 ~]# alias scandisk alias scandisk='echo '\''- - -'\'' > /sys/class/scsi_host/host0/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host1/scan;echo '\''- - -'\'' > /sys/class/scsi_host/host2/scan' [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/sdd 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 0x0712eaa0. 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): First sector (2048-20971519, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +2G Created a new partition 1 of type 'Linux' and of size 2 GiB. Command (m for help): p Disk /dev/sdd: 10 GiB, 10737418240 bytes, 20971520 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 Disklabel type: dos Disk identifier: 0x0712eaa0 Device Boot Start End Sectors Size Id Type /dev/sdd1 2048 4196351 4194304 2G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 卷标名为TEST mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 1048576 2k blocks and 131072 inodes Filesystem UUID: 0f8a2804-a927-4cde-9d3c-8066d7148386 Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@centos8 ~]# tune2fs -l /dev/sdd1 tune2fs 1.45.4 (23-Sep-2019) Filesystem volume name: TEST #卷标名为TEST。 Last mounted on: <not available> Filesystem UUID: 0f8a2804-a927-4cde-9d3c-8066d7148386 Filesystem magic number: 0xEF53 Filesystem 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_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl #centos8 ext4文件系统,默认就有acl功能,不需要单独设置 Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 131072 Block count: 1048576 Reserved block count: 10485 #预留块大小 Free blocks: 1011035 Free inodes: 131061 First block: 0 Block size: 2048 #块大小为2048。 Fragment size: 2048 Group descriptor size: 64 Reserved GDT blocks: 512 Blocks per group: 16384 Fragments per group: 16384 Inodes per group: 2048 Inode blocks per group: 256 Flex block group size: 16 Filesystem created: Thu Dec 3 22:58:44 2020 Last mount time: n/a Last write time: Thu Dec 3 22:58:44 2020 Mount count: 0 Maximum mount count: -1 Last checked: Thu Dec 3 22:58:44 2020 Check interval: 0 (<none>) Lifetime writes: 1058 kB Reserved blocks uid: 0 (user root) #预留给谁使用,root。 Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: c99589a0-f6eb-4dd6-a178-b4113c273353 Journal backup: inode blocks Checksum type: crc32c Checksum: 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 905164 0 905164 0% /dev tmpfs 921932 0 921932 0% /dev/shm tmpfs 921932 8940 912992 1% /run tmpfs 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% /boot tmpfs 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 ];then df | grep "/dev/$disk" else df | 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/sdb 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 0x2e83806e. 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): 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): p Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x2e83806e Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4196351 4194304 2G 83 Linux 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): 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): p Disk /dev/sdb: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x2e83806e Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4196351 4194304 2G 83 Linux /dev/sdb2 4196352 10485759 6289408 3G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/sdb1 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 524288 4k blocks and 131072 inodes Filesystem UUID: c520fbef-2726-4ab2-b54f-b654bd6c6a1f Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@centos8 ~]# mkfs.ext4 /dev/sdb2 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 786176 4k blocks and 196608 inodes Filesystem UUID: b5efe116-aec1-41e7-80a2-3791b3ee5669 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing 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 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 893740 0 893740 0% /dev tmpfs 921916 0 921916 0% /dev/shm tmpfs 921916 9528 912388 2% /run tmpfs 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% /boot tmpfs 184380 1168 183212 1% /run/user/42 tmpfs 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/sdb2 sdc 8:32 0 5G 0 disk sr0 11:0 1 7.7G 0 rom [root@centos8 ~]# fdisk /dev/sdc 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 0x2885d32c. 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): First sector (2048-10485759, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-10485759, default 10485759): +3G Created a new partition 1 of type 'Linux' and of size 3 GiB. Command (m for help): p Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x2885d32c Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 6293503 6291456 3G 83 Linux 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): 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): p Disk /dev/sdc: 5 GiB, 5368709120 bytes, 10485760 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 Disklabel type: dos Disk identifier: 0x2885d32c Device Boot Start End Sectors Size Id Type /dev/sdc1 2048 6293503 6291456 3G 83 Linux /dev/sdc2 6293504 10485759 4192256 2G 83 Linux Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/sdb2 sdc 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/sdc1 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 786432 4k blocks and 196608 inodes Filesystem UUID: e4eac13f-f7aa-4cb1-9c72-d492f16231b9 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@centos8 ~]# mkfs.ext4 /dev/sdc2 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 524032 4k blocks and 131072 inodes Filesystem UUID: 91996752-51a6-42c3-9398-fdc9c58aa39f Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing 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 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 893740 0 893740 0% /dev tmpfs 921916 0 921916 0% /dev/shm tmpfs 921916 9536 912380 2% /run tmpfs 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% /boot tmpfs 184380 1168 183212 1% /run/user/42 tmpfs 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 #挂载DVD1 mount: block device /dev/sr0 is write-protected, mounting read-only [root@centos6 ~]# mount /dev/sr1 /mnt/dvd2 #挂载DVD2 mount: block device /dev/sr1 is write-protected, mounting read-only [root@centos6 ~]# df Filesystem 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/dvd1 CentOS_BuildTag images repodata RPM-GPG-KEY-CentOS-Testing-6 EFI isolinux RPM-GPG-KEY-CentOS-6 TRANS.TBL EULA Packages RPM-GPG-KEY-CentOS-Debug-6 GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 [root@centos6 ~]# ls /mnt/dvd2 CentOS_BuildTag Packages RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 EULA 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/iso 5.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/iso total 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/cd CentOS_BuildTag images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 EFI isolinux repodata RPM-GPG-KEY-CentOS-Testing-6 EULA lost+found RPM-GPG-KEY-CentOS-6 TRANS.TBL GPL Packages RPM-GPG-KEY-CentOS-Debug-6 [root@centos6 ~]# vim /etc/yum.repos.d/test.repo #设置光盘镜像本地源 [base] name=base baseurl=file:///misc/cd checkgpg=0 :wq [root@centos6 ~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 4.0 kB 00:00 ... repo id repo name status base base 6,713 repolist: 6,713
方法二:
#先设置光驱加载CentOS-6.10-x86_64-bin-DVD1.iso [root@centos6 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 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.iso 3807+0 records in 3807+0 records out 3991928832 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 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 in 2086+1 records out 2187515904 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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 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/cd CentOS_BuildTag images RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 EFI isolinux repodata RPM-GPG-KEY-CentOS-Testing-6 EULA lost+found RPM-GPG-KEY-CentOS-6 TRANS.TBL GPL Packages RPM-GPG-KEY-CentOS-Debug-6 [root@centos6 ~]# vim /etc/yum.repos.d/test.repo #设置光盘镜像本地源 [base] name=base baseurl=file:///misc/cd checkgpg=0 :wq [root@centos6 ~]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile base | 4.0 kB 00:00 ... repo id repo name status base base 6,713 repolist: 6,713
第二部分 RAID
1、创建一个可用空间为1G的RAID设备
文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录
[root@centos8 ~]# scandisk [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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.90 Continue creating array? (y/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/md0 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 261632 4k blocks and 65408 inodes Filesystem UUID: 5540936f-bfe4-46ff-8fbb-88e071f5499a Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done [root@centos8 ~]# tune2fs -l /dev/md0 tune2fs 1.45.4 (23-Sep-2019) Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: 5540936f-bfe4-46ff-8fbb-88e071f5499a Filesystem magic number: 0xEF53 Filesystem 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_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 65408 Block count: 261632 Reserved block count: 13081 Free blocks: 252781 Free inodes: 65397 First block: 0 Block size: 4096 Fragment size: 4096 Group descriptor size: 64 Reserved GDT blocks: 127 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8176 Inode blocks per group: 511 Flex block group size: 16 Filesystem created: Fri Dec 4 16:56:44 2020 Last mount time: n/a Last write time: Fri Dec 4 16:56:44 2020 Mount count: 0 Maximum mount count: -1 Last checked: Fri Dec 4 16:56:44 2020 Check interval: 0 (<none>) Lifetime writes: 533 kB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: d8599d77-afd5-4e2f-80c6-f206e7dc2bab Journal backup: inode blocks Checksum type: crc32c Checksum: 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 -h Filesystem Size Used Avail Use% Mounted on devtmpfs 884M 0 884M 0% /dev tmpfs 901M 0 901M 0% /dev/shm tmpfs 901M 8.7M 892M 1% /run tmpfs 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 tmpfs 181M 0 181M 0% /run/user/0 /dev/md0 990M 2.6M 921M 1% /backup [root@centos8 ~]# reboot [root@centos8 ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 884M 0 884M 0% /dev tmpfs 901M 0 901M 0% /dev/shm tmpfs 901M 8.7M 892M 1% /run tmpfs 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% /backup tmpfs 181M 0 181M 0% /run/user/0 [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 /backup sdc 8:32 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 /backup sdd 8:48 0 1G 0 disk └─md0 9:0 0 1022M 0 raid1 /backup sr0 11:0 1 7.7G 0 rom
2、创建由三块硬盘组成的可用空间为2G的RAID5设备
要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录
[root@centos8 ~]# scandisk [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 metadata mdadm: array /dev/md1 started. [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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/md1 mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 523264 4k blocks and 130816 inodes Filesystem UUID: d4447cca-1a84-44c3-b3f6-9a7956091233 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done [root@centos8 ~]# tune2fs -l /dev/md1 tune2fs 1.45.4 (23-Sep-2019) Filesystem volume name: <none> Last mounted on: <not available> Filesystem UUID: d4447cca-1a84-44c3-b3f6-9a7956091233 Filesystem magic number: 0xEF53 Filesystem 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_csum Filesystem flags: signed_directory_hash Default mount options: user_xattr acl Filesystem state: clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 130816 Block count: 523264 Reserved block count: 26163 Free blocks: 505316 Free inodes: 130805 First block: 0 Block size: 4096 Fragment size: 4096 Group descriptor size: 64 Reserved GDT blocks: 255 Blocks per group: 32768 Fragments per group: 32768 Inodes per group: 8176 Inode blocks per group: 511 RAID stride: 64 RAID stripe width: 128 Flex block group size: 16 Filesystem created: Fri Dec 4 17:24:39 2020 Last mount time: n/a Last write time: Fri Dec 4 17:24:40 2020 Mount count: 0 Maximum mount count: -1 Last checked: Fri Dec 4 17:24:39 2020 Check interval: 0 (<none>) Lifetime writes: 1045 kB Reserved blocks uid: 0 (user root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal inode: 8 Default directory hash: half_md4 Directory Hash Seed: f959b864-fcb7-4eb0-8088-f04be25671fd Journal backup: inode blocks Checksum type: crc32c Checksum: 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 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 905164 0 905164 0% /dev tmpfs 921932 0 921932 0% /dev/shm tmpfs 921932 8900 913032 1% /run tmpfs 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% /boot tmpfs 184384 0 184384 0% /run/user/0 /dev/md1 2027408 6144 1900228 1% /mydata [root@centos8 ~]# reboot [root@centos8 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 905164 0 905164 0% /dev tmpfs 921932 0 921932 0% /dev/shm tmpfs 921932 8908 913024 1% /run tmpfs 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% /mydata tmpfs 184384 0 184384 0% /run/user/0 [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 /mydata sdc 8:32 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 /mydata sdd 8:48 0 1G 0 disk └─md1 9:1 0 2G 0 raid5 /mydata sr0 11:0 1 7.7G 0 rom
第三部分 LVM
1、创建一个至少有两个PV组成的大小为20G的名为testvg的VG;
需求PE大小为16MB,而后在卷组中的创建大小为5G的逻辑卷testlv;挂载至/users目录
[root@centos8 ~]# scandisk [root@centos8 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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 inodes Filesystem UUID: 81a7eb1b-72ae-4d5c-9d0f-44a3daa14610 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@centos8 ~]# mkdir /users [root@centos8 ~]# mount /dev/testvg/testlv /users/ #挂载逻辑卷 [root@centos8 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 884M 0 884M 0% /dev tmpfs tmpfs 901M 0 901M 0% /dev/shm tmpfs tmpfs 901M 8.7M 892M 1% /run tmpfs 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% /boot tmpfs 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 archlinux archlinux: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 28 drwx------ 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 .bashrc drwxr-xr-x 2 archlinux archlinux 4096 Dec 6 19:56 pam.d
3、扩展testlv至7G
需求archlinux用户的文件不能丢失
[archlinux@centos8 root]$ exit exit [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 required old_desc_blocks = 1, new_desc_blocks = 1 The 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 -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 884M 0 884M 0% /dev tmpfs tmpfs 901M 0 901M 0% /dev/shm tmpfs tmpfs 901M 8.7M 892M 1% /run tmpfs 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% /boot tmpfs 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 28 drwx------ 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 .bashrc drwxr-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.1 e2fsck 1.45.4 (23-Sep-2019) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 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 -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 884M 0 884M 0% /dev tmpfs tmpfs 901M 0 901M 0% /dev/shm tmpfs tmpfs 901M 8.7M 892M 1% /run tmpfs 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% /boot tmpfs 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 28 drwx------ 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 .bashrc drwxr-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 system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/polkit-1': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/systemd-user': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/passwd': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/password-auth': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vmtoolsd': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/system-auth': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/vlock': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/runuser-l': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sssd-shadowutils': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/postlogin': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/remote': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo-i': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/fingerprint-auth': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sshd': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/config-util': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/su-l': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/smartcard-auth': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/sudo': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/other': Read-only file system rm: cannot remove '/mnt/testlv-snapshot/archlinux/pam.d/login': Read-only file system rm: 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 20 drwx------ 3 archlinux archlinux 4096 Dec 6 19:57 archlinux drwx------ 2 root root 16384 Dec 6 19:54 lost+found [root@centos8 ~]# ll /users/archlinux/ total 4 drwxr-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 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 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
加载全部内容