1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
fdisk /dev/sdb欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+10G分区 2 已设置为 Linux 类型,大小设为 10 GiB命令(输入 m 获取帮助):wThe partition table has been altered!# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sdb2# mkdir -pv /data/mydata# mount -t ext4 -o defaults,noexec,nodiratime,acl /dev/sdb2 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
# fdisk /dev/sdb命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+1G分区 2 已设置为 Linux 类型,大小设为 1 GiB命令(输入 m 获取帮助):t分区号 (1,2,默认 2):Hex 代码(输入 L 列出所有代码):82已将分区“Linux”的类型更改为“Linux swap / Solaris”命令(输入 m 获取帮助):wThe partition table has been altered!# partx -a /dev/sdb# cat /proc/partitions major minor #blocks name 8 0 41943040 sda 8 1 2048 sda1 8 2 1048576 sda2 8 3 31461376 sda3 8 16 20971520 sdb 8 17 10485760 sdb1 8 18 1048576 sdb2 11 0 1048575 sr0 253 0 10485760 dm-0 253 1 1048576 dm-1 253 2 5242880 dm-2# mkswap /dev/sdb2正在设置交换空间版本 1,大小 = 1048572 KiB无标签,UUID=13400b7b-46b9-4acf-8314-b52055a3a71f[root@localhost ~]# swapon -a /deb/sdb2# swapon -s文件名 类型 大小 已用 权限/dev/dm-1 partition 1048572 0 -1/dev/sdb2 partition 1048572 0 -2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bashecho -e "All of disk:\n `fdisk -l | grep '磁盘' | awk -F , '{print $1}'`"echo -e "The Disk partation information:\n `df -h`"
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0: 读、写性能最好; 可用空间:N*min(S1,S2,...) 无容错能力 最少磁盘数:2, 2+RAID-1: 读性能提升、写性能略有下降; 可用空间:1*min(S1,S2,...) 有冗余能力 最少磁盘数:2, 2+,必须为偶数块磁盘RAID-5: 读性能一样,写惩罚为4 可用空间:(N-1)*min(S1,S2,...) 有容错能力:1块磁盘 最少磁盘数:3, 3+,奇数块磁盘RAID-10: 读性能一样,写惩罚为2 可用空间:N*min(S1,S2,...)/2 有容错能力:每组镜像最多只能坏一块; 最少磁盘数:4, 4+,必须为偶数块磁盘
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
# fdisk /dev/sdaWARNING: 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): nFirst cylinder (4307-15665, default 4307): Using default value 4307Last cylinder, +cylinders or +size{K,M,G} (4307-15665, default 15665): +10GCommand (m for help): nFirst cylinder (5613-15665, default 5613): Using default value 5613Last cylinder, +cylinders or +size{K,M,G} (5613-15665, default 15665): +10GCommand (m for help): nFirst cylinder (6919-15665, default 6919): Using default value 6919Last cylinder, +cylinders or +size{K,M,G} (6919-15665, default 15665): +10GCommand (m for help): tPartition number (1-8): 7Hex code (type L to list codes): fdChanged system type of partition 7 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-8): 8Hex code (type L to list codes): fdChanged system type of partition 8 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-9): 9Hex code (type L to list codes): fdChanged system type of partition 9 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md0 -a yes -n 2 -l 1 -x 1 -c 128 /dev/sda{7,8,9}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
]# fdisk /dev/sdaWARNING: 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): nFirst cylinder (8225-15665, default 8225): Using default value 8225Last cylinder, +cylinders or +size{K,M,G} (8225-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8487-15665, default 8487): Using default value 8487Last cylinder, +cylinders or +size{K,M,G} (8487-15665, default 15665): +2GCommand (m for help): nFirst cylinder (8749-15665, default 8749): Using default value 8749Last cylinder, +cylinders or +size{K,M,G} (8749-15665, default 15665): +2GCommand (m for help): tPartition number (1-12): 10Hex code (type L to list codes): fd Changed system type of partition 10 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 11Hex code (type L to list codes): fdChanged system type of partition 11 to fd (Linux raid autodetect)Command (m for help): tPartition number (1-12): 12Hex code (type L to list codes): fdChanged system type of partition 12 to fd (Linux raid autodetect)Command (m for help): wThe partition table has been altered!]# partx -a /dev/sda]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{10,11,12}]# mkfs.ext4 /dev/md1
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bashif [ $# -le 1 ];then echo "more than 2 arg!" exitelse for i in $*;do echo "$i total lines: `wc -l $i | cut -d" " -f1`" donefiecho "Total args: $#"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bashif [ $# -le 2 ];then echo "more than 3 arg!" exitelse for i in $*;do id $i &> /dev/null if [ $? -eq 0 ];then echo "$i exists" else useradd $i && echo "$i" | passwd --stdin $i let x++ fi donefiecho "Total create users: $x"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bashfor i in {1..20};do useradd visitor$i let x+= `id -u visitor$i`doneecho "sum of visitor user id: $x"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bashfor i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do let sum1+= $(`grep "^#" $i | wc -l`) let sum1+= $(`grep "^$" $i | wc -l`)doneecho "total #begin lines:$sum1"echo "total spacelines:$sum2"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bashfor i in `grep "/bin/bash$" /etc/passwd | cut -d: -f1`;do echo "user:$i,uid:`id -u $i`" let x+=`id -u $i`doneecho "sum of UID:$x`"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bashfor i in `cut -d: -f1 /etc/passwd`;do id $i | grep "," &> /dev/null if [ $? -eq 0 ];then echo "user: $i" && let x++ fidoneecho "sum: $x"
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@localhost ~]# pvcreate /dev/sda{3,5}[root@localhost ~]# vgcreate -s 8M myvg /dev/sda{3,5}[root@localhost ~]# lvcreate -L 5G -n mylv1 myvg[root@localhost ~]# mkfs.ext4 /dev/myvg/mylv1[root@localhost ~]# mkdir /users[root@localhost ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@localhost ~]# useradd -d /users/magedu magedu[root@localhost ~]# su - magedu[magedu@localhost ~]$ cp /etc/rc.sysinit .[magedu@localhost ~]$ cp /tmp/* .
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@localhost ~]# lvresize +9G /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@localhost ~]# umount /dev/myvg/mylv1[root@localhost ~]# e2fsck -f /dev/myvg/mylv1[root@localhost ~]# resize2fs /dev/myvg/mylv1 7G[root@localhost ~]# lvreduce -L 7G /dev/myvg/mylv1[root@localhost ~]# mount -a
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@localhost ~]# lvcreate -L 2G -s -p r -n mysnap1 /dev/myvg/mylv1
原创文章,作者:N21_smile,如若转载,请注明出处:http://www.178linux.com/47087
评论列表(1条)
条理清晰一些,