磁盘管理作业

创建一个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

相关推荐

  • 自建CA搭建SSL加密网站

    企业环境中,在安全级别要求较高的公司,经常需要搭建基于SSL加密传输的网站,使用https协议访问web站点,能大大提高网站的安全性。但构建https站点,需要用到证书。内部网站到互联网上申请费用不菲的证书显然不符合经济性。于是,自建内部CA成为我们的首选。 本文以两台服务器,分别扮演CA及Web网站的角色,详细论述自建CA搭建加密网站的过程。  …

    Linux干货 2016-07-29
  • GRUB

    什么是GRUB GRUB(boot loader):grub:GRand Unified Bootloader     有两个版本:grub 0.x:grub legacy经典版;grub 2.x grub legacy:主要运行分三个阶段 stage1(第一阶段):安装在mbr中 stage1.5(第1.5阶段):存…

    Linux干货 2016-09-21
  • bash 数组和变量

    数组可以把多个变量集合起来,不用再一个个的声明变量,也可以调多个单个的变量使用,极大方便了我们的使用,而且Linux bash中的数组还支持同一个数组中同时有数字和字符串。下面让我们来了解一下数组。 一,数组的简介 变量:存储单个元素的内存空间 数组:存储多个元素的连续的内存空间,相当于多个变量的集合。 数组名和索引 索引:编号从0 开始,属于数值索引 注意…

    Linux干货 2016-08-24
  • Linux入门之Centos6 和Centos7的安装

    在安装Centos6 和Centos7 之前,首先VMware需要安装完成,所需镜像CentOS-6.9-x86_64-bin-DVD1和CentOS-7-x86_64-Everything-1611(本次实验所用的版本)准备好,然后开启VMware,进行安装之旅,在安装过程中,Centos6 和Centos7 在前15步的配置是一样的步骤,在16步开启虚拟…

    2017-07-15
  • CentOS 7 忘记root密码的解决之道

    1、启动时任意键暂停启动,会出现如下界面: 2、按e键进入编辑模式,将光标移动linux16开始的行,添加内核参数 rd.break 3、按 ctrl+x 组合键启动 4、查看各分区和文件系统的挂载情况,需要将 / 的模式改为 rw 5、当前系统上的 / 是在光盘上的,切换至挂载目录下的 / ,才可以修改密码 6、在 / 目录下创建autorela…

    Linux干货 2016-09-26
  • Linux磁盘管理

    面对一块硬盘,我们该如何使用它呢?本文从机械硬盘结构,分区,格式化,和挂载四个层次进行介绍。 一、机械硬盘结构 现在服务器使用机械式硬盘是主流,因为其造价低,容量大,和固态硬盘相比读写性能要差很多。机械硬盘主要由以下几个部件构成:转轴Spindle,盘片Platter,机械臂Boom,磁头Head。工作机制是马达带动盘片高速旋转,磁头对盘片进行擦写数据或读取…

    Linux干货 2016-09-01