磁盘管理作业

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

[root@English6 ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xba5c32cb.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba5c32cb

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +2G

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@English6 ~]# mke2fs -b 2048 -m 1 -t ext4 -L TEST /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=TEST
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
131560 inodes, 1052240 blocks
10522 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=538968064
65 block groups
16384 blocks per group, 16384 fragments per group
2024 inodes per group
Superblock backups stored on blocks: 
	16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816

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

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@English6 ~]# blkid
/dev/sda1: UUID="47c3f22b-7ed9-4ce1-b341-2d95ff6555af" TYPE="ext4" 
/dev/sda2: UUID="33bb1eff-ce5c-4fd8-954e-191c7fb12e6d" TYPE="ext4" 
/dev/sda3: UUID="c9eeb128-84ac-402c-bf90-91ef5f355355" TYPE="ext4" 
/dev/sda5: UUID="68b451f6-71ee-4631-a98c-c0a201df6009" TYPE="swap" 
/dev/sde1: UUID="6fbf0519-88ee-4d99-80aa-3738551ccbcb" TYPE="ext4" LABEL="sde" 
/dev/sde2: UUID="46fbd103-c122-4880-8090-e69b7762f3ad" TYPE="swap" 
/dev/sdb1: UUID="7454f830-57f9-46f8-bb3d-78cb0c34e803" TYPE="swap" 
/dev/sdc1: LABEL="TEST" UUID="04b2bfca-32b9-4d52-beb4-5845281c63a4" TYPE="ext4" 
[root@English6 ~]# vim /etc/fstab 


#
# /etc/fstab
# Created by anaconda on Thu Jul 21 16:53:41 2016
#
# 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
#
UUID=33bb1eff-ce5c-4fd8-954e-191c7fb12e6d /                       ext4    defaults        1 1
UUID=47c3f22b-7ed9-4ce1-b341-2d95ff6555af /boot                   ext4    defaults        1 2
UUID=c9eeb128-84ac-402c-bf90-91ef5f355355 /testdir                ext4    defaults        1 2
UUID=68b451f6-71ee-4631-a98c-c0a201df6009 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
UUID="04b2bfca-32b9-4d52-beb4-5845281c63a4"     /wang   ext4    acl     0 0
~                                                                                                                                                                      
~                                                                  
[root@English6 ~]# mount -a   
[root@English6 ~]# reboot

Broadcast message from root@English6.8
	(/dev/pts/2) at 22:33 ...

The system is going down for reboot NOW!   
[root@English6 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       50264772 4707780  42996992  10% /
tmpfs             502068      72    501996   1% /dev/shm
/dev/sda1         194241   34207    149794  19% /boot
/dev/sda3       20027260  333816  18669444   2% /testdir
/dev/sdc1        2005740    9236   1975460   1% /wang

写一个脚本,完成如下功能:

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

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

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

[root@localhost sh.log]# cat cipan.sh 
#!/bin/bash
#author:DYW
#写一个脚本,完成两个功能(1)列出当前系统识别到的所有磁盘设备(2)如磁盘数量为1,则显示其空间使用信息,否则,则显示最后一个磁盘上的空间使用信息
part=`cat /proc/partitions`
echo -e "$part\t"
echo "==============================="
declare -a par=(`cat /proc/partitions|grep -o "sd[a-z]$"|xargs`)
a=${#par[*]}
if [ $a == 1 ];then
	echo -e "`df -h /dev/${par[0]}*|sort -r|uniq`\t"
else
	echo -e "`df -h /dev/${par[$a-1]}*|sort -r|uniq`\t"
fi

[root@localhost sh.log]# bash cipan.sh 
major minor  #blocks  name

  11        0    7587840 sr0
   8        0  104857600 sda
   8        1     512000 sda1
   8        2  104344576 sda2
   8       16   20971520 sdb
   8       17   10485760 sdb1
   8       48   20971520 sdd
   8       49   10485760 sdd1
   8       32   20971520 sdc
   8       33   10485760 sdc1
 253        0   52428800 dm-0
 253        1    2097152 dm-1
 253        2   49750016 dm-2
   8       64  104857600 sde	
===============================
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        479M     0  479M   0% /dev	

原创文章,作者:DYW,如若转载,请注明出处:http://www.178linux.com/41844

(0)
DYWDYW
上一篇 2016-09-01 18:47
下一篇 2016-09-01 20:03

相关推荐

  • 第三周作业

    1、列出当前系统上所有已经登录的用户的用户名,注意:同一个用户登录多次,则只显示一次即可。 [root@UncleZ ~]# who | cut -d' ' -f1 | uniq -c 2、取出最后登录到当前系统的用户的相关信息。 [roo…

    Linux干货 2016-12-17
  • yum使用及编译安装

    前端程序包管理器     CentOS:yum,dnf     YUM:Yellowdog update Modifier     URL:ftp:// . . .     文件服务器:  …

    Linux干货 2016-08-24
  • 描述LVS的工作原理

    一、LVS结构   LVS由前端的负载均衡器(Load Balancer,LB)和后端的真实服务器(Real Server,RS)群组成。RS间可通过局域网或广域网连接。LVS的这种结构对用户是透明的,用户只能看见一台作为LB的虚拟服务器(Virtual Server),而看不到提供服务的RS群。当用户的请求发往虚拟服务器,LB根据设定的包转发策略和负载均衡…

    Linux干货 2016-08-29
  • Cobbler 自动化部署系统

    本人较懒,做好笔记,预排版,打印成 PDF 了。-_## Cobbler 自动化部署系统.pdf

    Linux干货 2015-08-17
  • VPS服务器的购买使用

           Virtual Host Server(虚拟主机)是一个云计算服务,相比于传统的购买服务器硬件方式搭建服务器,有着价格便宜,个性化定制配置,使用灵活等特点。按需求购买计算资源,只需要几分钟时间就可以在公网配置一个属于自己的服务器。         最著名的云计算服务提供商国外有Amazon,Google,vultr等等,国内有阿里云,腾讯云等等…

    2018-03-26
  • vsftpd 配置文件的一些设置

    ftp:File Transfer protocol 文件传输协议 两个连接: tcp:命令连接 tcp:数据连接 主动模式:服务器端通过20端口主动连接客户端,客户端监听在于服务器端的建立连接的端口+1上,服务器工作在tcp/20 被动模式:客户端使用自己与服务器端建立端口+1上连接客户端的随机端口 防火墙上连接追踪 数据要流失化文本:文件流二进制 c/s…

    Linux干货 2017-09-10