第七週作業
1、創建一個10G分區,並格式爲ext4文件系統;
[root@STCO6 /]# 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-2610, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 /]# 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: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x0e54b55e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux Command (m for help): q
(1) 要求其block大小爲2048, 預留空間百分比爲2, 卷標爲MYDATA, 默認掛載屬性包含acl;
[root@STCO6 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 657408 inodes, 5245206 blocks 104904 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=543162368 321 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
[root@STCO6 ~]# mkdir -p /data/mydata [root@STCO6 ~]# mount -t ext4 -o noexec,noatime,acl /dev/sdb1 /data/mydata/
2、創建一個大小爲1G的swap分區,並創建好文件系統,並啓用之;
[root@STCO6 ~]# 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): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-2610, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +1G 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): 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@STCO6 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1060284 KiB no label, UUID=ae1b57f3-472d-4ae4-8620-2fb40c5916be [root@STCO6 ~]# swapon /dev/sdb2 [root@STCO6 ~]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x000b04eb 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 2611 20458496 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x0e54b55e Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 83 Linux /dev/sdb2 1307 1438 1060290 82 Linux swap / Solaris Disk /dev/mapper/vg_stco6-lv_root: 18.8 GB, 18798870528 bytes 255 heads, 63 sectors/track, 2285 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: 0x00000000 Disk /dev/mapper/vg_stco6-lv_swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 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: 0x00000000
3、寫一個腳本
(1)、獲取並列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
[root@STCO6 ~]# cat /tmp/disk.sh #!/bin/bash # disk=$(fdisk -l|egrep -o "/dev/sd.?\>") for i in $disk;do echo $i df -h|awk '/'${i//\//\\/}'/{print $0}' done [root@STCO6 ~]# chmod u+x /tmp/disk.sh [root@STCO6 ~]# bash -n /tmp/disk.sh [root@STCO6 ~]# /tmp/disk.sh /dev/sda /dev/sda1 477M 40M 412M 9% /boot /dev/sdb
4、總結RAID的各個級別及其組合方式和性能的不同;
5、創建一個大小爲10G的RAID1,要求有一個空閒盤,而且CHUNK大小爲128k;
[root@STCO6 ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xbb65f33a. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-4568, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-4568, default 4568): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-4568, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-4568, default 4568): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (2613-4568, default 2613): Using default value 2613 Last cylinder, +cylinders or +size{K,M,G} (2613-4568, default 4568): +10G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): fd Changed system type of partition 1 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): fd Changed system type of partition 2 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# mdadm -C /dev/md0 -a yes -n 2 -x 1 -l 1 -c 128 /dev/sdc{1,2,3} 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 Continue creating array? y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@STCO6 ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sdc3[2](S) sdc2[1] sdc1[0] 10482176 blocks super 1.2 [2/2] [UU] unused devices: <none>
6、創建一個大小爲4G的RAID5設備,chunk大小爲256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
[root@STCO6 ~]# fdisk /dev/sdd Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x5466fe3b. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-1958, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1958, default 1958): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (524-1958, default 524): Using default value 524 Last cylinder, +cylinders or +size{K,M,G} (524-1958, default 1958): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (1047-1958, default 1047): Using default value 1047 Last cylinder, +cylinders or +size{K,M,G} (1047-1958, default 1958): +4G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): fd Changed system type of partition 1 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): fd Changed system type of partition 2 to fd (Linux raid autodetect) Command (m for help): t Partition number (1-4): 3 Hex code (type L to list codes): fd Changed system type of partition 3 to fd (Linux raid autodetect) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sda{1,2,3} mdadm: cannot open /dev/sda1: Device or resource busy [root@STCO6 ~]# mdadm -C /dev/md1 -a yes -n 3 -c 256K -l 5 /dev/sdd{1,2,3} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. [root@STCO6 ~]# mke2fs -t 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 525200 inodes, 2098432 blocks 104921 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2151677952 65 block groups 32768 blocks per group, 32768 fragments per group 8080 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 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@STCO6 ~]# mkdir /backup [root@STCO6 ~]# echo "/dev/md1 /backup ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
7、寫一個腳本
(1) 接受一個以上文件路徑作爲參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共爲幾個文件統計了其行數;
[root@STCO6 tmp]# cat line.sh #!/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" [root@STCO6 tmp]# bash -n line.sh [root@STCO6 tmp]# chmod u+x line.sh [root@STCO6 tmp]# ./line.sh testScript1 testScript2 testScript3 testScript4 testScript5 testScript6 testScript7 testScript1 的文件的行數是: 3 testScript2 的文件的行數是: 5 testScript3 的文件的行數是: 3 testScript4 的文件的行數是: 11 testScript5 的文件的行數是: 9 testScript6 的文件的行數是: 9 testScript7 錯誤的文件路徑 本次統計的文件數爲: 6
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
[root@STCO6 tmp]# cat adduser.sh #!/bin/bash # declare -i name=0 if [ $# -lt 2 ] ;then echo "請輸入至少兩個待創建的用戶名" && exit 1 fi for i in $@;do id $i &> /dev/null if [ $? -eq 0 ];then echo "用戶 $i 已存在" else useradd $i && echo "$i" | passwd --stdin $i let name++ fi done echo "創建的用戶數量:$name" [root@STCO6 tmp]# chmod +x adduser.sh [root@STCO6 tmp]# bash -n adduser.sh [root@STCO6 tmp]# ./adduser.sh TU1 TU2 TU3 TU4 TU5 TU6 Changing password for user TU1. passwd: all authentication tokens updated successfully. Changing password for user TU2. passwd: all authentication tokens updated successfully. Changing password for user TU3. passwd: all authentication tokens updated successfully. Changing password for user TU4. passwd: all authentication tokens updated successfully. Changing password for user TU5. passwd: all authentication tokens updated successfully. Changing password for user TU6. passwd: all authentication tokens updated successfully. 創建的用戶數量:6
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
[root@STCO6 tmp]# cat Createuser.sh #!/bin/bash # declare -i sum=0 for i in {1..20};do useradd visitor$i && echo "visitor$i UID 是: `id -u visitor$i`" let sum+=$(id -u visitor$i) done echo "用戶 UID 之和 : $sum" [root@STCO6 tmp]# chmod u+x Createuser.sh [root@STCO6 tmp]# bash -n Createuser.sh [root@STCO6 tmp]# ./Createuser.sh visitor1 UID 是: 3031 visitor2 UID 是: 3032 visitor3 UID 是: 3033 visitor4 UID 是: 3034 visitor5 UID 是: 3035 visitor6 UID 是: 3036 visitor7 UID 是: 3037 visitor8 UID 是: 3038 visitor9 UID 是: 3039 visitor10 UID 是: 3040 visitor11 UID 是: 3041 visitor12 UID 是: 3042 visitor13 UID 是: 3043 visitor14 UID 是: 3044 visitor15 UID 是: 3045 visitor16 UID 是: 3046 visitor17 UID 是: 3047 visitor18 UID 是: 3048 visitor19 UID 是: 3049 visitor20 UID 是: 3050 用戶 UID 之和 : 60810
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
[root@STCO6 tmp]# cat line2.sh #!/bin/bash # sum=0 files=(/etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab) for i in ${files[@]};do echo $i "#開頭的行數: $(grep '^#' $1 | wc -l)" let sum+=`cat $i|grep '^$'|wc -l` done echo "空白的總行數: $sum" [root@STCO6 tmp]# chmod +x line2.sh [root@STCO6 tmp]# bash -n line2.sh [root@STCO6 tmp]# ./line2.sh /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab /etc/rc.d/rc.sysinit #開頭的行數: 44 /etc/rc.d/init.d/functions #開頭的行數: 44 /etc/fstab #開頭的行數: 44 空白的總行數: 206
11、寫一個腳本,顯示當前系統上所有默認shell爲bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
[root@STCO6 tmp]# cat bashuser.sh #!/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" [root@STCO6 tmp]# chmod +x line2.sh [root@STCO6 tmp]# chmod +x bashuser.sh [root@STCO6 tmp]# bash -n bashuser.sh [root@STCO6 tmp]# ./bashuser.sh root UID is 0 suyi UID is 500 testuser UID is 501 testuser1 UID is 502 testuser2 UID is 503 testuser3 UID is 504 testuser4 UID is 505 testuser5 UID is 506 mageia UID is 1100 openstack UID is 3003 hadoop UID is 2500 bash UID is 3004 testbash UID is 3005 basher UID is 3006 fedora UID is 3008 user1 UID is 3009 user10 UID is 3010 user11 UID is 3011 user12 UID is 3012 user13 UID is 3013 user14 UID is 3014 user15 UID is 3015 user16 UID is 3016 user17 UID is 3017 user18 UID is 3018 user19 UID is 3019 user20 UID is 3020 user21 UID is 3021 TU1 UID is 3022 TU2 UID is 3023 TU3 UID is 3024 TU4 UID is 3025 TU5 UID is 3026 TU6 UID is 3027 TU7 UID is 3028 5 UID is 3029 TU8 UID is 3030 visitor1 UID is 3031 visitor2 UID is 3032 visitor3 UID is 3033 visitor4 UID is 3034 visitor5 UID is 3035 visitor6 UID is 3036 visitor7 UID is 3037 visitor8 UID is 3038 visitor9 UID is 3039 visitor10 UID is 3040 visitor11 UID is 3041 visitor12 UID is 3042 visitor13 UID is 3043 visitor14 UID is 3044 visitor15 UID is 3045 visitor16 UID is 3046 visitor17 UID is 3047 visitor18 UID is 3048 visitor19 UID is 3049 visitor20 UID is 3050 默認shell爲bash的用戶UID之和爲:149386
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;並說明共有多少個此類用戶;
[root@STCO6 tmp]# cat Groupuser.sh #!/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" [root@STCO6 tmp]# chmod +x Groupuser.sh [root@STCO6 tmp]# bash -n Groupuser.sh [root@STCO6 tmp]# ./Groupuser.sh bin 擁有附加組 daemon 擁有附加組 adm 擁有附加組 postfix 擁有附加組 slackware 擁有附加組 openstack 擁有附加組 擁有附加組的用戶總數是: 6
13、創建一個由至少兩個物理卷組成的大小爲20G的卷組;要求,PE大小爲8M;而在卷組中創建一個大小爲5G的邏輯卷mylv1,格式化爲ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@STCO6 ~]# fdisk /dev/sdc Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x5924ad3c. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) 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 Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-5221, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-5221, default 5221): +10G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-5221, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-5221, default 5221): +10G Command (m for help): t Partition number (1-4): 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM) Command (m for help): p Disk /dev/sdc: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x5924ad3c Device Boot Start End Blocks Id System /dev/sdc1 1 1306 10490413+ 8e Linux LVM /dev/sdc2 1307 2612 10490445 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@STCO6 ~]# partx -a /dev/sdc BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@STCO6 ~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created [root@STCO6 ~]# pvcreate /dev/sdc2 Physical volume "/dev/sdc2" successfully created [root@STCO6 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vg_stco6 lvm2 a--u 19.51g 0 /dev/sdc1 lvm2 ---- 10.00g 10.00g /dev/sdc2 lvm2 ---- 10.00g 10.00g [root@STCO6 ~]# vgcreate -s 8M testvg /dev/sdc{1,2} Volume group "testvg" successfully created [root@STCO6 ~]# vgdisplay --- Volume group --- VG Name testvg 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 20.00 GiB PE Size 8.00 MiB Total PE 2560 Alloc PE / Size 0 / 0 Free PE / Size 2560 / 20.00 GiB VG UUID yW39bc-tG1d-WxfL-i5P9-U1HO-Ilem-xG1YtM --- Volume group --- VG Name vg_stco6 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 19.51 GiB PE Size 4.00 MiB Total PE 4994 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 0 / 0 VG UUID vTi8LR-3pAa-zALe-D2rO-AWdO-fsf4-MVP3O1 [root@STCO6 ~]# lvcreate -L 5G -n mylv1 testvg Logical volume "mylv1" created. [root@STCO6 ~]# mkfs.ext4 /dev/testvg/mylv1 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 36 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@STCO6 ~]# echo "/dev/testvg/mylv1 /users ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
14、新建用戶magedu;其家目錄爲/users/magedu,而後su切換至此用戶,複製多個文件至家目錄;
[root@STCO6 ~]# useradd -d /users/magedu magedu [root@STCO6 ~]# su - magedu [magedu@STCO6 ~]$ cp /etc/fstab /etc/issue ./
15、擴展mylv1至9G,確保擴展完成後原有數據完全可用;
[root@STCO6 magedu]# lvextend -L +4G /dev/testvg/mylv1 Size of logical volume testvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. [root@STCO6 magedu]# lvdisplay --- Logical volume --- LV Path /dev/testvg/mylv1 LV Name mylv1 VG Name testvg LV UUID TU9EXH-JTTx-s4Sp-5Z3C-ipCQ-Rsbi-yVBIj3 LV Write Access read/write LV Creation host, time STCO6, 2016-09-17 15:35:26 +0800 LV Status available # open 1 LV Size 9.00 GiB Current LE 1152 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_stco6/lv_root LV Name lv_root VG Name vg_stco6 LV UUID mm31j6-AvWw-agrn-RmkG-TXbb-fAlP-ZcQzDD LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:13 +0800 LV Status available # open 1 LV Size 17.51 GiB Current LE 4482 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_stco6/lv_swap LV Name lv_swap VG Name vg_stco6 LV UUID welimE-WYab-IkFQ-Y43Q-5RBQ-c6Ju-yIeNPE LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:19 +0800 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
16、縮減mylv1至7G,確保縮減完成後原有數據完全可用;
[root@STCO6 ~]# umount /dev/testvg/mylv1 [root@STCO6 ~]# e2fsck -f /dev/testvg/mylv1 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/testvg/mylv1: 23/327680 files (0.0% non-contiguous), 55914/1310720 blocks [root@STCO6 ~]# resize2fs /dev/testvg/mylv1 resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/testvg/mylv1 to 2359296 (4k) blocks. The filesystem on /dev/testvg/mylv1 is now 2359296 blocks long. [root@STCO6 ~]# lvreduce -L 7G /dev/testvg/mylv1 WARNING: Reducing active logical volume to 7.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce testvg/mylv1? [y/n]: y Size of logical volume testvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized. [root@STCO6 ~]# lvdisplay --- Logical volume --- LV Path /dev/testvg/mylv1 LV Name mylv1 VG Name testvg LV UUID TU9EXH-JTTx-s4Sp-5Z3C-ipCQ-Rsbi-yVBIj3 LV Write Access read/write LV Creation host, time STCO6, 2016-09-17 15:35:26 +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:2 --- Logical volume --- LV Path /dev/vg_stco6/lv_root LV Name lv_root VG Name vg_stco6 LV UUID mm31j6-AvWw-agrn-RmkG-TXbb-fAlP-ZcQzDD LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:13 +0800 LV Status available # open 1 LV Size 17.51 GiB Current LE 4482 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_stco6/lv_swap LV Name lv_swap VG Name vg_stco6 LV UUID welimE-WYab-IkFQ-Y43Q-5RBQ-c6Ju-yIeNPE LV Write Access read/write LV Creation host, time STCO6, 2016-08-04 02:29:19 +0800 LV Status available # open 1 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
17、對mylv1創建快照,並通過備份數據;要求保留原有的屬主屬組等信息;
[root@STCO6 ~]# lvcreate -L 1G -n snapmylv -p r -s /dev/testvg/mylv1 Logical volume "snapmylv" created. [root@STCO6 ~]# cd /dev/testvg [root@STCO6 testvg]# ll total 0 lrwxrwxrwx. 1 root root 7 Sep 17 16:41 mylv1 -> ../dm-2 lrwxrwxrwx. 1 root root 7 Sep 17 16:41 snapmylv -> ../dm-5