RAID:


级别:仅代表磁盘组织方式不同,没有上下之分;
0: 条带
 性能提升: 读,写
 冗余能力(容错能力): 无
 空间利用率:nS
 至少2块盘
1: 镜像
 性能表现:写性能下降,读性能提升
 冗余能力:有
 空间利用率:1/2
 至少2块盘
2:
3
4: 校验码;校验码盘IO成为瓶颈
5: 轮流校验盘
 性能表现:读,写提升
 冗余能力:有
 空间利用率:(n-1)/n
 至少需要3块
10(先镜像,后条带;最常用模式):
 性能表现:读、写提升
 冗余能力:有
 空间利用率:1/2
 至少需要4块
01(先条带,后镜像;备份开销大):
 性能表现:读、写提升
 冗余能力:有
 空间利用率:1/2
 至少需要4块
50:
 性能表现:读、写提升
 冗余能力:有
 空间利用率:(n-2)/n
    至少需要6块
jbod:
 性能表现:无提升
 冗余能力:无
 空间利用率:100%
 至少需要2块




创建逻辑RIAD:硬件级别数据备份
/dev/md0
/dev/md1


md: 内核模块
mdadm: shell命令,将任何块设备做成RAID;不同磁盘上的分区进行


模式化的命令:
 创建模式
  -C
   专用选项:
    -l: 级别
    -n #: 设备个数
    -a {yes|no}: 是否自动为其创建设备文件
    -c: CHUNK大小, 2^n,默认为64K
    -x #: 指定空闲盘个数
 管理模式
  --add, --remove, --fail
  mdadm /dev/md# --fail /dev/sda7
 监控模式
  -F
 增长模式
  -G
 装配模式
  -A


练习:创建

RAID0
 2G:
  4: 512MB
  2: 1G


Command (m for help): t  (调整分区类型)
Partition number (1-10): 9
Hex code (type L to list codes): fd
Changed system type of partition 9 to fd (Linux raid autodetect)


Command (m for help): t
Partition number (1-10): 10
Hex code (type L to list codes): fd
Changed system type of partition 10 to fd (Linux raid autodetect)


Command (m for help): p


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x31e2db75


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263        2610    18860310    5  Extended
/dev/sdb5             263         524     2104483+  83  Linux
/dev/sdb6             525        1178     5253223+  83  Linux
/dev/sdb7            1179        1310     1060258+  83  Linux
/dev/sdb8            1311        1442     1060258+  82  Linux swap / Solaris
/dev/sdb9            1443        1574     1060258+  fd  Linux raid autodetect
/dev/sdb10           1575        1706     1060258+  fd  Linux raid autodetect


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#

[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sdb{9,10}   (使用两个盘sdb9/sdb10 创建raid0模式硬盘md0)
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# cat /proc/mdstat   查看所有启动的raid设备
Personalities : [raid0]
md0 : active raid0 sdb10[1] sdb9[0]
      2117632 blocks super 1.2 512k chunks
     
unused devices: <none>
[root@localhost ~]#

[root@localhost ~]# mke2fs -j /dev/md0 (md0创建文件系统ext3)
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
132464 inodes, 529408 blocks
26470 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=545259520
17 block groups
32768 blocks per group, 32768 fragments per group
7792 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 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]#

[root@localhost ~]# fdisk -l (查看硬盘分区)


Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0004cc30


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2350    18566144   83  Linux
/dev/sda3            2350        2611     2097152   82  Linux swap / Solaris


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x31e2db75


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263        2610    18860310    5  Extended
/dev/sdb5             263         524     2104483+  83  Linux
/dev/sdb6             525        1178     5253223+  83  Linux
/dev/sdb7            1179        1310     1060258+  83  Linux
/dev/sdb8            1311        1442     1060258+  82  Linux swap / Solaris
/dev/sdb9            1443        1574     1060258+  fd  Linux raid autodetect
/dev/sdb10           1575        1706     1060258+  fd  Linux raid autodetect


Disk /dev/md0: 2168 MB, 2168455168 bytes
2 heads, 4 sectors/track, 529408 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk identifier: 0x00000000


[root@localhost ~]#
[root@localhost ~]# mount /dev/md0 /mnt/
[root@localhost ~]# ls /mnt/
lost+found (硬盘挂载成功

root@localhost ~]#




