linux如何扩展根分区,linux扩展根分区详细步骤
Linux虛擬機擴展根分區!
虛擬機根分區空間不夠用,在虛擬機管理界面進行單個磁盤擴展(圖形化界面操作略),比如原來是30G,擴展至40G,(擴展需要關機之后操作)
其中的10G空間需要重新分區,以下是分區相關操作讓擴展的空間生效:
登錄系統之后:
df -h ?發現空間沒有發生變化:
[root@lub ~]# df -h
Filesystem ? ? ? ? ? ?Size ?Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
25G ? 19G ?4.2G ?82% /
tmpfs ? ? ? ? ? ? ? ? 642M ? ? 0 ?642M ? 0% /dev/shm
/dev/sda1 ? ? ? ? ? ? 485M ? 34M ?426M ? 8% /boot
fdisk -l ? 發現總容量已經擴展。
[root@lub ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00069f1c
------------------------------
對擴展的磁盤進行分區:
[root@lub ~]# fdisk /dev/sda
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: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00069f1c
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 ? ? ? ?4047 ? ?31992832 ? 8e ?Linux LVM
Command (m for help): n
Command action
e ? extended
p ? primary partition (1-4)
3
Invalid partition number for type `3'
Command action
e ? extended
p ? primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (4047-5221, default 4047):
Using default value 4047
Last cylinder, +cylinders or +size{K,M,G} (4047-5221, default 5221):
Using default value 5221
Command (m for help): p -------查看分區后的情況
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00069f1c
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 ? ? ? ?4047 ? ?31992832 ? 8e ?Linux LVM
/dev/sda3 ? ? ? ? ? ?4047 ? ? ? ?5221 ? ? 9431826+ ?83 ?Linux
---新增的sda3
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@lub ~]#
--------------------使用命令發現partprobe /dev/sda3發現分區并沒有起作用:
[root@lub ~]# partprobe /dev/sda3
Error: Could not stat device /dev/sda3 - No such file or directory.
[root@lub ~]# pvcreate /dev/sda3
Device /dev/sda3 not found (or ignored by filtering).
-----重啟系統。
------LVM操作。擴展根分區
[root@lub ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@lub ~]# vgs
VG ? ? ? #PV #LV #SN Attr ? VSize ?VFree
VolGroup ? 1 ? 2 ? 0 wz--n- 30.51g ? ?0
[root@lub ~]# vgextend VolGroup /dev/sda3
Volume group "VolGroup" successfully extended
[root@lub ~]# vgs
VG ? ? ? #PV #LV #SN Attr ? VSize ?VFree
VolGroup ? 2 ? 2 ? 0 wz--n- 39.50g 8.99g
[root@lub ~]# lvextend -L +8.99G /dev/mapper/VolGroup-lv_root
Rounding size to boundary between physical extents: 8.99 GiB
Extending logical volume lv_root to 33.50 GiB
Logical volume lv_root successfully resized
[root@lub ~]# resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 3
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 8781824 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 8781824 blocks long.
----命令操作根分區情況,發現已經生效:
[root@lub ~]# df -h
Filesystem ? ? ? ? ? ?Size ?Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
33G ? 19G ? 13G ?60% /
tmpfs ? ? ? ? ? ? ? ? 642M ? ? 0 ?642M ? 0% /dev/shm
/dev/sda1 ? ? ? ? ? ? 485M ? 34M ?426M ? 8% /boot
[root@lub ~]#
完成擴展。!
總結
以上是生活随笔為你收集整理的linux如何扩展根分区,linux扩展根分区详细步骤的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux进程故障如何修复,33.Lin
- 下一篇: linux中popen汉字乱码,Pyth