Chinaunix首页 | 论坛 | 博客
  • 博客访问: 410626
  • 博文数量: 119
  • 博客积分: 25
  • 博客等级: 民兵
  • 技术积分: 1061
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-14 12:48
个人简介

醉心于技术。

文章分类

全部博文(119)

文章存档

2018年(34)

2016年(1)

2015年(4)

2014年(6)

2013年(74)

我的朋友

分类: 系统运维

2013-09-28 11:00:26

来源:

先创建两个LVM:
[root@server4 ~]# lvcreate -L 150M tools -n lv1
  Rounding up size to full physical extent 152.00 MB
  Logical volume "lv1" created

[root@server4 ~]# lvcreate -L 200M tools -n lv2
  Logical volume "lv2" created

[root@server4 ~]# lvs
  LV    VG    Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv1   tools -wi-a- 152.00M                                     
  lv2   tools -wi-a- 200.00M                                     
  tools tools -wi-ao 600.00M      
[root@server4 ~]# mkfs.ext3 /dev/mapper/tools-lv2

[root@server4 ~]# mkdir /lv1;mkdir /lv2
[root@server4 ~]# mount /dev/mapper/tools-lv1 /lv1/

[root@server4 ~]# df
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3    8.7G  3.1G  5.1G  38% /
/dev/sda1     ext3     99M   12M   83M  12% /boot
tmpfs        tmpfs     97M     0   97M   0% /dev/shm
/dev/md0      ext3    3.8G   72M  3.6G   2% /home
/dev/mapper/tools-tools
              ext3    582M   11M  548M   2% /tools
/dev/hdc   iso9660    2.9G  2.9G     0 100% /media/cdrom
/dev/mapper/tools-lv1
              ext3    148M  5.6M  135M   4% /lv1
/dev/mapper/tools-lv2
              ext3    194M  5.6M  179M   4% /lv2
lv2的大小为200M,lv1的大小是150M,下来把lv2的大小缩小为100M,如下所示:
[root@server4 /]# cp /etc/resolv.conf /lv2/

