linux,添加新硬盘的方法

一、物理机添加一块新的硬盘方法(目的是把后加的磁盘直接加在现有的上面,不用再分区挂载)
1、首先要确定现有系统在那块盘上
  [root@localhost ~]# df -lh
Filesystem            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 -lh
3、如果是虚拟机的话,历史命令如下
mkfs.ext4 /dev/vdb 
pvcreate /dev/vdb   
vgextend vmvg  /dev/vdb
lvextend -L +49G /dev/mapper/vmvg-root
resize2fs -p /dev/vmvg/root

三、调整现有分区大小
在使用Fedora13-x86_64过程中,发现系统分配给root用户lvm份额太少.
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 11G 37G 23% /
tmpfs 878M 100K 878M 1% /dev/shm
/dev/sda1 485M 28M 432M 7% /boot
/dev/mapper/VolGroup-lv_home
406G 411M 385G 1% /home
/dev/sdc 124M 107M 18M 86% /media/16F0-286F
[root@localhost ~]#
总共才50G,决定给它增加份额,现做好重要文件备份,以防万一.
思路:
先减掉VolGroup-lv_home的份额,再把减掉份额增加到VolGroup-lv_root.

[root@localhost ~]# pvscan
PV /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 206G
resize2fs 1.41.10 (10-Feb-2009)
Filesystem at /dev/mapper/VolGroup-lv_home is mounted on /home; on-line resizing required
On-line shrinking from 107954176 to 54001664 not supported.
[root@localhost ~]# umount /home
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 206G
resize2fs 1.41.10 (10-Feb-2009)
Please run ‘e2fsck -f /dev/mapper/VolGroup-lv_home‘ first.

[root@localhost ~]# e2fsck -f /dev/mapper/VolGroup-lv_home
e2fsck 1.41.10 (10-Feb-2009)
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/mapper/VolGroup-lv_home: 1534/26992640 files (1.2% non-contiguous), 1799101/107954176 blocks
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_home 206G
resize2fs 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 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup-lv_home is now 54001664 blocks long.

[root@localhost ~]# mount /home
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 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_home
203G 400M 193G 1% /home
[root@localhost ~]# lvreduce -L 206G /dev/mapper/VolGroup-lv_home
WARNING: Reducing active and open logical volume to 206.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
Reducing logical volume lv_home to 206.00 GiB
Logical volume lv_home successfully resized
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
50G 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_home
203G 400M 193G 1% /home
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 465.25 GiB
PE Size 32.00 MiB
Total PE 14888
Alloc PE / Size 8302 / 259.44 GiB
Free PE / Size 6586 / 205.81 GiB
VG UUID ymBJK0-SNdq-DWHg-MlPu-31sG-ZpO1-kCrUmu

[root@localhost ~]# man lvextend
[root@localhost ~]# lvextend -L +205.81G /dev/mapper/VolGroup-lv_root
Rounding up size to full physical extent 205.81 GiB
Extending logical volume lv_root to 255.81 GiB
Logical volume lv_root successfully resized
[root@localhost ~]# resize2fs -p /dev/mapper/VolGroup-lv_root
resize2fs 1.41.10 (10-Feb-2009)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 16
Performing 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 -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
252G 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_home
203G 400M 193G 1% /home

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。