线上服务器对根分区进行磁盘扩容

date:2016-04-07

今天领导让我对一台服务器的根分区做扩容,记下来做笔记使用。

 [root@logstashsvr ~]# df -hT
Filesystem                          Type   Size  Used Avail Use% Mounted on
/dev/mapper/vg_logstashsvr-LogVol00 ext4   290G  207G   69G  76% /
tmpfs                               tmpfs  2.9G     0  2.9G   0% /dev/shm
/dev/sda1                           ext4   194M   28M  156M  16% /boot

通过fdisk -l 查看插了一块/dev/sdb  的硬盘进来接下来

对第二块硬盘sdb进行分区

[root@logstashsvr ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf47f4312.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sdb: 1073.7 GB, 1073741824000 bytes
255 heads, 63 sectors/track, 130541 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: 0xf47f4312

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130541, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130541, default 130541):
Using default value 130541
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

说明:上面操作对sdb硬盘进行了分区操作,设为sdb1分区了(当然上面建立的主分区可以为1-4中的任意一个,我这里选择的1)。


接下来就是:

使用工具partprobe让kernel读取分区信息
partprobe
使用fdisk工具只是将分区信息写到磁盘,如果需要mkfs磁盘分区则需要重启系统,
而使用partprobe则可以使kernel重新读取分区 信息,从而避免重启系统。

[root@logstashsvr ~]# partprobe /dev/sdb
-bash: partprobe: command not found
提示我们没有找到,那我们就安装。

[root@logstashsvr ~]# yum -y install parted
然后再执行

[root@logstashsvr ~]# partprobe /dev/sdb

对新建立的分区进行格式化,这个过程时间比较长。

[root@logstashsvr ~]# mkfs.ext4 /dev/sd
sda   sda1  sda2  sdb   sdb1  
[root@logstashsvr ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536000 inodes, 262142637 blocks
13107131 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
8000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
    102400000, 214990848

正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override

接下来我们可以查看一下vgdisplay查看卷祖的闲置空间是多少,方便下面的逻辑卷扩展,这里我忘了看了,就直接+100FREE全部用掉了

[root@logstashsvr ~]# lvextend -l +100%FREE /dev/vg_logstashsvr/LogVol00
  Extending logical volume LogVol00 to 1.26 TiB
  Logical volume LogVol00 successfully resized
[root@logstashsvr ~]# resize2fs /dev/vg_logstashsvr/LogVol00

这一步我等了一两个小时。以为出什么问题了呢。

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_logstashsvr/LogVol00 is mounted on /; on-line resizing required
old desc_blocks = 19, new_desc_blocks = 81
Performing an on-line resize of /dev/vg_logstashsvr/LogVol00 to 339197952 (4k) blocks.
The filesystem on /dev/vg_logstashsvr/LogVol00 is now 339197952 blocks long.

[root@logstashsvr ~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/vg_logstashsvr-LogVol00  1.3T  207G 1003G  18% /
tmpfs                                2.9G     0  2.9G   0% /dev/shm
/dev/sda1                            194M   28M  156M  16% /boot
大功告成!!!!!

 

posted @ 2016-04-07 09:15  BigBao的博客  阅读(1100)  评论(0编辑  收藏  举报