標籤:
摘自 :http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c4224615172da2fa663f4344959e2d3956b21f0baca36d2c761e26b69fca894adcbe866d72c8713b214bda074f920eafba5153c337e751fede1ff0cdf02592dec5a3af4327b944040a9781894d731fdd1efa034795b19939550807bb9d2765894e7659df7413e01ca5b5256e76c7ac8a4b4cb268832157cce96eed6205b562e24c4b7a13b74cc05c027d6eb71930ff35785fd4b14ae75b2e0063eb08a4b9b0b5ef5f8dacfd30ebedcbde79c224bd94&p=863fc64ad49c0eb419bd9b7e0e159d&newp=c33ec64ad4db11a058ee97264f4a85231610db2151d4da1067&user=baidu&fm=sc&query=centos+%D0%E9%C4%E2%BB%FA%C0%A9%C8%DD+Re%2Dreading+the+partition+table+failed+with+error+16%3A+Device+or+resource+busy%2E&qid=a5323d5b000035f6&p1=1
遇到的情況是一模一樣的,留著自己看看吧!
========================================================
背景:程式開發伺服器是虛擬機器,原來只規划了2G,後來發現硬碟不夠用了,需要進行擴容。參考文章:《實戰Linux下VMware虛擬機器根目錄空間擴充》http://blog.sina.com.cn/s/blog_709919050100wap1.html
註:請首先閱讀參考文章,本文是在其基礎之上,在不同環境中進行的案例。同時,原文有幾處地方沒有交代的那麼清楚,初學者可能會走彎路,在這裡進行了相應補充。========================================================看到文章說必須基於LVM,那是不是呢?命令檢驗一下。據說
centos預設安裝也是LVM的。[[email protected] ~]$
lvdisplay --- Logical volume ---
LV Path /dev/vg_vm/lv_root
LV Name lv_root
VG Name vg_vm
LV UUID bWyLlY-hYra-7hPc-2eU9-tXMH-FJFa-7ZLDoF
LV Write Access read/write
LV Creation host, time vm.sss, 2015-01-05 03:29:55 +0800
LV Status available
# open 1
LV Size 6.71 GiB
Current LE 1718
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vg_vm/lv_swap
LV Name lv_swap
VG Name vg_vm
LV UUID oLj3cQ-USD7-JIGZ-HMJz-NlmA-aQf6-lECYyC
LV Write Access read/write
LV Creation host, time vm.sss, 2015-01-05 03:29:56 +0800
LV Status available
# open 1
LV Size 816.00 MiB
Current LE 204
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1[[email protected] ~]$
sudo fdisk -l Disk /dev/sda:
32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x00036057
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 1045 7875584 8e Linux LVM
Disk
/dev/mapper/vg_vm-lv_root: 7205 MB, 7205814272 bytes
255 heads, 63 sectors/track, 876 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: 0x00000000
Disk
/dev/mapper/vg_vm-lv_swap: 855 MB, 855638016 bytes
255 heads, 63 sectors/track, 104 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: 0x00000000 然後,在windows虛擬機器管理軟體上,給
虛擬機器擴容——前提是關閉虛擬機器OS。來個30G,當然,進去之後,可以看到總容量增加了。到32G了,還是沒有發現新的分區,虛擬機器軟體也已經提醒了。[[email protected] ~]$
sudo fdisk /dev/sda
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.最後一步出現這樣的提示。 但是我們發現,fdisk -l,這個分區已經出來了。
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 1045 7875584 8e Linux LVM
/dev/sda3 1045 3916 23066662 83 Linux
當然,這時候用ls /dev是看不到sd3的。因為還沒格式化。sudo mkfs -t ext3 /dev/sda3 現在也是報錯的。
Could not stat /dev/sdb3之類的。既然上次已經提示了要reboot,那就roboot一下吧。[[email protected] ~]$
partprobe還是出現同樣的警告。難道還是不行?Warning: WARNING:
the kernel failed to re-read
the
partition
table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.管他呢,執行一下格式化吧。[[email protected] ~]$
sudo mkfs -t ext3 /dev/sda3居然OK了!這不嚇唬人嗎?[[email protected] ~]$
ll /dev/sda3
brw-rw----. 1 root disk 8, 3 Jan 6 10:33 /dev/sda3嘿嘿,已經有了哦然而,看看磁碟空間呢?怎麼還是這幾個分區呢[[email protected] ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vm-lv_root 6.7G 6.5G 83M 99% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot
sudo fdisk -l也可以發現,還是只有一個LVM的分區。 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 1045 7875584 8e Linux LVM
/dev/sda3 1045 3916 23066662 83 Linux [[email protected] ~]$
sudo lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_vm -wi-ao---- 6.71g
lv_swap vg_vm -wi-ao---- 816.00m [[email protected] ~]$
sudo pvcreate /dev/sda3
dev_is_mpath: failed to get device for 8:3
Physical volume "/dev/sda3" successfully created這裡有一個failed,以為出問題了呢,結果下面又success,玩我呢?不管他了。因為一查,都是這樣的提示,沒有問題。
/dev/mapper/vg_vm-lv_root 6.7G 6.5G 83M 99% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot /dev/mapper/vg_vm-lv_root這個應該就是LVM的組名,這裡顯示的不是sda2.來擴充這個組吧。[[email protected] ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vm-lv_root 6.7G 6.5G 83M 99% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot
[[email protected] ~]$
sudo vgextend /dev/mapper/vg_vm-lv_root /dev/sda3
Volume group name vg_vm/lv_root has invalid characters
[[email protected] ~]$
sudo vgextend /dev/mapper/vg_vm /dev/sda3
Volume group "vg_vm" successfully extended
原來這個組名,是-之前的字串——這要是沒有文章看著對比分析,誰知道啊? [[email protected] ~]$
sudo vgdisplay
--- Volume group ---
VG Name vg_vm
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 29.50 GiB
PE Size 4.00 MiB
Total PE 7553
Alloc PE / Size 1922 / 7.51 GiB
Free PE / Size 5631 / 22.00 GiB
VG UUID 8GwL0o-DTdc-Lmkc-gCCC-RBvv-yOQp-wMgpeq [[email protected] ~]$
sudo lvextend -L +22G /dev/vg_vm/lv_root /dev/sda3
Extending logical volume lv_root to 28.71 GiB
Insufficient free space: 5632 extents needed, but only 5631 available
估計是這其中用了一部分。22G沒那麼准了。那麼就21.0G吧[[email protected] ~]$
sudo lvextend -L +21.9G /dev/vg_vm/lv_root /dev/sda3 Rounding size to boundary between physical extents: 21.90 GiB
Extending logical volume lv_root to 28.61 GiB
Logical volume lv_root successfully resized 文中所說的vim /etc/fstab這一個步驟,沒太看明白。裡面的內容是否有改變?因為看到少了一個mapper我沒有管他,並沒有對這個檔案進行修改,然後繼續往下。 [[email protected] ~]$
sudo e2fsck -f /dev/vg_vm/lv_root
e2fsck 1.41.12 (17-May-2010)
/dev/vg_vm/lv_root is mounted.
e2fsck: Cannot continue, aborting. 不知為何報錯。但是這隻是一個檢查命令,繼續往前吧。[[email protected] ~]$
sudo resize2fs /dev/vg_vm/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_vm/lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 2
Performing an on-line resize of /dev/vg_vm/lv_root to 7500800 (4k) blocks.
The filesystem on /dev/vg_vm/lv_root is now 7500800 blocks long.
[[email protected] ~]$
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_vm-lv_root 29G 6.5G 22G 24% /
tmpfs 495M 80K 495M 1% /dev/shm
/dev/sda1 485M 326M 134M 71% /boot 可以看到,這個邏輯卷已經成功的擴容,根目錄又可以裝更多東西了。yeah!==========================================================================
centos 6.4 擴容