一、物理机添加一块新的硬盘方法(目的是把后加的磁盘直接加在现有的上面,不用再分区挂载)
1、首先要确定现有系统在那块盘上 [root@localhost ~]# df -lhFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root 50G 50G 0 100% /tmpfs 3.9G 0 3.9G 0% /dev/shm/dev/sdb1 485M 37M 424M 8% /boot/dev/mapper/VolGroup-lv_home 75G 7.9G 63G 12% /home从这些信息可以判断系统在sdb上2、分配新添加磁盘空间 给根目录加了50G 另外还有85G的空间没加,等以后不够的时候可以在加 这样灵活性比较高 用到的历史命令: 1019 2014-04-03 14:07:41 fdisk /dev/sda 1020 2014-04-03 14:08:07 partprobe 1023 2014-04-03 14:08:41 mkfs.ext4 /dev/sda 1025 2014-04-03 14:10:17 pvcreate /dev/sda 1028 2014-04-03 14:11:06 vgextend VolGroup /dev/sda 1030 2014-04-03 14:11:43 lvextend -L +50G /dev/mapper/VolGroup-lv_root 1031 2014-04-03 14:12:00 resize2fs -p /dev/VolGroup/lv_root 1032 2014-04-03 14:13:43 df -lh3、如果是虚拟机的话,历史命令如下mkfs.ext4 /dev/vdb pvcreate /dev/vdb vgextend vmvg /dev/vdblvextend -L +49G /dev/mapper/vmvg-rootresize2fs -p /dev/vmvg/root三、调整现有分区大小在使用Fedora13-x86_64过程中,发现系统分配给root用户lvm份额太少.[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root50G 11G 37G 23% /tmpfs 878M 100K 878M 1% /dev/shm/dev/sda1 485M 28M 432M 7% /boot/dev/mapper/VolGroup-lv_home406G 411M 385G 1% /home/dev/sdc 124M 107M 18M 86% /media/16F0-286F[root@localhost ~]#总共才50G,决定给它增加份额,现做好重要文件备份,以防万一.思路:先减掉VolGroup-lv_home的份额,再把减掉份额增加到VolGroup-lv_root.[root@localhost ~]# pvscanPV /dev/sda2 VG VolGroup lvm2 [465.25 GiB / 0 free]Total: 1 [465.25 GiB] / in use: 1 [465.25 GiB] / in no VG: 0 [0 ][root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 206Gresize2fs 1.41.10 (10-Feb-2009)Filesystem at /dev/mapper/VolGroup-lv_home is mounted on /home; on-line resizing requiredOn-line shrinking from 107954176 to 54001664 not supported.[root@localhost ~]# umount /home[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 206Gresize2fs 1.41.10 (10-Feb-2009)Please run 'e2fsck -f /dev/mapper/VolGroup-lv_home' first.[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_homee2fsck 1.41.10 (10-Feb-2009)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/mapper/VolGroup-lv_home: 1534/26992640 files (1.2% non-contiguous), 1799101/107954176 blocks[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 206Gresize2fs 1.41.10 (10-Feb-2009)Resizing the filesystem on /dev/mapper/VolGroup-lv_home to 54001664 (4k) blocks.Begin pass 3 (max = 3295)Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXThe filesystem on /dev/mapper/VolGroup-lv_home is now 54001664 blocks long.[root@localhost ~]# mount /home[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root50G 11G 37G 23% /tmpfs 878M 100K 878M 1% /dev/shm/dev/sda1 485M 28M 432M 7% /boot/dev/sdc 124M 107M 18M 86% /media/16F0-286F/dev/mapper/VolGroup-lv_home203G 400M 193G 1% /home[root@localhost ~]# lvreduce -L 206G /dev/mapper/VolGroup-lv_homeWARNING: Reducing active and open logical volume to 206.00 GiBTHIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce lv_home? [y/n]: yReducing logical volume lv_home to 206.00 GiBLogical volume lv_home successfully resized[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root50G 11G 37G 23% /tmpfs 878M 100K 878M 1% /dev/shm/dev/sda1 485M 28M 432M 7% /boot/dev/sdc 124M 107M 18M 86% /media/16F0-286F/dev/mapper/VolGroup-lv_home203G 400M 193G 1% /home[root@localhost ~]# vgdisplay--- Volume group ---VG Name VolGroupSystem IDFormat lvm2Metadata Areas 1Metadata Sequence No 5VG Access read/writeVG Status resizableMAX LV 0Cur LV 3Open LV 3Max PV 0Cur PV 1Act PV 1VG Size 465.25 GiBPE Size 32.00 MiBTotal PE 14888Alloc PE / Size 8302 / 259.44 GiBFree PE / Size 6586 / 205.81 GiBVG UUID ymBJK0-SNdq-DWHg-MlPu-31sG-ZpO1-kCrUmu[root@localhost ~]# man lvextend[root@localhost ~]# lvextend -L +205.81G /dev/mapper/VolGroup-lv_rootRounding up size to full physical extent 205.81 GiBExtending logical volume lv_root to 255.81 GiBLogical volume lv_root successfully resized[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_rootresize2fs 1.41.10 (10-Feb-2009)Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing requiredold desc_blocks = 4, new_desc_blocks = 16Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 67059712 (4k) blocks.The filesystem on /dev/mapper/VolGroup-lv_root is now 67059712 blocks long.让我们看一下,[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root252G 11G 229G 5% /tmpfs 878M 100K 878M 1% /dev/shm/dev/sda1 485M 28M 432M 7% /boot/dev/sdc 124M 107M 18M 86% /media/16F0-286F/dev/mapper/VolGroup-lv_home203G 400M 193G 1% /home