1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
这里我在设备/dev/sdb上操作为例: (1)创建一个10G分区: [root@localhost ~]# fdisk -u -c /dev/sdb Command (m for help): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First sector (4200448-1112584959, default 4200448): Using default value 4200448 Last sector, +sectors or +size{K,M,G} (4200448-1112584959, default 12584959): +10G Command (m for help): w [root@localhost ~]# partx -a /dev/sdb (2)文件系统格式化: [root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sdb1 (3)编辑/etc/fstab LABEL='MYDATA' /data/mydata ext4 nodiratime,noexec,acl 0 0
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@localhost ~]# fdisk -u -c /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First sector (2099200-16777215, default 2099200): Using default value 2099200 Last sector, +sectors or +size{K,M,G} (2099200-16777215, default 16777215): +1G Command (m for help): p Disk /dev/sdb: 8589 MB, 8589934592 bytes 171 heads, 40 sectors/track, 2452 cylinders, total 16777216 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xdbb0c7a6 Device Boot Start End Blocks Id System /dev/sdb1 2048 2099199 1048576 83 Linux /dev/sdb2 2099200 4196351 1048576 83 Linux Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 8589 MB, 8589934592 bytes 171 heads, 40 sectors/track, 2452 cylinders, total 16777216 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xdbb0c7a6 Device Boot Start End Blocks Id System /dev/sdb1 2048 2099199 1048576 83 Linux /dev/sdb2 2099200 4196351 1048576 82 Linux swap / Solaris Command (m for help): w [root@localhost ~]#partx -a /dev/sdb [root@localhost ~]#mkswap /dev/sdb2 [root@localhost ~]#swapon -a
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash # fdisk -l /dev/[hs]d[a-z]
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0: 读、写性能提升; 可用空间:N*min(S1,S2,...) 无容错能力 最少磁盘数:2, 2+ RAID-1: 读性能提升、写性能略有下降; 可用空间:1*min(S1,S2,...) 有冗余能力 最少磁盘数:2, 2+ RAID-4: 1101, 0110, 1011 RAID-5: 读、写性能提升 可用空间:(N-1)*min(S1,S2,...) 有容错能力:1块磁盘 最少磁盘数:3, 3+ RAID-6: 读、写性能提升 可用空间:(N-2)*min(S1,S2,...) 有容错能力:2块磁盘 最少磁盘数:4, 4+ 混合类型 RAID-10: 读、写性能提升 可用空间:N*min(S1,S2,...)/2 有容错能力:每组镜像最多只能坏一块; 最少磁盘数:4, 4+ RAID-01: RAID-50、RAID7 JBOD:Just a Bunch Of Disks 功能:将多块磁盘的空间合并一个大的连续空间使用; 可用空间:sum(S1,S2,...)
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
(1)创建分区 fdisk -u -c /dev/sdb Command (m for help):n Command action l logical (5 or over) p primary partition (1-4) l First sector (4206592-6293503, default 4206592): Using default value 4206592 Last sector, +sectors or +size{K,M,G} (4206592-6293503, default 6293503): +10G 创建3个大小为10G的分区,为/dev/sdb{8,9,10}, (2)内核重读分区表 partx -a 内核重读分区表 (3)以mdadm创建RAID mdadm -C /dev/md0 -n 2 -c 128k -l 1 -x 1 -a yes /dev/sdb{8,9,10}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
(1)创建分区 fdisk -u -c /dev/sdb Command (m for help):n Command action l logical (5 or over) p primary partition (1-4) l First sector (4206592-6293503, default 4206592): Using default value 4206592 Last sector, +sectors or +size{K,M,G} (4206592-6293503, default 6293503): +1G 创建5个大小为1G的分区,为/dev/sdb{8,9,10,11,12}, (2)内核重读分区表 partx -a 内核重读分区表 (3)以mdadm创建RAID mdadm -C /dev/md1 -n 5 -c 256k -l 5 -a yes /dev/sdb{8,9,10,11,12} (4)格式化文件系统 mkfs -t ext4 /dev/md1 (5)编辑配置文件 vim /etc/fstab 写入: /dev/md1 /backup ext4 auto,nodiratime,acl 0 0
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # for i in {1..$#};do linecount=$(wc -l $i|cut -d"" f1) echo "$i has $linecount lines " done echo "we count lenes of $i file !"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash # for i in {2..$#};do useradd $i echo "$i" |passwd --stdin $i done echo "there are $i user in all"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # if [ ! $UID -eq 0 ]; then echo "Only root." exit 1 fi for i in {1..20}; do if id visitor$i &> /dev/null; then echo "visitor$i exists." else useradd visitor$i if [ $? -eq 0 ]; then echo "visitor$i" | passwd --stdin visitor$i &> /dev/null echo "Add visitor$i finished." fi fi done
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # function count{ grep "^#" $1|wc -l grep "^[[:space:]]*$" $1|wc -l } count /etc/rc.d/rc.sysinit count /etc/rc.d/init.d/funcions count /etc/fstab
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # grep "\<bash$" /etc/passwd |cut -d: -f1,3 for i in $(grep "\<bash$" /etc/passwd |cut -d: -f3);do let sum+=$i done echo "$sum"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # grep "[^:]$" /etc/group |cut -d: -f4 |awk -F, '{i=1;while(i<=NF){printf "%s\n",$i;i++}} '|sort |uniq grep "[^:]$" /etc/group |cut -d: -f4 |awk -F, '{i=1;while(i<=NF){printf "%s\n",$i;i++}} '|sort |uniq|wc -l
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
(1)新建2个大小为10G的分区,设置systemID为8e [root@localhost ~]#fdisk -u -c /dev/sda Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 4 First sector (4196352-11116777215, default 4196352): Using default value 4196352 Last sector, +sectors or +size{K,M,G} (4196352-11116777215, default 11116777215): +30G Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First sector (4198400-67110882, default 4198400): Using default value 4198400 Last sector, +sectors or +size{K,M,G} (4196352-67110882, default 67110882): +10G 再分一个10G的分区,我们用来建立逻辑卷组的两个分区分别为/dev/sdb5,/dev/sdb6 Command (m for help): t Partition number (1-5): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) 同样的方法我把/dev/sdb6的systemID改为8e,然后保存退出: Command (m for help): w 内核重读分区表: [root@localhost ~]#partx -a /dev/sdb (2)新建pv [root@localhost ~]#pvcreate /dev/sdb{5,6} (3)创建VG [root@localhost ~]#vgcreate -s 8M myvg /dev/sdb{5,6} (4)新建LV [root@localhost ~]#lvcreate -L 5G -n mylv1 myvg (5)格式化 [root@localhost ~]#mkfs -t ext4 /dev/myvg/mylv1 (6)设置自动挂载 [root@localhost ~]#mkdir /users 编辑/etc/fstab,添加一行 /dev/myvg/mylv1 /users ext4 defaults,acl 0 0
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@localhost ~]#mkdir -p /users/magedu [root@localhost ~]#useradd -d /users/magedu magedu [root@localhost ~]#chown magedu:magedu /users/magedu [root@localhost ~]#su - magedu -bash-4.1$ cp /etc/bashrc /users/magedu/.bashrc -bash-4.1$ cp /etc/profile /users/magedu/.bash_profile
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@localhost ~]#lvextend -L +4G /dev/myvg/mylv1 [root@localhost ~]#resize2fs /dev/myvg/myylv1
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 -2G /dev/myvg/mylv1 [root@localhost ~]#mount /dev/myvg/mylv1 /users
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@localhost ~]#pvcreate -L 2G -s -n mylv1_ss /dev/myvg/mylv1
原创文章,作者:N20-重庆-雪寒,如若转载,请注明出处:http://www.178linux.com/18702
评论列表(1条)
写的很好,排版也很棒,7 8不对,在仔细看看,加油