lvm邏輯卷 練習題

創建一個至少有兩個PV組成的大小為20G的名為testvg的VG;要求PE大小為16MB, 而后在卷組中創建大小為5G的邏輯卷testlv;掛載至/users目錄;在/users下創建一個test.txt文件。擴展testlv至7G,要求archlinux用戶的文件不能丟失;收縮testlv至3G,要求archlinux用戶的文件不能丟失;對testlv創建快照,并嘗試基于快照備份數據,驗正快照的功能。

  任務1,創建邏輯卷testlv

  首先,先創建2個分區   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
[root@localhost~]# 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
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (7859-13081, default 7859): 
Using default value 7859
Last cylinder, +cylinders or +size{K,M,G} (7859-13081, default 13081): +10G
 
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (9165-13081, default 9165):    
Using default value 9165
Last cylinder, +cylinders or +size{K,M,G} (9165-13081, default 13081): +10G
 
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: 0x0002b73a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560   8e  Linux LVM
/dev/sda3            7859       13081    41952748+   5  Extended
/dev/sda5            7859        9164    10489414+  83  Linux
/dev/sda6            9165       10470    10490413+  83  Linux
 
Command (m for help): t   #修改分區ID
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: 0x0002b73a
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26        7859    62914560   8e  Linux LVM
/dev/sda3            7859       13081    41952748+   5  Extended
/dev/sda5            7859        9164    10489414+  8e  Linux LVM
/dev/sda6            9165       10470    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@localhost ~]# 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
[root@localhost ~]# 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 5
BLKPG: Device or resource busy
error adding partition 6
[root@localhost ~]# cat /proc/partitions #查看分區信息
major minor  #blocks  name
 
   8        0  125829120 sda
   8        1     204800 sda1
   8        2   62914560 sda2
   8        3          1 sda3
   8        5   10489414 sda5
   8        6   10490413 sda6
 253        0   20971520 dm-0
 253        1    2097152 dm-1
 253        2   10485760 dm-2
 253        3   20971520 dm-3

   創建pv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[root@localhost ~]# pvcreate /dev/sda5
  Physical volume “/dev/sda5” successfully created
[root@localhost ~]# pvcreate /dev/sda6
  Physical volume “/dev/sda6” successfully created
[root@localhost ~]# pvdisplay  
  “/dev/sda5” is a new physical volume of “10.00 GiB”
  — NEW Physical volume —
  PV Name               /dev/sda5
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               aWkcdi-T8zI-ZQ7h-xcPE-KhDI-HAmz-TEaAph
    
  “/dev/sda6” is a new physical volume of “10.00 GiB”
  — NEW Physical volume —
  PV Name               /dev/sda6
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Ib9szy-eyhG-zWDZ-sm6t-MUXI-sCUu-S2XtuG

  創建vg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
[root@localhost~]# vgcreate -v -s 16MB testvg /dev/sda5
    DEGRADED MODE. Incomplete RAID LVs will be processed.
    Wiping cache of LVM-capable devices
    Wiping cache of LVM-capable devices
    Adding physical volume ‘/dev/sda5’ to volume group ‘testvg’
    Archiving volume group “testvg” metadata (seqno 0).
    Creating volume group backup “/etc/lvm/backup/testvg” (seqno 1).
  Volume group “testvg” successfully created
[root@localhost~]# vgextend -v testvg /dev/sda6
    DEGRADED MODE. Incomplete RAID LVs will be processed.
    Checking for volume group “testvg”
    Archiving volume group “testvg” metadata (seqno 1).
    Wiping cache of LVM-capable devices
    Adding physical volume ‘/dev/sda6’ to volume group ‘testvg’
    Volume group “testvg” will be extended by 1 new physical volumes
    Creating volume group backup “/etc/lvm/backup/testvg” (seqno 2).
  Volume group “testvg” successfully extended
[root@localhost ~]# vgdisplay 
  — Volume group —
  VG Name               testvg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  2
  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               16.00 MiB   #PE 大小16MB
  Total PE              1280
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1280 / 20.00 GiB
  VG UUID               i06ZbB-QWLX-zWmW-x2hS-L8Uo-zAbN-g4MhEu

  創建邏輯卷testlv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~]# lvcreate -L 5G -n testlv /dev/testvg
  Logical volume “testlv” created
