losetup,设置和控制loop设备。使用这个程序最大的用处可能就是用于linux文件系统加密,这是今天不会提到的内容,可能会在<二>中谈及。至于今天这篇相信网上会有类似的很多,自己只是实验性的去玩一把:
目标:为实验LVM的设置而又不愿意占用本地磁盘的资源。
lee@lee-laptop:/media/sda6$ cd LVM-test/
建立两个零文件,每个10M。
lee@lee-laptop:/media/sda6/LVM-test$ dd if=/dev/zero of=./file.img bs=1k count=10000
记录了 1000+0 的读入
记录了 1000+0 的写出
1024000 字节 (1.0 MB) 已复制,0.00385965 秒,265 MB/秒
lee@lee-laptop:/media/sda6/LVM-test$ dd if=/dev/zero of=./file2.img bs=1k count=10000
记录了 1000+0 的读入
记录了 1000+0 的写出
1024000 字节 (1.0 MB) 已复制,0.00393117 秒,260 MB/秒
lee@lee-laptop:/media/sda6/LVM-test$ ls
file2.img file.img
将之设置为loop设备
lee@lee-laptop:/media/sda6/LVM-test$ sudo losetup /dev/loop0 file.img
[sudo] password for lee:
lee@lee-laptop:/media/sda6/LVM-test$ sudo losetup /dev/loop1 file2.img
建立一pv.
lee@lee-laptop:/media/sda6/LVM-test$ sudo pvcreate /dev/loop0 /dev/loop1
Physical volume "/dev/loop0" successfully created
Physical volume "/dev/loop1" successfully created
lee@lee-laptop:/media/sda6/LVM-test$ sudo pvdisplay
--- NEW Physical volume ---
PV Name /dev/loop0
VG Name
PV Size 1000.00 KB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID txf4xg-a2oe-1HLl-zcRh-hgNF-JK1D-IF45w3
--- NEW Physical volume ---
PV Name /dev/loop1
VG Name
PV Size 1000.00 KB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
建立卷组:
lee@lee-laptop:/media/sda6/LVM-test$ sudo vgcreate vg_test /dev/loop0 /dev/loop1
[sudo] password for lee:
Volume group "vg_test" successfully created
lee@lee-laptop:/media/sda6/LVM-test$ sudo vgdisplay
--- Volume group ---
VG Name vg_test
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 16.00 MB
PE Size 4.00 MB
Total PE 4
Alloc PE / Size 0 / 0
Free PE / Size 4 / 16.00 MB
VG UUID 93zU2l-oL5g-zWvz-oJmj-3U9A-O7y4-sTvKbT
激活刚刚建立的vg_test卷组
lee@lee-laptop:/media/sda6/LVM-test$ sudo vgchange -a y vg_test
0 logical volume(s) in volume group "vg_test" now active
在vg_test的基础上建立逻辑卷lv_test1和lv_test2
lee@lee-laptop:/media/sda6/LVM-test$ sudo lvcreate -L5M -nlv_test2 vg_test
Rounding up size to full physical extent 8.00 MB
Logical volume "lv_test2" created
lee@lee-laptop:/media/sda6/LVM-test$ sudo lvdisplay
--- Logical volume ---
LV Name /dev/vg_test/lv_test1
VG Name vg_test
LV UUID rL1KVN-cg6H-mQgi-hsyU-GiSU-Ndjm-I2Cz86
LV Write Access read/write
LV Status available
# open 0
LV Size 8.00 MB
Current LE 2
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:0
--- Logical volume ---
LV Name /dev/vg_test/lv_test2
VG Name vg_test
LV UUID QsdveI-XKww-yUNN-lQMZ-DkFi-DSym-hLONO7
LV Write Access read/write
LV Status available
# open 0
LV Size 8.00 MB
Current LE 2
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 254:1
到此,两个5M的逻辑卷就好了,格式化它看看输出情况:
lee@lee-laptop:/media/sda6/LVM-test$ mkdir test
lee@lee-laptop:/media/sda6/LVM-test$ sudo mount /dev/vg_test/lv_test1 /media/sda6/LVM-test/test
lee@lee-laptop:/media/sda6/LVM-test$ mount
/dev/sda2 on / type ext3 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
/sys on /sys type sysfs (rw,noexec,nosuid,nodev)
varrun on /var/run type tmpfs (rw,noexec,nosuid,nodev,mode=0755)
varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)
udev on /dev type tmpfs (rw,mode=0755)
devshm on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
lrm on /lib/modules/2.6.22-14-generic/volatile type tmpfs (rw)
/dev/sda1 on /media/sda1 type vfat (rw,utf8)
/dev/sda3 on /media/sda3 type ext3 (rw)
/dev/sda6 on /media/sda6 type ext3 (rw)
/dev/sda7 on /media/sda7 type ext3 (rw)
securityfs on /sys/kernel/security type securityfs (rw)
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
/dev/mapper/vg_test-lv_test1 on /media/sda6/LVM-test/test type ext3 (rw)
lee@lee-laptop:/media/sda6/LVM-test$ cd test
lee@lee-laptop:/media/sda6/LVM-test/test$ pwd
/media/sda6/LVM-test/test
lee@lee-laptop:/media/sda6/LVM-test/test$ ls
lost+found
lee@lee-laptop:/media/sda6/LVM-test/test$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 6.5G 4.4G 1.8G 72% /
varrun 248M 100K 248M 1% /var/run
varlock 248M 0 248M 0% /var/lock
udev 248M 104K 248M 1% /dev
devshm 248M 0 248M 0% /dev/shm
lrm 248M 34M 214M 14% /lib/modules/2.6.22-14-generic/volatile
/dev/sda1 6.9G 5.8G 1.2G 84% /media/sda1
/dev/sda3 8.2G 7.3G 424M 95% /media/sda3
/dev/sda6 8.7G 7.1G 1.2G 87% /media/sda6
/dev/sda7 5.6G 4.8G 515M 91% /media/sda7
/dev/mapper/vg_test-lv_test1
7.8M 1.1M 6.3M 15% /media/sda6/LVM-test/test
到此为止,研究lvm的管理方式和运行原理,将在缺少磁盘的情况下,任意的玩!
阅读(3396) | 评论(0) | 转发(0) |