lvm

[root@localhost ~]# fdisk /dev/sda
[root@localhost ~]# partprobe
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1         123      987966   83  Linux
/dev/sda4             124        1044     7397932+   5  Extended
/dev/sda5             124         246      987966   83  Linux
/dev/sda6             247         369      987966   83  Linux
/dev/sda7             370         492      987966   83  Linux
/dev/sda8             493         615      987966   83  Linux
===============创建PV============
[root@localhost ~]# pvcreate /dev/sda{5,6,7}
[root@localhost ~]# pvscan ====》列出系统中所有的PV及每个pv的信息
  PV /dev/sda5                      lvm2 [964.81 MB]
  PV /dev/sda6                      lvm2 [964.81 MB]
  PV /dev/sda7                      lvm2 [964.81 MB]
  Total: 3 [2.83 GB] / in use: 0 [0   ] / in no VG: 3 [2.83 GB]
     PV总容量                        /已经被vg使用的pv的量   /剩余的pv量
==============创建VG==============
[root@localhost ~]# vgcreate -s PE的大小(m,g,t)
[root@localhost ~]# vgcreate -s 16M vg01 /dev/sda{5,6,7}==》将sda5-7创建为vg01,并将PE大小指定为16M
  Volume group "vg01" successfully created
[root@localhost ~]# pvscan
  PV /dev/sda5   VG vg01   lvm2 [960.00 MB / 960.00 MB free]
  PV /dev/sda6   VG vg01   lvm2 [960.00 MB / 960.00 MB free]
  PV /dev/sda7   VG vg01   lvm2 [960.00 MB / 960.00 MB free]
  Total: 3 [2.81 GB] / in use: 3 [2.81 GB] / in no VG: 0 [0   ]
[root@localhost ~]# vgscan ==》vg已经创建成功
  Reading all physical volumes.  This may take a while...
  Found volume group "vg01" using metadata type lvm2
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg01
  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               2.81 GB ======>vg的大小
  PE Size               16.00 MB======>pe的大小
  Total PE              180     ======>pe的个数
  Alloc PE / Size       0 / 0   ======>已经使用的pe(因为还没有创建lvm,所以pe没有被使用 )
  Free  PE / Size       180 / 2.81 GB====>剩余的pe量
  VG UUID               PUMago-bU01-4oaG-p5iV-1eU2-Vs0I-qXtGhR
[root@localhost ~]# pvcreate /dev/sda8
  Physical volume "/dev/sda8" successfully created
[root@localhost ~]# vgextend vg01 /dev/sda8
  Volume group "vg01" successfully extended
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg01
  System ID            
  Format                lvm2
  Metadata Areas        4
  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                4
  Act PV                4
  VG Size               3.75 GB
  PE Size               16.00 MB
  Total PE              240
  Alloc PE / Size       0 / 0  
 Free  PE / Size       240 / 3.75 GB
  VG UUID               PUMago-bU01-4oaG-p5iV-1eU2-Vs0I-qXtGhR
============创建LV=================
[root@localhost ~]# lvcreate -L [lv大小(M,G,T)] -n [lv name] VGname
[root@localhost ~]# lvcreate -l [PEnumber] -n [lv name] VGname
[root@localhost ~]# lvcreate -L +1G -n lv01 vg01
  Logical volume "lv01" created
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                1.00 GB
  Current LE             64
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
[root@localhost ~]# mkfs -t ext3 /dev/vg01/lv01
[root@localhost ~]# mount /dev/vg01/lv01 /mnt/lvm
[root@localhost ~]# df -hT
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/hda2     ext3    7.6G  2.8G  4.5G  38% /
/dev/hda5     ext3    3.6G  154M  3.2G   5% /var
/dev/hda3     ext3    3.8G   72M  3.6G   2% /home
/dev/hda1     ext3    2.9G   75M  2.7G   3% /boot
tmpfs        tmpfs    252M     0  252M   0% /dev/shm
/dev/mapper/vg01-lv01=====>LV使用的设备实际放在/dev/mapper/下
              ext3   1008M   34M  924M   4% /mnt/lvm
  
[root@localhost ~]# vgdisplay ===>创建LV后查看VG的详细信息
  --- Volume group ---
  VG Name               vg01
  System ID            
  Format                lvm2
  Metadata Areas        4
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                4
  Act PV                4
  VG Size               3.75 GB
  PE Size               16.00 MB
  Total PE              240
  Alloc PE / Size       64 / 1.00 GB
  Free  PE / Size       176 / 2.75 GB
  VG UUID               PUMago-bU01-4oaG-p5iV-1eU2-Vs0I-qXtGhR
