1、創建一個10G分區,并格式為ext4文件系統;
(1) 要求其block大小為2048, 預留空間百分比為2, 卷標為MYDATA, 默認掛載屬性包含acl;
(2) 掛載至/data/mydata目錄,要求掛載時禁止程序自動運行,且不更新文件的訪問時間戳;
在擴展分區/dev/sda4下新建一個10G的分區/dev/sda5:
~]# 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 (4242-8158, default 4242): Using default value 4242 Last cylinder, +cylinders or +size{K,M,G} (4242-8158, default 8158): +10G
強制內核重讀磁盤分區信息并確認新分區創建成功:
~]# partx -a /dev/sda ~]# cat /proc/partitions major minor #blocks name 8 0 83886080 sda 8 1 512000 sda1 8 2 31457280 sda2 8 3 2097152 sda3 8 4 1 sda4 8 5 10488790 sda5
將此分區按要求創建為ext4文件系統:
~]# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sda5 ~]# tune2fs -o acl /dev/sda5 tune2fs 1.41.12 (17-May-2010)
在指定的目錄下按要求掛載此分區:
[root@CentOS6 ~]# mount -o noexec -o noatime /dev/sda5 /data/mydata/ [root@CentOS6 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.5G 27G 6% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 31M 421M 7% /boot /dev/sda5 9.8G 13M 9.6G 1% /data/mydata
2、創建一個大小為1G的swap分區,并創建好文件系統,并啟用之;
在擴展分區/dev/sda4下新建一個1G的分區/dev/sda6并修改類型為SWAP:
Command (m for help): n First cylinder (5548-8158, default 5548): Using default value 5548 Last cylinder, +cylinders or +size{K,M,G} (5548-8158, default 8158): +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): p Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x000cfe14 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 3981 31457280 83 Linux /dev/sda3 3981 4242 2097152 82 Linux swap / Solaris /dev/sda4 4242 8158 31461679 5 Extended /dev/sda5 4242 5547 10488790 83 Linux /dev/sda6 5548 5679 1060258+ 82 Linux swap / Solaris
強制內核重讀磁盤分區信息并確認新分區創建成功:
~]# partx -a /dev/sda ~]# cat /proc/partitions major minor #blocks name major minor #blocks name 8 0 83886080 sda 8 1 512000 sda1 8 2 31457280 sda2 8 3 2097152 sda3 8 4 1 sda4 8 5 10488790 sda5 8 6 1060258 sda6
將此分區按要求創建為SWAP文件系統并掛載啟用:
~]# mkswap -L SWAP2 /dev/sda6 Setting up swapspace version 1, size = 1060252 KiB LABEL=SWAP2, UUID=ee1b3009-e8aa-4a2d-8200-dd91b78a89aa
先查看本機目前的SWAP分區大小為2G:
~]# free -m total used free shared buffers cached Mem: 980 119 860 0 8 34 -/+ buffers/cache: 76 903 Swap: 2047 0 2047
掛載新SWAP分區后再驗證本機的SWAP分區大小為3G:
~]# swapon /dev/sda6 ~]# free -m total used free shared buffers cached Mem: 980 120 860 0 8 34 -/+ buffers/cache: 77 903 Swap: 3083 0 3083
3、寫一個腳本
(1)、獲取并列出當前系統上的所有磁盤設備;
(2)、顯示每個磁盤設備上每個分區相關的空間使用信息;
``` #!/bin/bash # fdisk -l /dev/[sh]d[a-z] | grep -o "Disk /dev/[sh]d[a-z]" echo fdisk -l ```
4、總結RAID的各個級別及其組合方式和性能的不同;
RAID稱為獨立(廉價)冗余磁盤陣列。是最初由伯克利大學提出的一種將多塊廉價的單塊硬盤按某種標準組合起來作為一塊硬盤來使用的解決方案。RAID的優點是能夠提高磁盤的I/O能力和冗余(恢復)能力。
RAID根據磁盤組合方式的不同分為多個RAID級別,常用的級別有RAID-0,RAID-1,RAID-,5,RAID-10,RAID-50,JBOD。
RAID-0: 又稱為條帶卷
RAID-0模式下,RAID控制會將每一個數據文件分為一個個小的數據塊,稱chunk。然后平均分配將chunk分別存儲到各個磁盤上。如此一來,RAID-0的整體IO能力
比單塊磁盤提高了N倍(N為組成RAID-0的磁盤數量),但RAID-0沒有任何冗余能力,一旦一塊磁盤損壞,所有數據都會丟失,故RAID-0只能用于存放臨時數據或不重要的文件,不能用于生產環境。
性能總結:IO能力提高N倍,無冗余能力,磁盤數量大于等于兩塊,最大存儲空間為N*MIn{disk1,2,3…}
RAID-1:又稱為鏡像卷
RAID-1模式下,RAID控制會將每一個數據文件分為一個個小的數據塊,稱為chunk。然后每一個chunk在各個磁盤上都會被存儲一份。如此一來, RAID-1的寫性能大大減少,因為每一個數據塊原來只需要寫一遍,現在要寫N遍,但讀性能卻大大提高,因為讀取數據時可以從各個磁盤中同時讀取,同時,RAID-1具有很強的數據恢復能力,一塊磁盤的損壞不會丟失數據。
性能總結:寫性能下降,讀性能上升,冗余能力強,磁盤數量大于等于兩塊,最大存儲空間Min{disk1,2,3,…}
RAID-5:
RAID-5至少由3塊以上磁盤構成,每次存儲數據時,輪流拿出一塊磁盤存儲校驗碼。校驗碼的作用是如果有一塊磁盤損壞,可以根據其他幾塊磁盤上的數據和校驗碼恢復出完整數據,但此時稱為RAID-5工作于降級模式,必須馬上修復損壞的磁盤。RAID-5存儲一個數據的過程如下:假設RAID-5由3塊磁盤組成。存儲一個數據,RAID控制器將數據分為6個chunk,第一次,存儲chunk1,chunk2于磁盤1,2,磁盤3存放校驗碼。第二次,存儲chunk3,chunk4于于磁盤1,3,磁盤2存放校驗碼。第三次,存儲chunk5,chunk6于磁盤2,3,磁盤1存放校驗碼。
性能總結:讀寫性能提升,有1塊磁盤的冗余能力,磁盤數量大于等于兩塊,最大存儲空間(N-1)*Min{disk1,2,3….}
混合類型:
RAID-10
假設RAID-10由10塊磁盤組成。先兩兩組合構成RAID-1,然后再將5組磁盤構成RAID-0。RAID-10是目前比較理想的RAID模型。RAID-10有一塊磁盤的冗余能力,讀寫能力也有提升。
性能總結:讀寫性能提升,有冗余能力(各鏡像中允許損壞一塊磁盤),磁盤數量大于等于4塊,最大存儲空間min{disk1,2,3,4…}*N/2
RAID-50
先組合出幾個RAID-5,然后將幾個RAID-5組按照RAID-0組成。也是一種比較理想的RAID模型。
性能總結:讀寫性能提升,有冗余能力(損壞一塊磁盤工作于降級模式),磁盤數量大于等于6塊
JBOD:Just a Bunch Of Disks
功能:將多塊磁盤的空間合并一個大的連續空間使用;
可用空間:sum(S1,S2,…)
用于存放一個超大的數據文件。
RAID的配置實現是通過RAID控制器在安裝硬盤時在BIOS上完成的。但我們也可以用軟件來模擬個RAID級別的實現。
5、創建一個大小為10G的RAID1,要求有一個空閑盤,而且CHUNK大小為128k;
在擴展分區/dev/sda4下新建3個邏輯分區,每個為10G,并將分區類型改為fd:
Command (m for help): p Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x000cfe14 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 3981 31457280 83 Linux /dev/sda3 3981 4242 2097152 82 Linux swap / Solaris /dev/sda4 4242 8158 31461679 5 Extended /dev/sda5 4242 5417 9444565 fd Linux raid autodetect /dev/sda6 5418 6593 9446188+ fd Linux raid autodetect /dev/sda7 6594 7769 9446188+ fd Linux raid autodetect
用兩個分區創建RAID-1,另一個作為空閑分區:
~]# mdadm -C /dev/md0 -n 2 -l 1 -a yes -c 128 -x 1 /dev/sda{5,6,7} ~]# cat /proc/mdstat Personalities : [raid1] md0 : active raid1 sda7[2](S) sda6[1] sda5[0] 9436352 blocks super 1.2 [2/2] [UU] unused devices: <none>
6、創建一個大小為4G的RAID5設備,chunk大小為256k,格式化ext4文件系統,要求可開機自動掛載至/backup目錄,而且不更新訪問時間戳,且支持acl功能;
在擴展分區/dev/sda4下新建3個邏輯分區,每個為2G,并將分區類型改為fd:
Command (m for help): p Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x000cfe14 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 3981 31457280 83 Linux /dev/sda3 3981 4242 2097152 82 Linux swap / Solaris /dev/sda4 4242 8158 31461679 5 Extended /dev/sda5 4242 4503 2102860 fd Linux raid autodetect /dev/sda6 4504 4765 2104483+ fd Linux raid autodetect /dev/sda7 4766 5027 2104483+ fd Linux raid autodetect
創建為RAID-5:
~]# mdadm -C /dev/md0 -n 3 -l 5 -a yes -c 256 /dev/sda{5,6,7} ~]# cat /proc/mdstat Personalities : [raid6] [raid5] [raid4] md0 : active raid5 sda7[3] sda6[1] sda5[0] 4201472 blocks super 1.2 level 5, 256k chunk, algorithm 2 [3/3] [UUU] unused devices: <none>
格式化為ext4文件系統:
~]# mkfs.ext4 /dev/md0 mke2fs 1.41.12 (17-May-2010) 文件系統標簽= 操作系統:Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 262944 inodes, 1050368 blocks 52518 blocks (5.00%) reserved for the super user 第一個數據塊=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 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 34 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
編輯/etc/fstab文件使/dev/md0能夠開機自動掛載:
~]# tail -n 1 /etc/fstab UUID=2165b6ca-78fa-403e-bd9b-3ea1092b6811 /data/mydata ext4 defaults,acl,noatime 0 0 ~]# reboot ~]# mount /dev/sda2 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/md127 on /data/mydata type ext4 (rw,noatime,acl) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
7、寫一個腳本
(1) 接受一個以上文件路徑作為參數;
(2) 顯示每個文件擁有的行數;
(3) 總結說明本次共為幾個文件統計了其行數;
``` #!/bin/bash # for i in $*;do line_num=$(wc -l $i | cut -d" " -f1) echo "$i has $line_num lines." done echo echo "we count $# files's line number this time." ```
8、寫一個腳本
(1) 傳遞兩個以上字符串當作用戶名;
(2) 創建這些用戶;且密碼同用戶名;
(3) 總結說明共創建了幾個用戶;
``` #!/bin/bash # if [ $# -le 2 ];then echo "Please enter two more user_id." && exit 2 fi for i in $*;do useradd $i echo $i | passwd --stdin $i done echo echo "we add $# users this time." ```
9、寫一個腳本,新建20個用戶,visitor1-visitor20;計算他們的ID之和;
``` #!/bin/bash # declare -i num=0 for i in `seq 20`;do useradd visitor$i id=$(id -u visitor$i) num=$[$num+$id] done echo "The id_sum of these twenty users are $num." ```
10、寫一腳本,分別統計/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#號開頭的行數之和,以及總的空白行數;
``` #!/bin/bash # declare -i count1=0 declare -i count2=0 for i in /etc/{fstab,rc.d/{rc.sysinit,init.d/functions}};do count1=$[$(grep "^#" $i | wc -l) + $count1] count2=$[$(grep "^[[:space:]]*$" $i | wc -l) + $count2] done echo "$count1 lines start with # and $count2 blank lines in {/etc/rc.d/init.d/functions,/etc/fstab,/etc/rc.d/rc.sysinit " ```
11、寫一個腳本,顯示當前系統上所有默認shell為bash的用戶的用戶名、UID以及此類所有用戶的UID之和;
``` #!/bin/bash # declare -i num=0 cat /etc/passwd | grep "bash$" | cut -d: -f1,3 echo for i in `cat /etc/passwd | grep "bash$" | cut -d: -f1,3 | cut -d: -f2`;do num=$[$num+$i] done echo "The id_sum of these users are $num." ```
12、寫一個腳本,顯示當前系統上所有,擁有附加組的用戶的用戶名;并說明共有多少個此類用戶;
``` #!/bin/bash # declare -i count=0 for i in `cat /etc/passwd | cut -d: -f1`;do group_num=$(id $i -G | wc -w) if [ $group_num -gt 1 ];then echo "user $i has appand group." let count++ fi done ```
13、創建一個由至少兩個物理卷組成的大小為20G的卷組VG;要求,PE大小為8M;而在卷組中創建一個大小為5G的邏輯卷mylv1,格式化為ext4文件系統,開機自動掛載至/users目錄,支持acl;
先在擴展分區/dev/sda4劃出3個邏輯分區/dev/sda5,/dev/sda6,/dev/sda7作為底層塊設備PV,分區類型改為8e并創建為PV:
Command (m for help): p Disk /dev/sda: 85.9 GB, 85899345920 bytes 255 heads, 63 sectors/track, 10443 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: 0x000cfe14 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 3981 31457280 83 Linux /dev/sda3 3981 4242 2097152 82 Linux swap / Solaris /dev/sda4 4243 9465 41953747+ 5 Extended /dev/sda5 4243 5548 10490413+ 8e Linux LVM /dev/sda6 5549 6332 6297448+ 8e Linux LVM /dev/sda7 6333 6855 4200966 8e Linux LVM [root@CentOS6 ~]# pvcreate /dev/sda{5,6,7} Physical volume "/dev/sda5" successfully created Physical volume "/dev/sda6" successfully created Physical volume "/dev/sda7" successfully created [root@CentOS6 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda5 lvm2 ---- 10.00g 10.00g /dev/sda6 lvm2 ---- 6.01g 6.01g /dev/sda7 lvm2 ---- 4.01g 4.01g
用已有的三個PV組成一個VG,PE大小為8M:
[root@CentOS6 ~]# vgs [root@CentOS6 ~]# vgcreate -s 8M myvg /dev/sda{5,6,7} Volume group "myvg" successfully created [root@CentOS6 ~]# vgdisplay --- Volume group --- VG Name myvg System ID Format lvm2 Metadata Areas 3 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 3 Act PV 3 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 GAca2m-HW4Q-zgIn-9ve2-vbx7-QNTh-EQ5lNx
在myvg中創建邏輯卷LV為5G的mylv1:
[root@CentOS6 ~]# lvs [root@CentOS6 ~]# lvcreate -L 5G -n mylv1 myvg Logical volume "mylv1" created. [root@CentOS6 ~]# lvdisplay --- Logical volume --- LV Path /dev/myvg/mylv1 LV Name mylv1 VG Name myvg LV UUID 0Bdi7m-GBja-lkOl-vipn-jTIy-fkcR-b8yzyr LV Write Access read/write LV Creation host, time CentOS6.8, 2016-10-24 11:26:50 +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
對可用分區mylv1格式化并設置開機自動掛載:
[root@CentOS6 ~]# mkfs.ext4 /dev/myvg/mylv1 mke2fs 1.41.12 (17-May-2010) 文件系統標簽= 操作系統:Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user 第一個數據塊=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 正在寫入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 25 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@CentOS6 ~]# tail -n 1 /etc/fstab UUID=29f0e9b2-30a8-49e4-af12-bf5689c291fa /users ext4 defaults,acl 0 0
14、新建用戶magedu;其家目錄為/users/magedu,而后su切換至此用戶,復制多個文件至家目錄;
確保/dev/myvg/mylv1掛載已完成:
[root@CentOS6 ~]# reboot [root@CentOS6 ~]# cd /users/ [root@CentOS6 users]# ls lost+found [root@CentOS6 users]# mount /dev/sda2 on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw) /dev/sda1 on /boot type ext4 (rw) /dev/mapper/myvg-mylv1 on /users type ext4 (rw,acl) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@CentOS6 ~]# useradd -d /users/magedu magedu [root@CentOS6 magedu]# su - magedu [magedu@CentOS6 ~]$ pwd /users/magedu [magedu@CentOS6 ~]$ cp /etc/resolv.conf /etc/httpd/conf/httpd.conf /etc/sysconfig/network-scripts/ifcfg-eth0 . [magedu@CentOS6 ~]$ ls httpd.conf ifcfg-eth0 resolv.conf
15、擴展mylv1至9G,確保擴展完成后原有數據完全可用;
[root@CentOS6 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.5G 27G 6% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 31M 421M 7% /boot /dev/mapper/myvg-mylv1 4.8G 11M 4.6G 1% /users [root@CentOS6 ~]# 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.
擴展文件系統邊界適應lv的擴展
[root@CentOS6 ~]# resize2fs /dev/myvg/mylv1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/myvg/mylv1 is mounted on /users; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/myvg/mylv1 to 2359296 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long. [root@CentOS6 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.5G 27G 6% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 31M 421M 7% /boot /dev/mapper/myvg-mylv1 8.8G 12M 8.3G 1% /users
16、縮減mylv1至7G,確保縮減完成后原有數據完全可用;
不能聯機縮減,要先卸載
[root@CentOS6 ~]# umount /dev/myvg/mylv1
強制檢測文件系統并先縮減文件系統的大小
[root@CentOS6 ~]# e2fsck -f /dev/myvg/mylv1 e2fsck 1.41.12 (17-May-2010) 第一步: 檢查inode,塊,和大小 第二步: 檢查目錄結構 第3步: 檢查目錄連接性 Pass 4: Checking reference counts 第5步: 檢查簇概要信息 /dev/myvg/mylv1: 23/589824 files (0.0% non-contiguous), 72691/2359296 blocks [root@CentOS6 ~]# resize2fs /dev/myvg/mylv1 7G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long.
縮小lv的大小并重新掛載
[root@CentOS6 ~]# 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 myvg/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. [root@CentOS6 ~]# mount /dev/myvg/mylv1 /users [root@CentOS6 ~]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda2 30G 1.5G 27G 6% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 31M 421M 7% /boot /dev/mapper/myvg-mylv1 6.8G 12M 6.5G 1% /users
確保文件沒有損壞
[root@CentOS6 ~]# cd /users/magedu/ [root@CentOS6 magedu]# cat resolv.conf # Generated by NetworkManager nameserver 192.168.1.1
17、對mylv1創建快照,并通過備份數據;要求保留原有的屬主屬組等信息;
快照卷和原卷必須在同一個VG上:
[root@CentOS6 ~]# lvcreate -L 20M -s -p r -n mylv1-snap /dev/myvg/mylv1 Rounding up size to full physical extent 24.00 MiB Logical volume "mylv1-snap" created. [root@CentOS6 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg owi-aos--- 7.00g mylv1-snap myvg sri-a-s--- 24.00m mylv1 0.05
掛載快照卷并查看:
[root@CentOS6 ~]# mount /dev/myvg/mylv1-snap /mnt mount: block device /dev/mapper/myvg-mylv1--snap is write-protected, mounting read-only [root@CentOS6 ~]# cd /mnt/ [root@CentOS6 mnt]# ls lost+found magedu [root@CentOS6 mnt]# cd magedu/ [root@CentOS6 magedu]# ls httpd.conf ifcfg-eth0 resolv.conf [root@CentOS6 magedu]# cat resolv.conf # Generated by NetworkManager nameserver 192.168.1.1
對原卷中的文件進行修改,快照卷中的文件不會發生改變:
[root@CentOS6 magedu]# cd /users/magedu/ [root@CentOS6 magedu]# ls httpd.conf ifcfg-eth0 resolv.conf [root@CentOS6 magedu]# vim resolv.conf [root@CentOS6 magedu]# cd /mnt/ [root@CentOS6 mnt]# ls lost+found magedu [root@CentOS6 mnt]# cd magedu/ [root@CentOS6 magedu]# cat resolv.conf # Generated by NetworkManager nameserver 192.168.1.1
不需要快照卷后,可以刪除這個snap-lv:
[root@CentOS6 ~]# umount /mnt [root@CentOS6 ~]# lvremove /dev/myvg/mylv1-snap Do you really want to remove active logical volume mylv1-snap? [y/n]: y Logical volume "mylv1-snap" successfully removed [root@CentOS6 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert mylv1 myvg -wi-ao---- 7.00g
原創文章,作者:上海-brown,如若轉載,請注明出處:http://www.www58058.com/54120