查看RAID阵列的详细信息
mdadm -D /dev/md#
 --detail

[root@localhost ~]# mdadm -D /dev/md0  (查看raid相关信息,或者mdadm --detail /dev/md127)
mdadm: cannot open /dev/md0: No such file or directory
[root@localhost ~]# mdadm -D /dev/md127
/dev/md127:
        Version : 1.2
  Creation Time : Fri Feb 24 22:51:00 2017
     Raid Level : raid0
     Array Size : 2117632 (2.02 GiB 2.17 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent


    Update Time : Fri Feb 24 22:51:00 2017
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0


     Chunk Size : 512K


           Name : localhost:0  (local to host localhost)
           UUID : ed1ec896:779ae712:b5496c27:f941c3d0
         Events : 0


    Number   Major   Minor   RaidDevice State
       0       8       25        0      active sync   /dev/sdb9
       1       8       26        1      active sync   /dev/sdb10
[root@localhost ~]#


   
watch: 周期性地执行指定命令,并以全屏方式显示结果
 -n #:指定周期长度,单位为秒,默认为2
格式: watch -n # 'COMMAND'
 
将当前RAID信息保存至配置文件,以便以后进行装配:
mdamd -D --scan > /etc/mdadm.conf

[root@localhost ~]# mdadm -D --scan
ARRAY /dev/md/localhost:0 metadata=1.2 name=localhost:0 UUID=ed1ec896:779ae712:b5496c27:f941c3d0
[root@localhost ~]#


RAID5:
 2G: 3, 1G




DM: Device Mapper
 逻辑设备
  RAID, LVM2
  
DM: LVM2
 快照:实现数据备份

 动态扩展硬盘空间
 多路径


linux卷管理

http://blog.csdn.net/wuweilong/article/details/7565530



创建PV

Command (m for help): t
Partition number (1-13): 7
Hex code (type L to list codes): 8e (PV类型)
Changed system type of partition 7 to 8e (Linux LVM)


Command (m for help): t
Partition number (1-13): 8
Hex code (type L to list codes): 8e
Changed system type of partition 8 to 8e (Linux LVM)


Command (m for help): p


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x31e2db75


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263        2610    18860310    5  Extended
/dev/sdb5             263         524     2104483+  83  Linux
/dev/sdb6             525        1178     5253223+  8e  Linux LVM
/dev/sdb7            1179        1310     1060258+  8e  Linux LVM
/dev/sdb8            1311        1442     1060258+  8e  Linux LVM

/dev/sdb9            1443        1574     1060258+  fd  Linux raid autodetect
/dev/sdb10           1575        1706     1060258+  fd  Linux raid autodetect
/dev/sdb11           1707        1968     2104483+  fd  Linux raid autodetect
/dev/sdb12           1969        2230     2104483+  fd  Linux raid autodetect
/dev/sdb13           2231        2492     2104483+  fd  Linux raid autodetect


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 ~]# fdisk -l


Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0004cc30


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              39        2350    18566144   83  Linux
/dev/sda3            2350        2611     2097152   82  Linux swap / Solaris


Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x31e2db75


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         262     2104483+  83  Linux
/dev/sdb4             263        2610    18860310    5  Extended
/dev/sdb5             263         524     2104483+  83  Linux
/dev/sdb6             525        1178     5253223+  8e  Linux LVM
/dev/sdb7            1179        1310     1060258+  8e  Linux LVM
/dev/sdb8            1311        1442     1060258+  8e  Linux LVM
/dev/sdb9            1443        1574     1060258+  fd  Linux raid autodetect
/dev/sdb10           1575        1706     1060258+  fd  Linux raid autodetect
/dev/sdb11           1707        1968     2104483+  fd  Linux raid autodetect
/dev/sdb12           1969        2230     2104483+  fd  Linux raid autodetect
/dev/sdb13           2231        2492     2104483+  fd  Linux raid autodetect


Disk /dev/md127: 2168 MB, 2168455168 bytes
2 heads, 4 sectors/track, 529408 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 524288 bytes / 1048576 bytes
Disk identifier: 0x00000000


[root@localhost ~]#

[root@localhost ~]# pvcreate /dev/sdb7 /dev/sdb6  (创建PV)
  Physical volume "/dev/sdb7" successfully created
  Physical volume "/dev/sdb6" successfully created
