码迷,mamicode.com
首页 > 其他好文 > 详细

LVM练习题

时间:2016-07-30 18:06:44      阅读:424      评论:0      收藏:0      [点我收藏+]

标签:

1、创建一个由两个物理卷组成大小为20G的卷组myvg,要求PE大小16M;而后新建 大小为7 G逻辑卷mylv1,要求其文件系统为ext4,块大小为2048,且开机能自动挂载至/users;

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
[root@demo ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa360fa76.
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-6527, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10G
 
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1307-6527, default 1307):
Using default value 1307
Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +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): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
[root@demo ~]# pvcreate myvg /dev/sdb{1,2}
  Device myvg not found (or ignored by filtering).
  Physical volume "/dev/sdb1" successfully created
  Physical volume "/dev/sdb2" successfully created
[root@demo ~]# vgcreate -s 16MB myvg /dev/sdb{1,2}
  Volume group "myvg" successfully created
[root@demo ~]# lvcreate -L 7G -n mylv1 myvg
  Logical volume "mylv1" created
[root@demo ~]# mke2fs -t ext4 -b 2048 /dev/myvg/mylv1
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
458752 inodes, 3670016 blocks
183500 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=541065216
224 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
 
Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done  
 
[root@demo ~]# mkdi
mkdict  mkdir  
[root@demo ~]# mkdir /users
[root@demo ~]# blkid /dev/myvg/mylv1
/dev/myvg/mylv1: UUID="2cf83771-e51e-4e86-a5a3-53309f13ba32" TYPE="ext4"
[root@demo ~]# echo ‘/dev/myvg/mylv1 /users ext4 defaults 1 4‘ >> /etc/fstab
[root@demo ~]# mount -a
[root@demo ~]# mount
/dev/mapper/vg_demo-lv_root 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/sr0 on /mnt type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv1 on /users type ext4 (rw)
[root@demo ~]# cd /users/
[root@demo users]# ls
lost+found

2、缩减mylv1至5G大小;确保其数据没有丢失;

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
[root@demo ~]# ls /users
init.d      rc     rc1.d  rc3.d  rc5.d  rc.local
lost+found  rc0.d  rc2.d  rc4.d  rc6.d  rc.sysinit
[root@demo ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_demo-lv_root
                       45G  2.8G   40G   7% /
tmpfs                 866M     0  866M   0% /dev/shm
/dev/sda1             477M   64M  385M  15% /boot
/dev/sr0              3.6G  3.6G     0 100% /mnt
/dev/mapper/myvg-mylv1
                      6.9G   12M  6.5G   1% /users
[root@demo ~]# umount /users
[root@demo ~]# e2fsck -f /dev/myvg/mylv1
e2fsck 1.43-WIP (20-Jun-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/myvg/mylv1: 253/458752 files (0.0% non-contiguous), 96357/3670016 blocks
[root@demo ~]# resize2fs /dev/myvg/mylv1 5G
resize2fs 1.43-WIP (20-Jun-2013)
Resizing the filesystem on /dev/myvg/mylv1 to 2621440 (2k) blocks.
The filesystem on /dev/myvg/mylv1 is now 2621440 blocks long.
 
[root@demo ~]# lvreduce -L 5G /dev/myvg/mylv1
  WARNING: Reducing active logical volume to 5.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 7.00 GiB (448 extents) to 5.00 GiB (320 extents).
  Logical volume mylv1 successfully resized
[root@demo ~]# mount /dev/myvg/mylv1 /users
[root@demo ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_demo-lv_root
                       45G  2.8G   40G   7% /
tmpfs                 866M     0  866M   0% /dev/shm
/dev/sda1             477M   64M  385M  15% /boot
/dev/sr0              3.6G  3.6G     0 100% /mnt
/dev/mapper/myvg-mylv1
                      4.9G   12M  4.6G   1% /users
 
[root@demo ~]# ls /users
init.d      rc     rc1.d  rc3.d  rc5.d  rc.local
lost+found  rc0.d  rc2.d  rc4.d  rc6.d  rc.sysinit

4、对mylv1创建快照卷snap-mylv1,并通过其备份数据至/tmp/user.tar.bz2;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@demo ~]# lvcreate -s -L 2G -n mylv1-snap -p r /dev/myvg/mylv1
  Logical volume "mylv1-snap" created
[root@demo ~]# mount /dev/myvg/mylv1-snap /mnt
mount: block device /dev/mapper/myvg-mylv1--snap is write-protected, mounting read-only
[root@demo ~]# ls /mnt/
init.d      rc     rc1.d  rc3.d  rc5.d  rc.local
lost+found  rc0.d  rc2.d  rc4.d  rc6.d  rc.sysinit
[root@demo ~]# tar -jcf /tmp/user.tar.bz2 /mnt/*
tar: Removing leading `/‘ from member names
[root@demo ~]# ls /tmp/
pulse-iUvjqtKWN6fB  user.tar.bz2  yum.log
[root@demo ~]# umount /mnt
[root@demo ~]# 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






LVM练习题

标签:

原文地址:http://www.cnblogs.com/Saviorsyang/p/5721435.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!