Linux的根分區如果已經使用率達到100%,導緻服務不能正常進行,我們可以這樣擴充根目錄的大小(注意:下面所有操作需在root使用者下完成)。
1. 新加一塊硬碟(這裡使用的是sde), 先建立實體卷
注意:擴充的分區必須要是linux lvm卷,是否是lvm卷是由磁盤第一次分區時候選擇的分區格式決定的。
[root@bigdata105 ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x6133f941.
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: The size of this disk is 3.0 TB (3000592982016 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 (指令 n 用于添加新分區)
Command action
e extended
p primary partition (1-4)
p (選擇建立主分區)
Partition number (1-4): 1
First cylinder (1-364801, default 1): (回車,預設将所有空間配置設定給第一個主分區)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349):
Using default value 267349
Command (m for help): t(修改磁盤格式)
Selected partition 1(指定分區号)
Hex code (type L to list codes): 8e (8e代表LVM)
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w (儲存所有并退出)
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2. 檢視目前磁盤情況
[root@bigdata105 ~]# fdisk -l
Disk /dev/sde: 3000.6 GB, 3000592982016 bytes
255 heads, 63 sectors/track, 364801 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: 0x6133f941
Device Boot Start End Blocks Id System
/dev/sde1 1 267349 2147480811 8e Linux LVM
可以看到/dev/sde1已支援LVM。
3. 将新建立的主分區建立為實體卷
[root@bigdata105 ~]# pvcreate /dev/sde1
Physical volume "/dev/sde1" successfully created
4. df -h指令檢視根目錄所屬的卷組和邏輯卷
[root@bigdata105 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_i8350r-lv_root 542G 318G 197G 62% /
tmpfs 127G 254M 126G 1% /dev/shm
/dev/sdd1 485M 40M 420M 9% /boot
/dev/mapper/vg_i8350r-lv_home 221G 58G 152G 28% /home
這裡根目錄所屬的卷組是vg_i8350r,邏輯卷是/dev/mapper/vg_i8350r-lv_root
5. 将剛建立的實體卷/dev/sde1添加到卷組中
[root@bigdata105 ~]# vgextend vg_i8350r /dev/sde1
Found duplicate PV i35fwCm5JjA6P77IVdaXDDYQBg50o5hm: using /dev/sdd2 not /dev/sdc2
Volume group "vg_i8350r" successfully extended
6. 将卷組的200GB擴充給根所在的邏輯卷
[root@bigdata105 ~]# lvextend -L +200G /dev/mapper/vg_i8350r-lv_root
Extending logical volume lv_root to 750.00 GiB
Logical volume lv_root successfully resized
7. 激活修改的配置
[root@bigdata105 ~]# resize2fs /dev/mapper/vg_i8350r-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_i8350r-lv_root is mounted on /; on-line resizing required
old desc_blocks = 35, new_desc_blocks = 47
Performing an on-line resize of /dev/mapper/vg_i8350r-lv_root to 196608000 (4k) blocks.
The filesystem on /dev/mapper/vg_i8350r-lv_root is now 196608000 blocks long.
8. 檢視擴充後系統情況
/dev/mapper/vg_i8350r-lv_root 739G 318G 383G 46% /
擴充前系統情況
根目錄已經成功擴充200G空間。
9. 其他
如果擴充的根目錄下裝有其它服務,如資料庫,則擴充操作完成後需要重新開機資料庫。