1、創建一個10G分區,并格式為ext4文件系統; (1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl; (2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
(1) ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x618744c6. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ~]# kpartx -af /dev/sdb ~]# fdisk -l |grep sdb Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors /dev/sdb120482097356710485760 83 Linux Disk /dev/mapper/sdb1: 10.7 GB, 10737418240 bytes, 20971520 sectors [root@node1 ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) /dev/sdb1 is apparently in use by the system; will not make a filesystem here! 報正在使用哦,解決方法 ~]# dmsetup status sdb1: 0 20971520 linear centos-home: 0 141443072 linear centos-swap: 0 4194304 linear centos-root: 0 104857600 linear ~]# dmsetup remove_all ~]# dmsetup status centos-home: 0 141443072 linear centos-swap: 0 4194304 linear centos-root: 0 104857600 linear ~]# fdisk -l | grep sdb1 /dev/sdb120482097356710485760 83 Linux ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=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: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# tune2fs -o acl /dev/sdb1 tune2fs 1.42.9 (28-Dec-2013) (2) ~]# mount -o noexec,noatime /dev/sdb1 /data/mydata ~]# cat /etc/mtab | grep 'sdb1' /dev/sdb1 /data/mydata ext4 rw,noexec,noatime,data=ordered 0 0 ~]# df -h | grep sdb1 /dev/sdb19.8G 13M 9.6G 1% /data/mydata
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G Partition 2 of type Linux and of size 1 GiB is set 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. ~]# kpartx /dev/sdb sdb1 : 0 20971520 /dev/sdb 2048 sdb2 : 0 2097152 /dev/sdb 20973568 ~]# partprobe /dev/sdb ~]# cat /proc/diskstats 8 16 sdb 1848 0 35766 5604 555 16633 463296 24749 0 8733 29069 8 17 sdb1 692 0 12206 1987 550 16633 463256 24647 0 5235 25351 8 18 sdb2 98 0 1664 34 0 0 0 0 0 27 33 ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=41508164-eaa0-46e2-b3a0-f2f69197359f ~]# swapon /dev/sdb2 ~]# cat /proc/swaps FilenameTypeSizeUsedPriority /dev/dm-1 partition20971480-1 /dev/sdb2 partition10485720-2
3、寫一個腳本 (1)、獲取并列出當前系統上的所有磁盤設備; (2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
1 #!/bin/bash 2 # 3 echo "show the disk " 4 fdisk -l | grep "^Disk /dev/s" | cut -d ' ' -f2 5 sleep 2 6 echo "show the usage" 7 df -h ~ ~]# bash show.sh show the disk /dev/sdb: /dev/sdc: /dev/sda: /dev/sdd: show the usage Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 50G 14G 37G 27% / devtmpfs 898M 0 898M 0% /dev tmpfs913M 84K 913M 1% /dev/shm tmpfs913M 9.0M 904M 1% /run tmpfs913M 0 913M 0% /sys/fs/cgroup /dev/sda1497M 158M 340M 32% /boot /dev/mapper/centos-home 68G 37M 68G 1% /home tmpfs183M 16K 183M 1% /run/user/42 tmpfs183M 0 183M 0% /run/user/0 /dev/sdb19.8G 13M 9.6G 1% /data/mydata
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,...) 常用級別:RAID-0, RAID-1, RAID-5, RAID-10, RAID-50, JBOD
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
~]# fdisk -l | grep sd Disk /dev/sda: 128.8 GB, 128849018880 bytes, 251658240 sectors /dev/sda1 *2048 1026047 512000 83 Linux /dev/sda2 1026048 251658239 125316096 8e Linux LVM Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Disk /dev/sdd: 21.5 GB, 21474836480 bytes, 41943040 sectors [root@localhost ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): L 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/Ma0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS55 EZ-Drivea7 NeXTSTEPf0 Linux/PA-RISC b 11 Hidden FAT1256 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT1663 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris bootff BBT 1e Hidden W95 FAT1 80 Old Minix Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ...... ~]# mdadm -C /dev/md0 -l 1 -c 128 -n 2 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 mdadm: /dev/sdb1 appears to contain an ext2fs file system size=10485760K mtime=Mon Nov 7 20:49:14 2016 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/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Nov 7 22:11:43 2016 Raid Level : raid1 Array Size : 10477568 (9.99 GiB 10.73 GB) Used Dev Size : 10477568 (9.99 GiB 10.73 GB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Nov 7 22:12:01 2016 State : clean, resyncing Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Resync Status : 11% complete Name : localhost.localdomain:0 (local to host localhost.localdomain) UUID : 051e87e0:f3e7d2bf:0aa4509f:d692dde2 Events : 1 Number Major Minor RaidDevice State 0 8 170 active sync /dev/sdb1 1 8 331 active sync /dev/sdc1 2 8 49- spare /dev/sdd1
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +4G Partition 2 of type Linux and of size 4 GiB is set Command (m for help): t Partition number (1,2, default 2): Hex code (type L to list all codes): fd Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ...... ~]# mdadm -C /dev/md1 -l 5 -c 256 -n 3 /dev/sdb2 /dev/sdc2 /dev/sdd2 mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md1 started. ~]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Mon Nov 7 22:18:45 2016 Raid Level : raid5 Array Size : 8380416 (7.99 GiB 8.58 GB) Used Dev Size : 4190208 (4.00 GiB 4.29 GB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Nov 7 22:19:08 2016 State : clean, degraded, recovering Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 256K Rebuild Status : 19% complete Name : localhost.localdomain:1 (local to host localhost.localdomain) UUID : cc64aeea:4d683284:8d775b59:224e7f55 Events : 4 Number Major Minor RaidDevice State 0 8 180 active sync /dev/sdb2 1 8 341 active sync /dev/sdc2 3 8 502 spare rebuilding /dev/sdd2 ~]# mke2fs -t ext4 /dev/md1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 524288 inodes, 2095104 blocks 104755 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2145386496 64 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, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# echo "/dev/md1 /backup ext4 defaults,noatime,acl 0 0">>/etc/fstab ~]# mount -a ~]# df -h Filesystem Size Used Avail Use% Mounted on ...... /dev/md1 7.8G 36M 7.3G 1% /backup
7、寫一個腳本 (1) 接受一個以上文件路徑作為參數; (2) 顯示每個文件擁有的行數; (3) 總結說明本次共為幾個文件統計了其行數;
#!/bin/bash # declare -i i=0 if [ $# -lt 1 ];then echo "please input file path" exit 1 fi for file in $*;do if [ -f $file ] ;then echo "$file:$(wc -l $file | cut -d' ' -f1)" let i++ else echo "please input file path" fi done echo "file counts:$i" 執行結果 ~]# bash line.sh please input file path ~]# bash line.sh /etc/passwd /etc/fstab /etc/passwd:71 /etc/fstab:13 file counts:2
8、寫一個腳本 (1) 傳遞兩個以上字符串當作用戶名; (2) 創建這些用戶;且密碼同用戶名; (3) 總結說明共創建了幾個用戶;
#!/bin/bash # declare -i i=0 if [ $# -lt 2 ];then echo "at lease two!!!!!" exit 2 fi for x in $*;do if id $x &>/dev/null;then備注:if判斷后加執行命令時無需加[] useradd $x;echo "$x" | passwd --stdin $x &>/dev/null else useradd $x -p $x &>/dev/null echo "user $x add ok" let i++ fi done echo "totle add user:$i" 執行結果: ~]# bash adduser.sh test1 at lease two!!!!! ~]# bash adduser.sh test1 test2 user test1 add ok user test2 exist totle add user:1 ~]# bash adduser.sh test1 test2 test3 user test1 exist user test2 exist user test3 add ok totle add user:1
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
#!/bin/bash # declare -i number declare -i sum=0 for i in {1..10};do useradd visitor$i echo "useradd visitor$i scuess!" done number=$(id -u visitor$i) sum+=$number echo "sum:$sum" 執行結果: ~]# bash useradd20.sh useradd visitor1 scuess! useradd visitor2 scuess! useradd visitor3 scuess! useradd visitor4 scuess! useradd visitor5 scuess! useradd visitor6 scuess! useradd visitor7 scuess! useradd visitor8 scuess! useradd visitor9 scuess! useradd visitor10 scuess! sum:4031
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
#!/bin/bash # declare -i num1 declare -i num2 declare -i totle declare -i sum for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do num1=$(grep "^#" $i | wc -l) num2=$(grep "^[[:space:]]*$" $i | wc -l) totle+=$num1 sum+=$num2 done echo "totle # line:$totle;totle space line:$sum" 運行結果: ~]# bash sumconf.sh totle # line:91;totle space line:175
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
這里bash的用戶只有一個,所以腳本寫為/sbin/nologin的用戶 #!/bin/bash # declare -i sum=0; declare -i i=0; USER=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{print $1}') USERUID=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{print $3}') USERUID2=$(grep "/sbin/nologin" /etc/passwd | awk -F ":" '{printf"%n,",$3}') USERUID2=${USERUID2//,/ } 將結果中的USERUID2的逗號全部轉換為空格 for i in $USERUID2;do let sum+=$i done echo "user id sum=$sum" echo -e "users is:\n$USER"echo -e /n 換行 echo -e "userid is:\n$USERUID" 運行結果: ~]# bash show.sh user id sum=1057 users is: bin daemon adm lp ... userid is: 1 2 3 ......
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
#!/bin/bash # declare -i i=0; user=$(awk -F ':' '{printf"%s,", $1}' /etc/passwd) user2=${user//,/ } for username in $user2;do group=$(id $username | cut -d' ' -f3) if [ -n $group ];then echo $username let i++ fi done echo "user number: $i" 運行結果: ~]# bash group2.sh root bin ...... user number: 25
13、創建一個由至少兩個物理卷組成的大小為20G的卷組;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
[root@localhost ~]# fdisk /dev/sdd Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xcd6e54be. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): +^H Unsupported suffix: '. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G Partition 1 of type Linux and of size 5 GiB is set Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (10487808-41943039, default 10487808): Using default value 10487808 Last sector, +sectors or +size{K,M,G} (10487808-41943039, default 41943039): +5G Partition 2 of type Linux and of size 5 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. ~]# pvcreate /dev/sdd1 Physical volume "/dev/sdd1" successfully created ~]# pvcreate /dev/sdd2 Physical volume "/dev/sdd2" successfully created ~]# vgcreate myvg -s 8M /dev/sdd1 /dev/sdd2 Volume group "myvg" successfully created ~]# lvcreate -L 5G -n mylv1 myvg Logical volume "mylv1" created. ~]# mkfs.ext4 /dev/myvg/mylv1 mke2fs 1.42.9 (28-Dec-2013) 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 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ~]# mkdir -p /users ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl 0 0">>/etc/fstab ~]# mount -a ~]# df -h |grep users /dev/mapper/myvg-mylv1 4.8G 20M 4.6G 1% /users
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
~]# useradd magedu -d /usersmagedu ~]# su - magedu welcome Tue Nov 8 15:30:58 CST 2016 ~]$ pwd /usersmagedu [magedu@localhost ~]$ cp /etc/fstab . [magedu@localhost ~]$ ls fstab
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created ~]# vgextend myvg /dev/sdc1 Volume group "myvg" successfully extended ~]# lvs LVVG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- 67.45g root centos -wi-ao---- 50.00g swap centos -wi-ao---- 2.00g mylv1 myvg -wi-ao---- 5.00g ~]# lvextend -L 9G /dev/myvg/mylv1 Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. ~]# resize2fs /dev/myvg/mylv1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long. ~]# df -h | grep users /dev/mapper/myvg-mylv1 8.8G 23M 8.3G 1% /users
16、縮減mylv1至7G,確??s減完成后原有數據完全可用;
~]# umount /dev/mapper/myvg-mylv1 ~]# e2fsck -f /dev/mapper/myvg-mylv1 e2fsck 1.42.9 (28-Dec-2013) 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/mapper/myvg-mylv1: 11/589824 files (0.0% non-contiguous), 75551/2359296 blocks ~]# resize2fs /dev/myvg/mylv1 7G resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long. ~]# lvreduce -L 7G /dev/myvg/mylv1 WARNING: Reducing active logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv1? [y/n]: y Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized. ~]# mount -a ~]# df -h |grep users /dev/mapper/myvg-mylv1 6.8G 23M 6.5G 1% /users
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
~]# lvcreate -L 1G -n mylv1_snapshot -p r -s /dev/myvg/mylv1 Logical volume "mylv1_snapshot" created. ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert home centos -wi-ao---- 67.45g root centos -wi-ao---- 50.00g swap centos -wi-ao---- 2.00g mylv1 myvg owi-aos--- 7.00g mylv1_snapshot myvg sri-a-s--- 1.00g mylv1 0.00 ~]# mkdir /lvmsnapshot ~]# mount /dev/myvg/mylv1_snapshot /lvmsnapshot/ mount: /dev/mapper/myvg-mylv1_snapshot is write-protected, mounting read-only ~]# ls -l /lvmsnapshot/ total 16 drwx------. 2 root root 16384 Nov 8 15:25 lost+found
原創文章,作者:N23-蘇州-void,如若轉載,請注明出處:http://www.www58058.com/58575