[root@localhost ~]# pvs (简单查看PV信息)
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb6       lvm2 ---  5.01g 5.01g
  /dev/sdb7       lvm2 ---  1.01g 1.01g
[root@localhost ~]#

[root@localhost ~]# pvdisplay
  "/dev/sdb6" is a new physical volume of "5.01 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb6
  VG Name              
  PV Size               5.01 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               z1Mvsy-DMq8-ms3D-rmbS-i7ge-IErh-nBSzRU
  
  "/dev/sdb7" is a new physical volume of "1.01 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb7
  VG Name              
  PV Size               1.01 GiB
  Allocatable           NO
  PE Size               0  
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               JtgqEC-CJsi-aif0-BjxI-RP2I-TNQ2-w8ExTa
  
[root@localhost ~]#

[root@localhost ~]# pvscan  (当前系统所有PV)
  PV /dev/sdb6         lvm2 [5.01 GiB]
  PV /dev/sdb7         lvm2 [1.01 GiB]
  Total: 2 [6.02 GiB] / in use: 0 [0   ] / in no VG: 2 [6.02 GiB]
[root@localhost ~]#


创建vg

[root@localhost ~]# vgcreate myvg /dev/sdb6 /dev/sdb7  (创建myvg)
  Volume group "myvg" successfully created
[root@localhost ~]# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  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               6.02 GiB
  PE Size               4.00 MiB
  Total PE              1540
  Alloc PE / Size       0 / 0  
  Free  PE / Size       1540 / 6.02 GiB
  VG UUID               eMVIAZ-GOr5-Dqtd-5RHj-psXZ-UeFr-oBfMjc
  
[root@localhost ~]# pvdisplay /dev/sdb6  (查看vg)

  --- Physical volume ---
  PV Name               /dev/sdb6
  VG Name               myvg
  PV Size               5.01 GiB / not usable 2.10 MiB
  Allocatable           yes
  PE Size               4.00 MiB  (PE大小默认为4M)
  Total PE              1282
  Free PE               1282
  Allocated PE          0
  PV UUID               z1Mvsy-DMq8-ms3D-rmbS-i7ge-IErh-nBSzRU
  
[root@localhost ~]#



[root@localhost ~]# vgremove myvg (移除vg)
  Volume group "myvg" successfully removed
[root@localhost ~]# vgcreate -s 8M myvg /dev/sdb6 /dev/sdb7 (创建VG,PE设置为8M)
  Volume group "myvg" successfully created
  Skipping volume group myvg]
[root@localhost ~]# vgdisplay myvg
  --- Volume group ---
  VG Name               myvg
  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               6.02 GiB
  PE Size               8.00 MiB
  Total PE              770
  Alloc PE / Size       0 / 0  
  Free  PE / Size       770 / 6.02 GiB
  VG UUID               HxUuci-I1aU-qUTS-SDoV-Eagj-WGUw-MIfTdK
  
[root@localhost ~]#


