虛擬機unbuntu的LVM實驗

先安裝完unbuntu虛擬機,然後選擇add device,加兩塊硬盤。

運行fdisk -l顯示硬盤信息,應該能看到三塊了,/dev/sda,/dev/sdb, /dev/sdc.

安裝lvm, sudo apt-get install lvm2。準備工作基本完成。

使用fdisk進行分區,分成/dev/sdb1, /dev/sdc1, m for help, t for change id, 8e = Linux LVM. 完成後如下:

nestor@nestor-desktop:~$ sudo fdisk -l

Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d09e6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        5580    44821318+  83  Linux
/dev/sda2            5581        9957    35158252+  83  Linux
/dev/sda3            9958       10443     3903795   82  Linux swap / Solaris

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x56ac033a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  8e  Linux LVM

Disk /dev/sdc: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x3c1fe419

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1        1305    10482381   8e  Linux LVM
 

接着就是LVM的配置,先上幾個概念:

PV: physical volumes

VG: volume groups

LV: logical volumes

 

將已有的物理分區映射到PV上,供VG管理:


nestor@nestor-desktop:~$ sudo pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created

nestor@nestor-desktop:~$ sudo pvscan
  PV /dev/sdb1         lvm2 [19.99 GB]
  PV /dev/sdc1         lvm2 [10.00 GB]
  Total: 2 [29.99 GB] / in use: 0 [0   ] / in no VG: 2 [29.99 GB]
nestor@nestor-desktop:~$ sudo pvdisplay /dev/sdc1
  --- NEW Physical volume ---
  PV Name               /dev/sdc1
  VG Name              
  PV Size               10.00 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               5MjNwr-7kdM-X0bD-hXq0-WBCt-iFDq-OeM3Yc
  

接着創建VG,包含需要的PV:

nestor@nestor-desktop:~$ sudo vgcreate VG1 /dev/sdc1 /dev/sdb1
  Volume group "VG1" successfully created
nestor@nestor-desktop:~$ vgscan
  Reading all physical volumes.  This may take a while...
  No volume groups found
nestor@nestor-desktop:~$ sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VG1" using metadata type lvm2

nestor@nestor-desktop:~$ sudo vgchange -a y VG1
  0 logical volume(s) in volume group "VG1" now active
nestor@nestor-desktop:~$ sudo vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "VG1" using metadata type lvm2
nestor@nestor-desktop:~$

 

然後就可以在VG上分配空間,創建不同大小的LV

nestor@nestor-desktop:~$ sudo lvcreate -L 500M -n LV1 VG1
  Logical volume "LV1" created
nestor@nestor-desktop:~$ sudo lvcreate -L 30000M -n LV3 VG1
  Logical volume "LV3" created
nestor@nestor-desktop:~$ sudo lvscan
  ACTIVE            '/dev/VG1/LV1' [500.00 MB] inherit
  ACTIVE            '/dev/VG1/LV3' [29.30 GB] inherit

格式化LV,創建和掛載LV:

nestor@nestor-desktop:~$ sudo mkfs -t ext3 /dev/VG1/LV1

nestor@nestor-desktop:~$ sudo mkdir /mnt/LV1
nestor@nestor-desktop:~$ sudo mkdir /mnt/LV3
nestor@nestor-desktop:~$
nestor@nestor-desktop:~$
nestor@nestor-desktop:~$ mount /dev/VG1/LV1 /mnt/LV1
mount: only root can do that
nestor@nestor-desktop:~$ sudo mount /dev/VG1/LV1 /mnt/LV1
nestor@nestor-desktop:~$ sudo mount /dev/VG1/LV3 /mnt/LV3

 

nestor@nestor-desktop:~$ sudo mount
/dev/sda1 on / type ext3 (rw,relatime,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.24-19-generic/volatile type tmpfs (rw)
/dev/sda2 on /home type ext3 (rw,relatime)
securityfs on /sys/kernel/security type securityfs (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
gvfs-fuse-daemon on /home/nestor/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=nestor)
/dev/mapper/VG1-LV1 on /mnt/LV1 type ext3 (rw)
/dev/mapper/VG1-LV3 on /mnt/LV3 type ext3 (rw)

雖然不知道之後可以做什麼,先記到這裏。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章