[root@localhost ~]# lvresize -L +1G /dev/vg01/lv01 ====>扩容LV
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             128
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
[root@localhost ~]# dumpe2fs /dev/vg01/lv01 =====>查看系统内superblock记录情况
[root@localhost ~]# resize2fs -f(强制进行reszie) device
[root@localhost ~]# resize2fs /dev/vg01/lv01
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg01/lv01 is mounted on /mnt/lvm; on-line resizing required
Performing an on-line resize of /dev/vg01/lv01 to 524288 (4k) blocks.
The filesystem on /dev/vg01/lv01 is now 524288 blocks long.
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             128
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
===========LVM快照 ============
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               vg01
     ........................................
  VG Size               3.75 GB
  PE Size               16.00 MB
  Total PE              240
  Alloc PE / Size       128 / 2.00 GB
  Free  PE / Size       112 / 1.75 GB
  VG UUID               PUMago-bU01-4oaG-p5iV-1eU2-Vs0I-qXtGhR
[root@localhost ~]# lvcreate -l 100 -s -n lvshot /dev/vg01/lv01
  Logical volume "lvshot" created
[root@localhost ~]# lvcreate -l[指定PE数量] 100 -s[代表创建快照] -n[快照名称] lvshot /dev/vg01/lv01[LVname]
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV snapshot status     source of
                         /dev/vg01/lvshot [active]
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             128
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/vg01/lvshot
  VG Name                vg01
  LV UUID                osWSF0-e4Oe-RUWF-qrKP-LokN-sYYb-2R9dLp
  LV Write Access        read/write
  LV snapshot status     active destination for /dev/vg01/lv01
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             128
  COW-table size         1.56 GB
  COW-table LE           100
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KB
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
[root@localhost ~]# lvremove /dev/vg01/lvshot
Do you really want to remove active logical volume lvshot? [y/n]: y
  Logical volume "lvshot" successfully removed
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             128
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
[root@localhost ~]# cp /etc/passwd /mnt/lvm/
[root@localhost ~]# ll /mnt/lvm/
总计 24
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost ~]# cp /var/log/messages /mnt/lvm/
[root@localhost ~]# ll /mnt/lvm/
总计 120
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw------- 1 root root 88047 11-23 09:05 messages
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost ~]# mkdir /tmp/lvshot
[root@localhost ~]# lvcreate -l 100 -s -n lvshot /dev/vg01/lv01
  Logical volume "lvshot" created
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg01/lv01
  VG Name                vg01
  LV UUID                4Oj1a0-hZ30-LJjO-KThx-09Qw-jos0-DfOPV1
  LV Write Access        read/write
  LV snapshot status     source of
                         /dev/vg01/lvshot [active]
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             128
  Segments               3
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/vg01/lvshot
  VG Name                vg01
  LV UUID                YZbnH1-aD32-vJT9-lfyS-0JkB-n00X-LGsEP1
  LV Write Access        read/write
  LV snapshot status     active destination for /dev/vg01/lv01
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             128
  COW-table size         1.56 GB
  COW-table LE           100
  Allocated to snapshot  0.00%
  Snapshot chunk size    4.00 KB
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
[root@localhost ~]# mount /dev/vg01/lvshot /tmp/lvshot/
[root@localhost ~]# ll /tmp/lvshot/
总计 120
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw------- 1 root root 88047 11-23 09:05 messages
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost ~]# df -hT
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/hda2     ext3    7.6G  2.8G  4.5G  38% /
/dev/hda5     ext3    3.6G  154M  3.2G   5% /var
/dev/hda3     ext3    3.8G   72M  3.6G   2% /home
/dev/hda1     ext3    2.9G   75M  2.7G   3% /boot
tmpfs        tmpfs    252M     0  252M   0% /dev/shm
/dev/mapper/vg01-lv01
              ext3    2.0G   34M  1.9G   2% /mnt/lvm
/dev/mapper/vg01-lvshot
              ext3    2.0G   34M  1.9G   2% /tmp/lvshot
[root@localhost ~]# umount /tmp/lvshot/
[root@localhost ~]# df -hT
文件系统      类型    容量  已用 可用 已用% 挂载点
/dev/hda2     ext3    7.6G  2.8G  4.5G  38% /
/dev/hda5     ext3    3.6G  154M  3.2G   5% /var
/dev/hda3     ext3    3.8G   72M  3.6G   2% /home
/dev/hda1     ext3    2.9G   75M  2.7G   3% /boot
tmpfs        tmpfs    252M     0  252M   0% /dev/shm
/dev/mapper/vg01-lv01
              ext3    2.0G   34M  1.9G   2% /mnt/lvm
[root@localhost ~]# rm -rf /mnt/lvm/messages
[root@localhost ~]# ll /mnt/lvm/
总计 24
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost ~]# cp /proc/cpuinfo /mnt/lvm/
[root@localhost ~]# ll /mnt/lvm/
总计 32
-r--r--r-- 1 root root   590 11-23 09:11 cpuinfo
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost ~]# lvdisplay /dev/vg01/lvshot
  --- Logical volume ---
  LV Name                /dev/vg01/lvshot
  VG Name                vg01
  LV UUID                YZbnH1-aD32-vJT9-lfyS-0JkB-n00X-LGsEP1
  LV Write Access        read/write
  LV snapshot status     active destination for /dev/vg01/lv01
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             128
  COW-table size         1.56 GB
  COW-table LE           100
  Allocated to snapshot  0.01%
  Snapshot chunk size    4.00 KB
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
  