[root@server4 /]# cp /etc/pam.d/* /lv2/
[root@server4 /]# ls /lv2
atd               gdm                  kshell             pup            sshd                          system-config-lvm
authconfig        gdm-autologin        login              reboot         su                            system-config-netboot
authconfig-gtk    gdmsetup             lost+found         remote         sudo                          system-config-network
authconfig-tui    gnome-screensaver    neat               resolv.conf    sudo-i                        system-config-network-cmd
chfn              gnome-system-log     newrole            rhn_register   su-l                          system-config-printer
chsh              gssftp               other              run_init       system-auth                   system-config-rootpassword
config-util       halt                 passwd             runuser        system-auth-ac                system-config-securitylevel
cpufreq-selector  kbdrate              pirut              runuser-l      system-cdinstall-helper       system-config-selinux
crond             kcheckpass           pm-hibernate       sabayon        system-config-authentication  system-config-services
cups              kdm                  pm-powersave       screen         system-config-date            system-config-soundcard
cvs               kdm-np               pm-suspend         serviceconf    system-config-display         system-config-time
dateconfig        klaptop_acpi_helper  pm-suspend-hybrid  setup          system-config-kdump           system-config-users
eject             kppp                 poweroff           smtp           system-config-keyboard        system-install-packages
ekshell           kscreensaver         ppp            &n
bsp;   smtp.sendmail  system-config-language
[root@server4 /]# umount /lv2
[root@server4 /]# lvresize -L 200M /dev/tools/lv2
  New size (50 extents) matches existing size (50 extents)
  Run `lvresize --help' for more information.

[root@server4 /]# e2fsck -f /dev/tools/lv2
e2fsck 1.39 (29-May-2006)
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/tools/lv2: 93/51200 files (2.2% non-contiguous), 12212/204800 blocks
[root@server4 /]# resize2fs /dev/tools/lv2 100M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/tools/lv2 to 102400 (1k) blocks.
The filesystem on /dev/tools/lv2 is now 102400 blocks long.
[root@server4 /]# lvresize -L 100M /dev/tools/lv2
  /dev/cdrom: open failed: Read-only file system
  WARNING: Reducing active logical volume to 100.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv2? [y/n]: y
  Reducing logical volume lv2 to 100.00 MB
  Logical volume lv2 successfully resized

[root@server4 /]# e2fsck -f /dev/tools/lv2
e2fsck 1.39 (29-May-2006)
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/tools/lv2: 93/26624 files (2.2% non-contiguous), 9116/102400 blocks
[root@server4 /]# mount /dev/tools/lv2 /lv2/

[root@server4 /]# df
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/sda2     ext3    8.7G  3.1G  5.1G  38% /
/dev/sda1     ext3     99M   12M   83M  12% /boot
tmpfs        tmpfs     97M     0   97M   0% /dev/shm
/dev/md0      ext3    3.8G   72M  3.6G   2% /home
/dev/mapper/tools-tools
              ext3    582M   11M  548M   2% /tools
/dev/hdc   iso9660    2.9G  2.9G     0 100% /media/cdrom
/dev/mapper/tools-lv1
              ext3    148M  5.6M  135M   4% /lv1
/dev/mapper/tools-lv2
              ext3     97M  5.7M   87M   7% /lv2
[root@server4 /]# ls lv2/
atd               gdm                  kshell             pup            sshd                          system-config-lvm
authconfig        gdm-autologin        login              reboot         su                            system-config-netboot
authconfig-gtk    gdmsetup             lost+found         remote         sudo                          system-config-network
authconfig-tui    gnome-screensaver    neat               resolv.conf    sudo-i                        system-config-network-cmd
chfn              gnome-system-log     newrole            rhn_register   su-l                          system-config-printer
chsh              gssftp               other              run_init       system-auth                   system-config-rootpassword
config-util       halt                 passwd             runuser        system-auth-ac                system-config-securitylevel
cpufreq-selector  kbdrate              pirut              runuser-l      system-cdinstall-helper       system-config-selinux
crond             kcheckpass           pm-hibernate       sabayon        system-config-authentication  system-config-services
cups              kdm                  pm-powersave       screen         system-config-date            system-config-soundcard
cvs               kdm-np               pm-suspend         serviceconf    system-config-display         system-config-time
dateconfig        klaptop_acpi_helper  pm-suspend-hybrid  setup          system-config-kdump           system-config-users
eject             kppp                 poweroff           smtp           system-config-keyboard        system-install-packages
ekshell      &nb
sp;    kscreensaver         ppp                smtp.sendmail  system-config-language
之前复制的数据都还存在的,这就OK了!

LVM逻辑卷的拉伸与缩小

逻辑卷可以实现动态在线拉伸,扩展一个逻辑卷的空间不需要卸载文件系统,拉伸一个逻辑卷的步骤如下:

  1. 保证卷组中有足够空闲空间:vgdisplay
  2. 扩充指定逻辑卷空间:lvextend -L +10G /dev/linuxcast-vg/mylv
  3. 更新文件系统:resize2fs /dev/linuxcast-vg/mylv
  4. 查看更新后的文件系统:df -h

拉伸一个卷组:

  1. 将要添加到卷组中的磁盘格式化为物理卷:pvcreate /dev/sdc
  2. 将磁盘添加到指定卷组中:vgextend linuxcast-vg /dev/sdc
  3. 查看扩充后大小:vgdisplay

逻辑卷可以动态缩小,但是缩小操作必须使逻辑卷离线,也就是卸载,缩小一个逻辑卷步骤如下:

  1. 卸载该逻辑卷:umount /dev/lnuxcast-lv/mylv
  2. 缩小文件系统:resize2fs /dev/linuxcast-lv/mylv 10G 
  3. 缩小逻辑卷大小:lvreduce -L -5G /dev/linuxcast-lv/mylv
  4. 查看缩小后大小:lvdisplay
  5. 挂载使用:mount /dev/linuxcast-lv/mylv /mnt

缩小一个卷组:

  1. 将一个磁盘移出一个卷组:vgreduce linuxcast-lv /dev/sdc
  2. 查看缩小后卷组大小:vgdisplay

阅读(4864) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~