Linux服務器LVM磁盤擴容

  • 查看磁盤信息
fdisk -l
  • 啓動VMware環境下的Linux操做系統,添加新分區,須要root帳號身份。
fdisk /dev/sda   # 後邊參數爲指定的擴容的磁盤

命令行提示下輸入【m】 輸入命令【n】添加新分區。 輸入命令【p】建立主分區。 輸入【回車】,選擇默認大小,這樣不浪費空間 輸入【回車】,選擇默認的start cylinder。 輸入【w】,保持修改node

  • 重啓linux,格式化 /dev/sda3
sudo reboot
  • 操做示例
[root@master /]# fdisk /dev/sda
 
WARNING: The size of this disk is 3.7 TB (3688303165440 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
 
 
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): p
 
Disk /dev/sda: 3688.3 GB, 3688303165440 bytes
255 heads, 63 sectors/track, 448410 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: 0x00000b93
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
 
Command (m for help): ^C
[root@master /]# fdisk /dev/sda
 
WARNING: The size of this disk is 3.7 TB (3688303165440 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
 
 
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): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-448410, default 2611):
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-267349, default 267349):
Using default value 267349
 
Command (m for help): p
 
Disk /dev/sda: 3688.3 GB, 3688303165440 bytes
255 heads, 63 sectors/track, 448410 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: 0x00000b93
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
/dev/sda3            2611      267349  2126509322+  83  Linux
 
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
 
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
  • 格式化磁盤
[root@master /]#  mke2fs /dev/sda3
1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
132907008 inodes, 531627330 blocks
26581366 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
16224 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, 512000000
 
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
 
done
 
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
  • 查看掛載點
[root@master ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_master-lv_root
                       18G   16G  1.1G  94% /
tmpfs                 1.4G   12K  1.4G   1% /dev/shm
/dev/sda1             477M   52M  400M  12% /boot
  • 添加新LVM到已有的LVM組,實現擴容
lvm                       進入lvm管理
 
lvm> pvcreate /dev/sda3         這是初始化剛纔的分區,必須的
 
lvm> vgextend vg_master /dev/sda3   將初始化過的分區加入到虛擬卷組vg_master  (查看虛擬卷組命令:vgdisplay)
 
lvm>lvextend -L +29.9G /dev/vg_master/lv_root  擴展已有卷的容量(29.9G這個數字在後面解釋)
 
lvm>pvdisplay              查看卷容量,這時你會看到一個很大的捲了
 
lvm>quit                 退出
  • 上步只是卷擴容了,下面是文件系統的真正擴容
[root@master ~]# resize2fs -p /dev/vg_master/lv_root 30g   //增長分區至30g
  • 再次查看分區信息
[root@master ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_master-lv_root
                       30G   16G   13G  55% /
tmpfs                 1.4G   12K  1.4G   1% /dev/shm
/dev/sda1             477M   52M  400M  12% /boo
相關文章
相關標籤/搜索