[root@localhost ~]# mkdir -p /backup
[root@localhost ~]# mount /dev/vg01/lvshot /tmp/lvshot/
[root@localhost ~]# cd /tmp/lvshot/
[root@localhost lvshot]# ll
总计 120
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw------- 1 root root 88047 11-23 09:05 messages
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
[root@localhost lvshot]#  tar -czf  /backup/lvshot.tar.gz  ./*
[root@localhost lvshot]# ll /backup/
总计 44
-rw-r--r-- 1 root root 39320 11-23 09:18 lvshot.tar.gz
[root@localhost lvshot]# tar -tf /backup/lvshot.tar.gz
./-f
./lost+found/
./messages
./passwd
[root@localhost lvshot]# umount /tmp/lvshot/
umount: /tmp/lvshot: device is busy
umount: /tmp/lvshot: device is busy
[root@localhost lvshot]# cd
[root@localhost ~]# umount /tmp/lvshot/
[root@localhost ~]# lvremove /dev/vg01/lvshot
Do you really want to remove active logical volume lvshot? [y/n]: y
  Logical volume "lvshot" successfully removed
[root@localhost ~]# umount /mnt/lvm/
[root@localhost ~]# mkfs -t ext3 /dev/vg01/lv01
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
Writing inode tables: done                           
Creating journal (16384 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.
[root@localhost ~]# mount /dev/vg01/lv01 /mnt/lvm/
[root@localhost ~]# ll /mnt/lvm/
总计 16
drwx------ 2 root root 16384 11-23 09:19 lost+found
[root@localhost ~]# tar -zxf /backup/lvshot.tar.gz -C /mnt/lvm/
[root@localhost ~]# ll /mnt/lvm/
总计 144
-rw-r--r-- 1 root root 19013 11-23 09:18 -f
drwx------ 2 root root 16384 11-23 08:40 lost+found
-rw------- 1 root root 88047 11-23 09:05 messages
-rw-r--r-- 1 root root  1601 11-23 09:05 passwd
===========history==========
  72  fdisk /dev/sda
   74  partprobe 
   76  fdisk -l /dev/sda
   77  pvcreate /dev/sda{5,6,7}
   78  pvscan
   79  pvdisplay 
   84  vgcreate -s 16M vg01 /dev/sda{5,6,7}
   85  vgscan
   86  vgdisplay 
    90  pvcreate /dev/sda8
   91  vgextend vg01 /dev/sda8
   92  vgdisplay
   93  lvcreate -L +1G -n lv01 vg01
   94  lvdisplay
   95  vgdisplay
   96  mkdir -p /mnt/lvm
   97  ll /mnt/lvm
   98  mkfs -t ext3 /dev/vg01/lv01
   99  mount /dev/vg01/lv01 /mnt/lvm
  100  df -hT
  101  lvresize -L +1G /dev/vg01/lv01
  102  lvdisplay
  103  dumpe2fs /dev/vg01/lv01
  104  resize2fs /dev/vg01/lv01
  105  df /mnt/lvm/
  106  lvdisplay
  107  vgdisplay 
  112  cp /etc/passwd /mnt/lvm/
  113  ll /mnt/lvm/
  114  cp /var/log/messages /mnt/lvm/
  115  ll /mnt/lvm/
  116  mkdir /tmp/lvshot
  117  lvcreate -l 100 -s -n lvshot /dev/vg01/lv01
  118  lvdisplay
  119  mount /dev/vg01/lvshot /tmp/lvshot/
  120  ll /tmp/lvshot/
  121  df -hT
  122  umount /tmp/lvshot/
  123  df -hT
  124  rm -rf /mnt/lvm/messages
  125  ll /mnt/lvm/
  126  cp /proc/cpuinfo /mnt/lvm/
  127  ll /mnt/lvm/
  128  lvdisplay /dev/vg01/lvshot
  129  mkdir -p /backup
  130  mount /dev/vg01/lvshot /tmp/lvshot/
  131  cd /tmp/lvshot/
  132  ll
  145   tar -czf -f /backup/lvshot.tar.gz  ./*
  146  ll /backup/
  147   tar -czf  /backup/lvshot.tar.gz  ./*
  148  ll /backup/
  149  tar -tf /backup/lvshot.tar.gz
  150  umount /tmp/lvshot/
  151  cd
  152  umount /tmp/lvshot/
  153  lvremove /dev/vg01/lvshot
  154  umount /mnt/lvm/
  155  mkfs -t ext3 /dev/vg01/lv01
  156  mount /dev/vg01/lv01 /mnt/lvm/
  157  ll /mnt/lvm/
  158  tar -zxf /backup/lvshot.tar.gz -C /mnt/lvm/
  159  ll /mnt/lvm/

你可能感兴趣的:(职场,休闲,lvm快照)