[root@localhost ~]# lvdisplay 
  — Logical volume —
  LV Path                /dev/testvg/testlv
  LV Name                testlv
  VG Name                testvg
  LV UUID                tNyjOF-7Sb4-RVbW-W7Yk-zi6N-jXYG-LK4sOI
  LV Write Access        read/write
  LV Creation host, time laopan, 2015-08-27 18:37:40 +0800
  LV Status              available
  # open                 0
  LV Size                5.00 GiB  #邏輯卷5G
  Current LE             320
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:4

   在/dev/testvg/testlv創建ext4文件系統   

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[root@localhost ~]# mkfs -t ext4 /dev/testvg/testlv 
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 20 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

   創建掛載點 mkdir /users

   把/dev/testvg/testlv 掛載至/users,在其目錄下創建一個test.txt文件

1
2
3
4
5
6
7
[root@localhost ~]# mount /dev/testvg/testlv /users
[root@localhost ~]# cd /users
[root@localhost users]# echo `date` > test.txt
[root@localhost users]# ls
lost+found  test.txt
[root@laopan users]# cat test.txt 
Thu Aug 27 18:45:46 CST 2015

   任務2,在線把testlv擴展至7G,保證test.txt是否丟失

   先對邏輯卷擴容

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost users]# lvextend -L 7G /dev/testvg/testlv 
  Size of logical volume testvg/testlv changed from 5.00 GiB (320 extents) to 7.00 GiB (448 extents). #已經擴展到7G了,但是文件系統識別的還是5G,所以需要對文件系統擴容
  Logical volume testlv successfully resized
[root@localhost users]# df
Filesystem           1K-blocks    Used Available Use% Mounted on
/dev/mapper/vg0-root  20511356  293400  19169380   2% /
tmpfs                  1954364       0   1954364   0% /dev/shm
/dev/sda1               194241   33069    150932  18% /boot
/dev/mapper/vg0-usr   10190136 1953200   7712648  21% /usr
/dev/mapper/vg0-var   20511356  199612  19263168   2% /var
/dev/mapper/testvg-testlv
                       5029504   10236   4757124   1% /users

   再對testlv的文件系統擴容,命令resize2fs 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost users]# resize2fs -f /dev/testvg/testlv 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/testvg/testlv is mounted on /users; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/testvg/testlv to 1835008 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 1835008 blocks long.
 
[root@localhost users]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg0-root   20G  287M   19G   2% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             190M   33M  148M  18% /boot
/dev/mapper/vg0-usr   9.8G  1.9G  7.4G  21% /usr
/dev/mapper/vg0-var    20G  195M   19G   2% /var
/dev/mapper/testvg-testlv
                      6.8G   12M  6.5G   1% /users

   回頭再確認一下/users下的test是否還在

1
2
[root@localhost users]# cat test.txt 
Thu Aug 27 18:45:46 CST 2015

   經驗證test.txt沒有損壞,任務完成

   任務3,下面進行邏輯卷縮減實驗

    首先需要卸載/dev/testvg/testlv

1
2
[root@localhost users]# cd ..
[root@localhost /]# umount /dev/testvg/testlv

    進行文件檢查

1
2
3
4
5
6
7
8
[root@localhost /]# e2fsck -f /dev/testvg/testlv 
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/testlv: 12/458752 files (0.0% non-contiguous), 64448/1835008 blocks

   檢查OK,進入一步,文件系統縮減

1
2
3
4
[root@localhost /]# resize2fs /dev/testvg/testlv 3G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/testvg/testlv to 786432 (4k) blocks.
The filesystem on /dev/testvg/testlv is now 786432 blocks long.

    最后縮減邏輯卷testlv

1
2
3
4
5
6
[root@localhost /]# lvreduce -L 3G /dev/testvg/testlv 
\  WARNING: Reducing active logical volume to 3.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv? [y/n]: y
  Size of logical volume testvg/testlv changed from 7.00 GiB (448 extents) to 3.00 GiB (192 extents).
  Logical volume testlv successfully resized

   把縮減后的邏輯卷testlv掛載至/users下面,檢查

