首页 > 系统服务 > 详细

Linux作业(4)-01

时间:2017-02-03 00:46:19      阅读:339      评论:0      收藏:0      [点我收藏+]

1、创建一个10G分区,并格式为ext4文件系统;

(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl

 [root@wangyafei ~]# fdisk -l

磁盘 /dev/sdb21.5 GB, 21474836480 字节,41943040 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/sda128.8 GB, 128849018880 字节,251658240 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000aaf3f

  
设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    96479231    46141440   8e  Linux LVM

磁盘 /dev/mapper/cl-root42.9 GB, 42945478656 字节,83877888 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/mapper/cl-swap4294 MB, 4294967296 字节,8388608 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节

[root@wangyafei ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。

Device does not contain a recognized partition table
使用磁盘标识符 0xa3aab447 创建新的 DOS 磁盘标签。

命令(输入 m 获取帮助)n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1)1
起始扇区 (2048-41943039,默认为 2048)
将使用默认值 2048
Last
扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039)+10G
分区 1 已设置为 Linux 类型,大小设为 10 GiB

命令(输入 m 获取帮助)w
The partition table has been altered!

Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@wangyafei ~]# fdisk -l

磁盘 /dev/sdb21.5 GB, 21474836480 字节,41943040 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xa3aab447

  
设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

磁盘 /dev/sda128.8 GB, 128849018880 字节,251658240 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000aaf3f

  
设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    96479231    46141440   8e  Linux LVM

磁盘 /dev/mapper/cl-root42.9 GB, 42945478656 字节,83877888 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节


磁盘 /dev/mapper/cl-swap4294 MB, 4294967296 字节,8388608 个扇区
Units =
扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理)512 字节 / 512 字节
I/O
大小(最小/最佳)512 字节 / 512 字节

[root@wangyafei ~]# mkfs -b 2048 -t ext4 -L MYDATA -m 2 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=MYDATA
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
104857 blocks (2.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=273678336
320 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, 1327104,
          2048000, 3981312

Allocating group tables:
完成                           
正在写入inode: 完成                           
Creating journal (32768 blocks):
完成
Writing superblocks and filesystem accounting information:
完成  

[root@wangyafei ~]# tune2fs -o acl /dev/sdb1
tune2fs 1.42.9 (28-Dec-2013)
[root@wangyafei ~]#
 

(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;

[root@wangyafei ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata
 [root@wangyafei ~]# mount | grep sdb1
/dev/sdb1 on /data/mydata type ext4 (rw,noexec,noatime,seclabel,data=ordered)
[root@wangyafei ~]#

 

2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;

[root@wangyafei ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助)n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
分区号 (2-4,默认 2)2
起始扇区 (20973568-41943039,默认为 20973568)
将使用默认值 20973568
Last
扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039)+1G
分区 2 已设置为 Linux 类型,大小设为 1 GiB

命令(输入 m 获取帮助)t
分区号 (1,2,默认 2)2
Hex
代码(输入 L 列出所有代码)82
已将分区“Linux”的类型更改为“Linux swap / Solaris”

命令(输入 m 获取帮助)w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16:
设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
[root@wangyafei ~]# partx -a /dev/sdb
partx: /dev/sdb: error adding partition 1
[root@wangyafei ~]# mkswap /dev/sdb2
正在设置交换空间版本 1,大小 = 1048572 KiB
无标签,UUID=e11cef19-dc78-44d1-8f8b-9993aa6c2f81
[root@wangyafei ~]# free
              total        used        free      shared  buff/cache   available
Mem:        2032156      176716     1631596        9132      223844     1660244
Swap:       4194300           0     4194300
[root@wangyafei ~]# swapon /dev/sdb2
[root@wangyafei ~]# free
              total        used        free      shared  buff/cache   available
Mem:        2032156      177432     1630828        9132      223896     1659508
Swap:       5242872           0     5242872
[root@wangyafei ~]#

 

3、写一个脚本

(1)、获取并列出当前系统上的所有磁盘设备;

(2)、显示每个磁盘设备上每个分区相关的空间使用信息;

[root@wangyafei ~]# touch DiskInfo_test.sh
[root@wangyafei ~]# vim DiskInfo_test.sh
[root@wangyafei ~]# cat DiskInfo_test.sh
#!/bin/bash
#Author:wangyafei
fdisk -l | grep "^/.*"
echo " "
df -lh
 
 [root@wangyafei ~]# bash DiskInfo_test.sh
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    23070719     1048576   82  Linux swap / Solaris
/dev/sda1   *        2048     4196351     2097152   83  Linux
/dev/sda2         4196352    96479231    46141440   8e  Linux LVM

文件系统             容量  已用  可用已用% 挂载点
/dev/mapper/cl-root   40G  4.8G   36G   12% /
devtmpfs             982M     0  982M    0% /dev
tmpfs                993M     0  993M    0% /dev/shm
tmpfs                993M  9.0M  984M    1% /run
tmpfs                993M     0  993M    0% /sys/fs/cgroup
/dev/sda1            2.0G  128M  1.9G    7% /boot
tmpfs                199M     0  199M    0% /run/user/0
/dev/sdb1            9.8G   13M  9.6G    1% /data/mydata
 
 


本文出自 “Argorse” 博客,请务必保留此出处http://wangyafei.blog.51cto.com/4789821/1894536

Linux作业(4)-01

原文:http://wangyafei.blog.51cto.com/4789821/1894536

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!