mount,shell脚本 测试

1、创建一个2G的文件系统,块大小为2048byte,预留1%可用空间,文件系统ext4,卷标为TEST,要求此分区开机后自动挂载至/test目录,且默认有acl挂载选项。

①.首先是创建分区:以(/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.


Command (m for help): p

Disk /dev/sdb: 42.9 GB, 42949672960 bytes, 83886080 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: 0x8b2da589

   Device Boot      Start         End      Blocks   Id  System

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-83886079, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

 ②.创建文化系统:

[root@localhost /]# mkfs -t 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, 802816

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

③创建挂载目录:

[root@localhost /]# mkdir -p  /test

④临时挂载:

[root@localhost /]# mount -o  auto,acl   /dev/sdb1   /test  

  永久挂载:

[root@localhost ~]# vim /etc/fstab   

#
# /etc/fstab
# Created by anaconda on Mon Apr 22 01:12:17 2024
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=cdea4c80-2a37-45aa-a05b-6f700505db57 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

UUID="491794d8-5798-4d33-aefb-cdb5a8e15211" /test  ext4  defaults,acl   0 0

⑤查看分区情况:

[root@localhost /]# lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda                                                                                
├─sda1          xfs                         cdea4c80-2a37-45aa-a05b-6f700505db57   /boot
└─sda2          LVM2_member                 riGs4v-wcJr-2qhC-1EpT-2X7c-YpUp-zRnF2n 
  ├─centos-root xfs                         504ff06f-f38e-409a-bfab-3ff045c8cfee   /
  └─centos-swap swap                        c3f42d31-88d2-447b-bde6-e6a79f3c0607   [SWAP]
sdb                                                                                
└─sdb1          ext4        TEST            491794d8-5798-4d33-aefb-cdb5a8e15211   /test 

⑥.验证acl权限是否成功,先给用户赋予rwx权限,登录Natsu用户,在ai.txt添加内容,然后在root用户查看内容有没有添加成功。

[root@localhost ~]# setfacl -m  u:Natsu:rwx   /test/ai.txt
[root@localhost ~]# getfacl /test/ai.txt
getfacl: Removing leading '/' from absolute path names
# file: test/ai.txt
# owner: root
# group: root
user::rw-
user:Natsu:rwx
group::r--
mask::rwx
other::r--

[root@localhost ~]# su - Natsu
Last login: Mon May  6 22:16:38 CST 2024 on pts/0

[Natsu@localhost test]$ vim ai.txt
你敢点击这个网址吗?https://www.baidu.com 

[Natsu@localhost ~]$ exit
logout
[root@localhost ~]# cat  /test/ai.txt 
ლ(′◉❥◉`ლ)
你敢点击这个网址吗?https://www.baidu.com 

2、写一个脚本,完成如下功能:
(1)列出当前系统识别到的所有磁盘设备。
(2)如磁盘数量为1,则显示其空间使用信息,否则,则显示最后一个磁盘上的空间使用信息。

[root@localhost data]# vim disktest.sh

#! /bin/bash
diskNum=`ls /dev/sd* | wc -l`
ls /dev/sd*
if [  $diskNum -eq 1 ];then
    df  -hT  ` ls /dev/sd* `
else
    df  -hT   `ls /dev/sd* | tail  -n1` 
fi

结果:

[root@localhost data]# bash disktest.sh
/dev/sda  /dev/sda1  /dev/sda2  /dev/sdb  /dev/sdb1
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/sdb1      ext4  2.0G  9.1M  1.9G   1% /test

 

  • 13
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值