[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb6  myvg lvm2 a--  5.01g 5.01g
  /dev/sdb7  myvg lvm2 a--  1.01g 1.01g
[root@localhost ~]# pvmove /dev/sdb7  (移除/dev/sdb7 pv中的数据)
  No data to move for myvg
[root@localhost ~]# vgreduce myvg /dev/sdb7 (将/devsdb7从myvg移除)
  Removed "/dev/sdb7" from volume group "myvg"
[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   1   0   0 wz--n- 5.01g 5.01g
[root@localhost ~]# pvs
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb6  myvg lvm2 a--  5.01g 5.01g
  /dev/sdb7       lvm2 ---  1.01g 1.01g
[root@localhost ~]#

[root@localhost ~]# vgextend myvg /dev/sdb7 (扩展vg中的数据)
  Volume group "myvg" successfully extended
[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   2   0   0 wz--n- 6.02g 6.02g
[root@localhost ~]#

[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   2   0   0 wz--n- 6.02g 6.02g
[root@localhost ~]# pvdisplay /dev/sdb6 (pv加入vg后,pe无法改变)
  --- Physical volume ---
  PV Name               /dev/sdb6
  VG Name               myvg
  PV Size               5.01 GiB / not usable 2.10 MiB
  Allocatable           yes
  PE Size               8.00 MiB
  Total PE              641
  Free PE               641
  Allocated PE          0
  PV UUID               z1Mvsy-DMq8-ms3D-rmbS-i7ge-IErh-nBSzRU
  
[root@localhost ~]#


创建lv

[root@localhost ~]# lvcreate -L 128M -n mylv myvg (创建128M的lv为mylv)
  Logical volume "mylv" created
[root@localhost ~]# lvs
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 128.00m                                                   
[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/myvg/mylv
  LV Name                mylv
  VG Name                myvg
  LV UUID                0ckBC6-VCtf-9V2N-m73K-NjfW-xD3r-9UuE0G
  LV Write Access        read/write
  LV Creation host, time localhost, 2017-02-25 18:27:45 -0800
  LV Status              available
  # open                 0
  LV Size                128.00 MiB
  Current LE             16
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
[root@localhost ~]# mke2fs -j /dev/myvg/mylv  (lv创建文件系统)
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
32768 inodes, 131072 blocks
6553 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
16 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
 8193, 24577, 40961, 57345, 73729


Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/myvg/mylv /mnt  (挂载lv设备)
[root@localhost ~]# ls /mnt/
lost+found
[root@localhost ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mnt type ext3 (rw)
[root@localhost ~]# ls /dev/mapper/  (lv设备实际目录)
control  myvg-mylv
[root@localhost ~]# ll -l /dev/myvg/
total 0
lrwxrwxrwx. 1 root root 7 Feb 25 18:29 mylv -> ../dm-0
[root@localhost ~]# ll -l /dev/myvg/mylv
lrwxrwxrwx. 1 root root 7 Feb 25 18:29 /dev/myvg/mylv -> ../dm-0

[root@localhost ~]# lvremove /dev/mapper/myvg-mylv  (先卸载lv设备,才能移除lv)
  Logical volume myvg/mylv contains a filesystem in use.
[root@localhost ~]# umount /mnt/ 
[root@localhost ~]# lvremove /dev/myvg/mylv
Do you really want to remove active logical volume mylv? [y/n]: y
  Logical volume "mylv" successfully removed
[root@localhost ~]# lvs
[root@localhost ~]#




不影响数据使用的前提下:

扩展lv(先扩展lv,再扩展fs),风险比较小

lvextend

resize2fs


[root@localhost ~]# lvcreate -L 2G -n mylv myvg (创建myvg,大小为2G)
  Logical volume "mylv" created
[root@localhost ~]# mke2fs -j /dev/myvg/mylv  (myvg创建文件系统)
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
131072 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
8192 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 ~]# mkdir /mydir
[root@localhost ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-a----- 2.00g                                                   
[root@localhost ~]# vim /etc/fstab  (自动挂载mylv)
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mydir type ext3 (rw)
[root@localhost ~]# cd /mydir/
[root@localhost mydir]# ll
total 16
drwx------. 2 root root 16384 Feb 25 19:04 lost+found
[root@localhost mydir]# cp /etc/inittab .
[root@localhost mydir]# cat inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[root@localhost mydir]# cd
[root@localhost ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              18G  3.1G   14G  19% /
tmpfs                 931M   72K  931M   1% /dev/shm
/dev/sda1             283M   33M  236M  13% /boot
/dev/mapper/myvg-mylv
                      2.0G   68M  1.9G   4% /mydir

[root@localhost ~]# lvextend -L 5G /dev/myvg/mylv  (在线扩展lv)
[root@localhost ~]# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  myvg   2   1   0 wz--n- 6.02g 4.02g
[root@localhost ~]# lvextend -L 5G /dev/myvg/mylv
  Size of logical volume myvg/mylv changed from 2.00 GiB (256 extents) to 5.00 GiB (640 extents).
  Logical volume mylv successfully resized
[root@localhost ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              18G  3.1G   14G  19% /
tmpfs                 931M   72K  931M   1% /dev/shm
/dev/sda1             283M   33M  236M  13% /boot
/dev/mapper/myvg-mylv
                      2.0G   68M  1.9G   4% /mydir
[root@localhost ~]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv myvg -wi-ao---- 5.00g                                                   
[root@localhost ~]# resize2fs -p /dev/myvg/mylv
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/myvg/mylv is mounted on /mydir; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/myvg/mylv to 1310720 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 1310720 blocks long.


[root@localhost ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              18G  3.1G   14G  19% /
tmpfs                 931M   72K  931M   1% /dev/shm
/dev/sda1             283M   33M  236M  13% /boot
/dev/mapper/myvg-mylv
                      5.0G   69M  4.7G   2% /mydir
[root@localhost ~]# cd /mydir/
[root@localhost mydir]# ll
total 20
-rw-r--r--. 1 root root   884 Feb 25 19:06 inittab
drwx------. 2 root root 16384 Feb 25 19:04 lost+found
[root@localhost mydir]# cat inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[root@localhost mydir]#




缩减lv(先缩减fs,再扩展lv)

注意:1、不能在线缩减,得先卸载;
   2、确保缩减后的空间大小依然能存储原有的所有数据;
   3、在缩减之前应该先强行检查文件,以确保文件系统处于一至性状态;


root@localhost mydir]# umount /mydir/
umount: /mydir: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@localhost mydir]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mydir type ext3 (rw)
[root@localhost mydir]# cd
[root@localhost ~]# umount /mydir/  (先卸载)
[root@localhost ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@localhost ~]# e2fsck -f /dev/myvg/mylv   (一致性检查)
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/myvg/mylv: 12/327680 files (0.0% non-contiguous), 38000/1310720 blocks
[root@localhost ~]# resize2fs /dev/myvg/mylv 3G  (缩减fs为3G)
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/mylv to 786432 (4k) blocks.
The filesystem on /dev/myvg/mylv is now 786432 blocks long.


[root@localhost ~]# lvreduce -L 3G /dev/myvg/mylv   (再缩减mylv为3G)
  WARNING: Reducing active logical volume to 3.00 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce mylv? [y/n]: y
  Size of logical volume myvg/mylv changed from 5.00 GiB (640 extents) to 3.00 GiB (384 extents).
  Logical volume mylv successfully resized
[root@localhost ~]# mount -a
[root@localhost ~]# mount
/dev/sda2 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/mapper/myvg-mylv on /mydir type ext3 (rw)
[root@localhost ~]# df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              18G  3.1G   14G  19% /
tmpfs                 931M   72K  931M   1% /dev/shm
/dev/sda1             283M   33M  236M  13% /boot
/dev/mapper/myvg-mylv
                      3.0G   68M  2.8G   3% /mydir

[root@localhost ~]# cd /mydir/
[root@localhost mydir]# cat inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[root@localhost mydir]#


快照卷常用于数据备份

[root@localhost ~]# lvcreate -L 128M -n mysnap -s -p r /dev/myvg/mylv  (创建mysnap,大小为128M)
  Logical volume "mysnap" created
[root@localhost ~]# lvs
  LV     VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  mylv   myvg owi-aos---   3.00g                                                   
  mysnap myvg sri-a-s--- 128.00m      mylv   0.01                                  
[root@localhost ~]# mount /dev/myvg/mysnap /mnt/  (挂载mysnap)
mount: block device /dev/mapper/myvg-mysnap is write-protected, mounting read-only

[root@localhost ~]# ll /mnt/
total 20
-rw-r--r--. 1 root root   884 Feb 25 19:06 inittab
drwx------. 2 root root 16384 Feb 25 19:04 lost+found
[root@localhost ~]# cat inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
[root@localhost ~]#

[root@localhost ~]# tar jcf /tmp/mydir.tar.bz2 inittab (备份mysnap中数据)
[root@localhost ~]# umount /mnt/
[root@localhost ~]# lvremove /dev/myvg/mysnap  (移除快照mysnap)
Do you really want to remove active logical volume mysnap? [y/n]: y  
  Logical volume "mysnap" successfully removed
[root@localhost ~]# cd /mydir/
[root@localhost mydir]# ll
total 20
-rw-r--r--. 1 root root   884 Feb 25 19:06 inittab
drwx------. 2 root root 16384 Feb 25 19:04 lost+found
[root@localhost mydir]# rm inittab  (数据丢失后,使用快照卷进行数据恢复)
rm: remove regular file `inittab'? y
[root@localhost mydir]# tar xf /tmp/mydir.tar.bz2 -C ./
[root@localhost mydir]# ll
total 20
-rw-r--r--. 1 root root   884 Feb 22 17:38 inittab
drwx------. 2 root root 16384 Feb 25 19:04 lost+found
[root@localhost mydir]#