)虛擬機器環境中linux系統增加磁碟空間

來源:互聯網
上載者:User

前段時間在vmware ESXi虛擬化環境中安裝了一套turbolinux系統,當時並沒有在意磁碟如何規劃,使用了LVM,心想反正能夠隨時擴充。不料時間不長,問題出現了,分配的磁碟空間滿了。以為能夠象windows Server環境中使用磁碟管理增加動態磁碟那樣方便呢,就隨意在ESX管理器中將原有的磁碟從10G增加到了13G,重啟掛載LVM沒有左右,重啟系統了。

重啟後 ,使用fdisk -l能夠看到/dev/sda的空間已經增加了,但仍還是原來的兩個磁碟/dev/sda1和/dev/sda2 (LVM)。在LVM邏輯卷管理其中仍是原來的10G空間,但在“未初始化的執行個體”中可以看到增加的3G未初始化的磁碟執行個體(unpartitioned space on /dev/sda)。

解決辦法:

使用sfdisk /dev/sda 命令,選擇n (add a new partition),然後選擇p (primary partition ),選擇一個磁碟號,隨後系統會自動提示選擇起始塊和最後的塊。使用p(print the partion table)查看磁碟是否已經增加:

Disk /dev/sda: 13.9 GB, 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
/dev/sda3 1306 1697 3148740 83 Linux
可以看到/dev/sda3的 id是83,這樣的磁碟無法加入到lvm中,選擇t(change a partition's system id),鍵入8e (Linux LVM 的id)。

最後,w儲存退出。再使用sfsik -l即可看到新增的磁碟。

此時,使用lvm的初始化磁碟工具或者直接使用pvcreate /dev/sda3命令會提示出錯,提示

Device “/dev/sda3” not found (or ignored by filtering)

出錯的原因在於使用fdisk修改配置時沒有在runlevel 1下進行,重啟系統後可解決此問題。

[root@turbolinux ~]# fdisk -l

Disk /dev/sda: 13.9 GB, 13958643712 bytes
255 heads, 63 sectors/track, 1697 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1305 10377990 8e Linux LVM
/dev/sda3 1306 1697 3148740 8e Linux LVM
[root@turbolinux ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@turbolinux ~]# lvm
lvm> pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [9.88 GB / 640.00 MB free]
PV /dev/sda3 lvm2 [3.00 GB]
Total: 2 [12.88 GB] / in use: 1 [9.88 GB] / in no VG: 1 [3.00 GB]
lvm> vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended
lvm> lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID 9tKx5o-7wgM-0BhF-OMqy-EY14-ttbL-30j1px
LV Write Access read/write
LV Status available
# open 1
LV Size 7.25 GB
Current LE 232
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
lvm> lvextend
Please specify either size or extents but not both.
lvm> lvextend -L+2G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 9.25 GB
Logical volume LogVol00 successfully resized
lvm> lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID 9tKx5o-7wgM-0BhF-OMqy-EY14-ttbL-30j1px
LV Write Access read/write
LV Status available
# open 1
LV Size 9.25 GB
Current LE 296
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

邏輯卷的大小已經更改到9.23G了,但檔案系統仍沒有增加:

[root@turbolinux ~]# df
檔案系統 1K-塊 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
7364072 5140148 1843844 74% /
/dev/sda1 101086 25946 69921 28% /boot
tmpfs 2073968 0 2073968 0% /dev/shm

需要使用resize2fs命令將檔案系統擴充到增加的空間上:
[root@turbolinux ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2424832 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2424832 blocks long.

[root@turbolinux ~]# df -m
檔案系統 1M-塊 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
9176 5020 3683 58% /
/dev/sda1 99 26 69 28% /boot
tmpfs 2026 0 2026 0% /dev/shm
[root@turbolinux ~]# df
檔案系統 1K-塊 已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
9395560 5140156 3770492 58% /
/dev/sda1 101086 25946 69921 28% /boot
tmpfs 2073968 0 2073968 0% /dev/shm
至此,磁碟空間的擴充工作完畢。

另,更改swap空間的內容如下:

預設安裝時,不知為何,將swap的空間定為了5G,感覺沒有必要這麼大,需減少一點,因為swap在VolGroup00中,所以調整大小非常方便,

  具體操作如下:

  關閉swap先

  # swapoff -v /dev/VolGroup00/LogVol01

  # lvm lvreduce /dev/VolGroup00/LogVol01 -L -1G

  # mkswap /dev/VolGroup00/LogVol01

  重新開啟swap

  # swapon -va

swap常用命令:

cat /proc/swaps

swapon -s

調整swap大小:
dd if=/dev/zero of=swapfree bs=32k count=8192 (256MB)
mkswap swapfree
swapon /tmp/swapfree

停止:
swapoff /tmp/swapfree
啟動時載入:
在/etc/fstab檔案中,加入下行:
/tmp/swapfree swap swap defaults 0 0

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.