1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
~]# fdisk /dev/sda p:查看分区列表 n:创建10G的逻辑分区 w:保存并写入磁盘 ~]# partx -a /dev/sda 连续执行两遍 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sda5 ~]# mkdir -p /data/mydata ~]# mount -o noatime, noexec,acl /dev/sda5 /data/mydata
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
~]# fdisk /dev/sda 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): n First cylinder (4175-15665, default 4175): Using default value 4175 Last cylinder, +cylinders or +size{K,M,G} (4175-15665, default 15665): +1G Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): 82 Changed system type of partition 6 to 82 (Linux swap / Solaris) Command (m for help): w ~]# partx -a /dev/sda ~]# partx -a /dev/sda LKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 [root@magelinux ~]# mkswap /dev/sda6 Setting up swapspace version 1, size = 1060252 KiB no label, UUID=d8e98437-9162-460f-a2ed-03ce35c86fc9 ~]# swapon /dev/sda6
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash # fdisk -l | grep -o "^/dev/[[:alnum:]]\{3,\}" df -hl
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID0:需要2块或者2块以上的盘组合
可用空间:N*min(S1,S2,…)
读写性能都会提升,无冗余功能
无容错能力。
一个盘坏,所有数据都会丢失
最求最大容量和速度,安全性最低
RAID1:需要2块或者2块以上的盘组合
可用空间:1*min(S1,S2,…)
硬盘数量越多,其读取速度就越大,但它的写的速度有稍微的降低。
有冗余功能,最大容错:n-1
但无论有多少个盘,其容量仅为一个盘。
最求最大安全性
RAID5:需要最少3块硬盘
可用空间:(N-1)*min(S1,S2,…)
有冗余功能,最大容错:1
最求最大容量,最小预算。
RAID6:需要最少4块硬盘
可用空间:(N-2)*min(S1,S2,…)
有冗余功能,最大容错:2
相比RAID5较安全
RAID10:需要最少4块硬盘。
可用空间:n/2*min(S1,S2,…)
有冗余功能:最大容错:n/2
安全性高,集合了RAID0与RAID1的优点
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@magelinux tmp]# fdisk /dev/sda 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): n First cylinder (4307-15665, default 4307): Using default value 4307 Last cylinder, +cylinders or +size{K,M,G} (4307-15665, default 15665): +10G Command (m for help): n First cylinder (5613-15665, default 5613): Using default value 5613 Last cylinder, +cylinders or +size{K,M,G} (5613-15665, default 15665): +10G Command (m for help): n First cylinder (6919-15665, default 6919): Using default value 6919 Last cylinder, +cylinders or +size{K,M,G} (6919-15665, default 15665): +10G Command (m for help): t Partition number (1-8): 7 Hex code (type L to list codes): fd Changed system type of partition 7 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-8): 8 Hex code (type L to list codes): fd Changed system type of partition 8 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-9): 9 Hex code (type L to list codes): fd Changed system type of partition 9 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! [root@magelinux tmp]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 [root@magelinux tmp]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 BLKPG: Device or resource busy error adding partition 9 root@magelinux dev]# mdadm -C /dev/md0 -a yes -n 2 -l 1 -x 1 -c 128 /dev/sda{7,8,9} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 [root@magelinux dev]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sda9[2](S) sda8[1] sda7[0] 10482176 blocks super 1.2 [2/2] [UU] [>....................] resync = 3.2% (335872/10482176) finish=4.5min speed=37319K/sec
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@magelinux ~]# fdisk /dev/sda 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): n First cylinder (8225-15665, default 8225): Using default value 8225 Last cylinder, +cylinders or +size{K,M,G} (8225-15665, default 15665): +2G Command (m for help): n First cylinder (8487-15665, default 8487): Using default value 8487 Last cylinder, +cylinders or +size{K,M,G} (8487-15665, default 15665): +2G Command (m for help): n First cylinder (8749-15665, default 8749): Using default value 8749 Last cylinder, +cylinders or +size{K,M,G} (8749-15665, default 15665): +2G Command (m for help): t Partition number (1-12): 10 Hex code (type L to list codes): fd Changed system type of partition 10 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-12): 11 Hex code (type L to list codes): fd Changed system type of partition 11 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-12): 12 Hex code (type L to list codes): fd Changed system type of partition 12 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. root@magelinux ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 BLKPG: Device or resource busy error adding partition 9 [root@magelinux ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7 BLKPG: Device or resource busy error adding partition 8 BLKPG: Device or resource busy error adding partition 9 BLKPG: Device or resource busy error adding partition 10 BLKPG: Device or resource busy error adding partition 11 BLKPG: Device or resource busy error adding partition 12 [root@magelinux ~]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{10,11,12} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. [root@magelinux ~]# mkfs.ext4 /dev/md1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 262944 inodes, 1051136 blocks 52556 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1077936128 33 block groups 32768 blocks per group, 32768 fragments per group 7968 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@magelinux ~]# mkdir /backup root@magelinux ~]# blkid /dev/sda2: UUID="95d2365a-6617-4f22-8e37-b09710889454" TYPE="ext4" /dev/sda1: UUID="0272d96d-ef83-40f9-b04f-03f18a9b6761" TYPE="ext4" /dev/sda3: UUID="dd168e27-cbc1-46ae-8064-91ea6580d897" TYPE="swap" /dev/block/8:2: UUID="95d2365a-6617-4f22-8e37-b09710889454" TYPE="ext4" /dev/sda5: LABEL="MYDATA" UUID="ac999e9a-a3a3-4524-85d5-b84674a224b5" TYPE="ext4" /dev/sda6: UUID="d8e98437-9162-460f-a2ed-03ce35c86fc9" TYPE="swap" /dev/sda7: UUID="b0764f82-324e-56a7-01e0-46888c4d22bf" UUID_SUB="be0ba639-5fd8-69fa-3f6f-2c56f535a7c4" LABEL="magelinux:0" TYPE="linux_raid_member" /dev/sda8: UUID="b0764f82-324e-56a7-01e0-46888c4d22bf" UUID_SUB="f61613d7-72fe-6475-b9f0-709bee024cb6" LABEL="magelinux:0" TYPE="linux_raid_member" /dev/sda9: UUID="b0764f82-324e-56a7-01e0-46888c4d22bf" UUID_SUB="3652cfe2-88b6-45b8-f736-78cb3e8eae28" LABEL="magelinux:0" TYPE="linux_raid_member" /dev/sda10: UUID="c82749e9-1f1c-53a1-9e92-47d70dd07a53" UUID_SUB="84f87f9f-ee97-e5cb-b49c-0fe224e39f5a" LABEL="magelinux:1" TYPE="linux_raid_member" /dev/sda11: UUID="c82749e9-1f1c-53a1-9e92-47d70dd07a53" UUID_SUB="ecdcc6df-c4da-a167-650d-2c8046a072a1" LABEL="magelinux:1" TYPE="linux_raid_member" /dev/sda12: UUID="c82749e9-1f1c-53a1-9e92-47d70dd07a53" UUID_SUB="61d34300-af29-9ed0-d116-fa045fba7c0f" LABEL="magelinux:1" TYPE="linux_raid_member" /dev/md1: UUID="da965a4f-afc7-4375-9f47-d69910523cee" TYPE="ext4" [root@magelinux /]# vim /etc/fstab UUID=da965a4f-afc7-4375-9f47-d69910523cee /backup ext4 defaults,acl,nodiratime 0 0
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # declare -i sum=0 if [ $# -lt 1 ];then echo “请您至少给出一条文件路径” && exit 1 fi for i in $@;do if [ -f $i ];then echo "$i 的文件的行数是: `wc -l $i | cut -d" " -f1` " let sum++ else echo "$i 不是正确的文件路径" fi done echo "本次统计的文件数为: $sum"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash # declare -i name=0 if [ $# -lt 2 ] ;then echo "Please give at least two need to create a username" && exit 5 fi for i in $@;do id $i &> /dev/null if [ $? -eq 0 ];then echo "This $i exists" else useradd $i && echo "$i" | passwd --stdin $i let name++ fi done echo "Create user number:$name"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i sum=0 for i in {1..20};do useradd visitor$i && echo "visitor$i UID is: `id -u visitor$i`" name=$(id -u visitor$i) let sum+=$name done echo "the user UID sum is : $sum"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # declare -i a=0 declare -i b=0 for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do fu=`grep "^#" $i | wc -l` ng=`grep "^[[:space:]]\+$" $i | wc -l` let a+=$fu let b+=$ng done echo "The total number of # for the beginning :$a" echo "Total number of blank lines:$b"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # declare -i sum=0 user=$(grep "/bin/bash$" /etc/passwd) for i in $user;do uid=`echo $i | cut -d: -f3` user=`echo $i | cut -d: -f1` echo "$user UID is $uid" let sum+=$uid done echo "默认shell为bash的用户UID之和为:$sum"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash declare -i user=0 name=`cut -d: -f1 /etc/passwd` for i in $name;do group=`id $i|cut -d" " -f3|awk -F"," '{print $2}'` if [ -n "$group" ];then echo "$i 拥有附加组" let user++ fi done echo "拥有附加组的用户总数是: $user"
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@magelinux ~]# fdisk /dev/sda Command (m for help): n First cylinder (2869-15665, default 2869): Using default value 2869 Last cylinder, +cylinders or +size{K,M,G} (2869-15665, default 15665): +10G Command (m for help): n First cylinder (4175-15665, default 4175): Using default value 4175 Last cylinder, +cylinders or +size{K,M,G} (4175-15665, default 15665): +10G Command (m for help): t Partition number (1-6): 5 Hex code (type L to list codes): 8e Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) Command (m for help): p Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 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: 0x000d5ced Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2614 20480000 83 Linux /dev/sda3 2614 2869 2048000 82 Linux swap / Solaris /dev/sda4 2869 15665 102788088+ 5 Extended /dev/sda5 2869 4174 10486599+ 8e Linux LVM /dev/sda6 4175 5480 10490413+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. 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) Syncing disks. [root@magelinux ~]# partx -a /dev/sda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 4 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 [root@magelinux ~]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created [root@magelinux ~]# pvcreate /dev/sda6 Physical volume "/dev/sda6" successfully created [root@magelinux ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda5 lvm2 --- 10.00g 10.00g /dev/sda6 lvm2 --- 10.00g 10.00g [root@magelinux ~]# vgcreate -s 8M myvg /dev/sda{5,6} Volume group "myvg" successfully created [root@magelinux ~]# vgdisplay --- Volume group --- VG Name myvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 19.99 GiB PE Size 8.00 MiB Total PE 2559 Alloc PE / Size 0 / 0 Free PE / Size 2559 / 19.99 GiB VG UUID NnCyy1-kevE-pul3-aGpH-GySi-GOQT-S4DABZ [root@magelinux ~]# lvcreate -L 5G -n mylv myvg Logical volume "mylv" created. [root@magelinux ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mylv LV Name mylv VG Name myvg LV UUID 5sVS3Y-xers-mlnv-c32W-pOnb-shBo-xLCxmD LV Write Access read/write LV Creation host, time magelinux, 2016-08-26 23:31:39 +0800 LV Status available # open 0 LV Size 5.00 GiB Current LE 640 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@magelinux ~]# mkfs.ext4 /dev/myvg/mylv mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@magelinux ~]# blkid /dev/sda2: UUID="95d2365a-6617-4f22-8e37-b09710889454" TYPE="ext4" /dev/sda1: UUID="0272d96d-ef83-40f9-b04f-03f18a9b6761" TYPE="ext4" /dev/sda3: UUID="dd168e27-cbc1-46ae-8064-91ea6580d897" TYPE="swap" /dev/block/8:2: UUID="95d2365a-6617-4f22-8e37-b09710889454" TYPE="ext4" /dev/sda5: UUID="hXii7i-t1yU-k5ZA-3C6q-67iZ-2Rz0-JkZF2e" TYPE="LVM2_member" /dev/sda6: UUID="CLhY2q-9K77-she6-G7Mr-w4nw-9ZLv-J7ccsH" TYPE="LVM2_member" /dev/mapper/myvg-mylv: UUID="1e6bda45-524f-403e-9f52-5fa0d0c4f56b" TYPE="ext4" 编辑/etc/fstab,在文末行添加此行内容 UUID=1e6bda45-524f-403e-9f52-5fa0d0c4f56b /users ext4 defaults,acl 0 0
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@magelinux ~]# useradd -d /users/magedu magedu [root@magelinux ~]# su - magedu [magedu@magelinux ~]$ cp -ar /etc/rc.d/* ~
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@magelinux ~]# lvextend -L +4G /dev/myvg/mylv Size of logical volume myvg/mylv changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv successfully resized [root@magelinux ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mylv LV Name mylv VG Name myvg LV UUID 5sVS3Y-xers-mlnv-c32W-pOnb-shBo-xLCxmD LV Write Access read/write LV Creation host, time magelinux, 2016-08-26 23:31:39 +0800 LV Status available # open 0 LV Size 9.00 GiB Current LE 1152 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@magelinux ~]# resize2fs /dev/myvg/mylv resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/myvg/mylv to 2359296 (4k) blocks. The filesystem on /dev/myvg/mylv is now 2359296 blocks long.
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@magelinux ~]# umount /dev/myvg/mylv [root@magelinux ~]# e2fsck -f /dev/myvg/mylv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/myvg/mylv: 11/589824 files (0.0% non-contiguous), 72671/2359296 blocks [root@magelinux ~]# resize2fs /dev/myvg/mylv [root@magelinux ~]# lvreduce -L 7G /dev/myvg/mylv WARNING: Reducing active logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv? [y/n]: y Size of logical volume myvg/mylv changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv successfully resized [root@magelinux ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mylv LV Name mylv VG Name myvg LV UUID 5sVS3Y-xers-mlnv-c32W-pOnb-shBo-xLCxmD LV Write Access read/write LV Creation host, time magelinux, 2016-08-26 23:31:39 +0800 LV Status available # open 0 LV Size 7.00 GiB Current LE 896 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@magelinux ~]# mount /dev/myvg/mylv /users
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@magelinux users]# lvcreate -L 1G -n snapmylv -p r -s /dev/myvg/mylv [root@magelinux users]# cd /dev/myvg/ [root@magelinux myvg]# ls mylv snapmylv
原创文章,作者:微,如若转载,请注明出处:http://www.178linux.com/41741
评论列表(1条)
作业完成的非常的棒,知识点总结到位,作业给出详细的操作过程,加油!