第四周作业

1、描述GPT是什么
      guid partition  table


2、创建一个2G的分区,并格式化为ext4文件系统。要求:
    (1)block大小为2048k,预留空间20%,卷标为MYDATA
	 (2) 挂载至/mydata目录,要求挂载时禁用程序自动运行,且不更新文件的访问时间戳
	(3)可开机自动挂载
	
[root@HFJ /]# mke2fs -t ext4 -L MYDATA -m 20 -b 2048   /dev/sdc1
[root@HFJ /]# mount -O noauto,noatime /dev/sdc1 /mydata
[root@HFJ /]# vim /etc/fstab
[root@HFJ /]# cat  /etc/fstab
....
/dev/sdc1  /mydata                ext4    defaults,noauto,noatime       0 0
       
3、创建一个大小为1.7G的swap分区,并启用。
[root@HFJ /]# fdisk /dev/sdb

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/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xf963ea8d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         218     1751053+  83  Linux
/dev/sdb2             219         436     1751085   83  Linux
/dev/sdb3             437         652     1735020   83  Linux


Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 82
Changed system type of partition 3 to 82 (Linux swap / Solaris)

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 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: 0xf963ea8d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         218     1751053+  83  Linux
/dev/sdb2             219         436     1751085   83  Linux
/dev/sdb3             437         652     1735020   82  Linux swap / Solaris

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@HFJ /]# mkswap /dev/sdb3
Setting up swapspace version 1, size = 1735016 KiB
no label, UUID=1647f3cd-7e99-47d9-af02-68f5332d701f
[root@HFJ /]# free
             total       used       free     shared    buffers     cached
Mem:       1019884     634104     385780          0     105664     369924
-/+ buffers/cache:     158516     861368
Swap:      1023992          0    1023992

[root@HFJ /]# swapon /dev/sdb3

[root@HFJ /]# free
             total       used       free     shared    buffers     cached
Mem:       1019884     635476     384408          0     106020     369924
-/+ buffers/cache:     159532     860352
Swap:      2759004          0    2759004


4、编写脚本计算/etc/passwd文件中第10个用户和第20个用户的id之和。
#!/bin/bash
#计算/etc/passwd文件中第10个用户和第20个用户的uid之和
u10=$(head -10 /etc/passwd|tail -1|cut -d: -f3)
u20=$(head -20 /etc/passwd|tail -1|cut -d: -f3)
sum=$[ $u10 + $u20 ]
echo $sum


5、将当前主机名保存至hostname变量中,主机名如果为空,或者为localhost.localdomainm则设置为www.magedu.com
#!/bin/bash
hostname=$(hostname)
if [ -z "$hostname" -o "$hostname" = "localhost.localdomainm" ];then
    hostname "www.magedu.com"
fi


6、编写脚本,通过命令行参数传入一个用户名,判断id是偶数还是奇数
#!/bin/bash
if [ -z "$1" ];then
    echo "Usage:$0 username"
    exit 1
fi

if  id $1 &>/dev/null;then
    userid=$(grep -w "^$1" /etc/passwd|cut -d: -f3)
else
    echo "$1 is not exist"
    exit 2
fi

if (($userid%2));then
    echo "UID : $userid is  odd   number"
else
    echo "UID : $userid is  even  number"
fi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值