Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1185073
  • 博文数量: 128
  • 博客积分: 10010
  • 博客等级: 上将
  • 技术积分: 4870
  • 用 户 组: 普通用户
  • 注册时间: 2007-04-19 14:28
文章分类

全部博文(128)

文章存档

2010年(2)

2009年(22)

2008年(104)

我的朋友

分类: LINUX

2009-03-24 20:42:07

rhel5 LVM应用之如何缩小LVM
 
先创建两个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 ~]# mkfs.ext3 /dev/mapper/tools-lv2
[root@server4 ~]# mkdir /lv1;mkdir /lv2
[root@server4 ~]# mount /dev/mapper/tools-lv1 /lv1/
[root@server4 ~]# mount /dev/mapper/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    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                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           kscreensaver         ppp                smtp.sendmail  system-config-language
之前复制的数据都还存在的,这就OK了!
 
阅读(2657) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-04-26 16:13:01

不过没有每一步的注解,我自己搞吧!

chinaunix网友2009-04-26 16:12:32

不错不错! 一直没有找到缩小成功的方法,今个找到了,谢谢。