1
2
3
4
5
6
7
8
9
10
11
12
[root@localhost /]# mount /dev/testvg/testlv /users/
[root@localhost /]# df -h #容量檢查
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg0-root   20G  287M   19G   2% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
/dev/sda1             190M   33M  148M  18% /boot
/dev/mapper/vg0-usr   9.8G  1.9G  7.4G  21% /usr
/dev/mapper/vg0-var    20G  195M   19G   2% /var
/dev/mapper/testvg-testlv
                      2.9G  7.6M  2.7G   1% /users
[root@localhost /]# cat /users/test.txt #文件檢查
Thu Aug 27 18:45:46 CST 2015

   testlv變成2.9G在一定范圍可接受。文件test.txt沒有損壞。

   任務4,對testlv做快照

1
2
[root@localhost users]# lvcreate -s -L 1G -p r -n test_snap_shot /dev/testvg/testlv 
  Logical volume “test_snap_shot” created

   檢查快照

1
2
3
4
[root@localhost users]# mount /dev/testvg/test_snap_shot /mnt
mount: block device /dev/mapper/testvg-test_snap_shot is write-protected, mounting read-only
[root@localhost users]# cat /mnt/test.txt 
Thu Aug 27 18:45:46 CST 2015

原創文章,作者:island,如若轉載,請注明出處:http://www.www58058.com/71234

(0)
islandisland
上一篇 2017-03-16
下一篇 2017-03-16

相關推薦

  • N25-第二周作業

    1、  Linux上的文件管理類命令都有那些,其常用的使用方法及其相關示例演示。 常用的管理類命令有:rm、mv、cp 1)         rm:remove rm [ OPTION ] FILE 常用選項:     &nbsp…

    Linux干貨 2016-12-13
  • Linux 命令行返回狀態

    linux 執行命令后會返回一個狀態碼 命令執行成功返回0: 當刪除一個文件并刪除成功時返回的狀態碼為0 [root@localhost 1]# rm -rf 1_1 [root@localhost 1]# echo $? 0 命令執行失敗返回1-255 當把 文件夾 1_1 重命名為1_2失敗后狀態碼為1 [root@localhost 1]# mv 1_…

    Linux干貨 2017-08-28
  • 多任務腳本發布

    1、此腳本用于將80和443用iptables mark標記后 添加到 ipcsadm 中,讓80端口和443端口當成一類 服務進行調度 —————————————————————————————————————————————— #!/bin/bash 多端口綁定,這里是80和443被iptables綁定為一個標記分發后端 vip=172.16.0.99M…

    Linux干貨 2017-06-25
  • keepalived+varnish+haproxy+LNAMP

      nfs: 192.168.1.40 rp1: 192.168.1.41 rp2: 192.168.1.42 mariadb: 192.168.1.43 web1: 192.168.1.110 web2: 192.168.1.111 app1: 192.168.1.112 app2: 192.168.1.113 實驗效果:用keepalived高…

    2018-02-18
  • Linux基于OpenSSL實現私有CA構建

    前言 隨著互聯網的迅猛發展,網絡通信已經成為傳遞信息的主要途徑。而通信時的數據傳輸大部分卻是明文傳輸的,在網絡這個不安全的環境下,如果沒有一套數據加密機制,就會導致敏感信息和重要數據泄露,引起不可估量的損失。而OpenSSL正好彌補了這一缺憾,那什么是OpenSSL呢?OpenSSL是一套強大的具有加密功能的組件,它包含libcrypto(公共加密庫)、li…

    Linux干貨 2015-04-13
  • vim文本編輯器

    vim簡介: vi: Visual Interface,文本編輯器 文本:ASCII, Unicode 文本編輯種類: 行編輯器: sed 全屏編輯器:nano, vi vim – Vi Improved 其他編輯器: gedit一個簡單的圖形編輯器 gvim一個Vim 編輯器的圖形版本   vim使用: 三種主要模式: 命令(Norm…

    Linux干貨 2017-06-17
欧美性久久久久