VMware下ubuntu擴(kuò)展磁盤(pán)空間的方法
近日由于虛擬機(jī)下安裝軟件過(guò)多,時(shí)不時(shí)彈出磁盤(pán)空間不足的問(wèn)題。查找了很多資料,都沒(méi)有很好的解決辦法。
朋友發(fā)來(lái)一個(gè)鏈接,還是老外有良心。翻譯出來(lái)放在這里,根據(jù)我的實(shí)際需求進(jìn)行了操作,達(dá)到了預(yù)期目的。
以防萬(wàn)一,在操作之前將虛擬機(jī)進(jìn)行了備份。
由于安裝時(shí)沒(méi)有自己進(jìn)行分區(qū),磁盤(pán)大小也使用了默認(rèn)的20G。后來(lái)發(fā)現(xiàn)果然悲劇。
使用df -h命令查看具體使用情況
@ubuntu:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 17G 1020M 95% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 745M 4.0K 745M 1% /dev tmpfs 151M 1.3M 150M 1% /run none 5.0M 0 5.0M 0% /run/lock none 755M 220K 755M 1% /run/shm none 100M 48K 100M 1% /run/user
使用root權(quán)限 fdisk -l查看
在虛擬機(jī)的設(shè)置——>硬盤(pán)——>擴(kuò)展 選項(xiàng),選擇需要擴(kuò)展到的容量,這里我是從20G擴(kuò)展到40G。
設(shè)置完成后發(fā)現(xiàn)依然無(wú)法使用,而是在擴(kuò)展分區(qū)里。
Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ea50f Device Boot Start End Blocks Id System /dev/sda1 * 2048 39845887 19921920 83 Linux /dev/sda2 39847934 41940991 1046529 5 Extended /dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris
具體思路是將分區(qū)先刪除,然后再重新進(jìn)行分區(qū)。注意,這里使用fdisk -l查看的信息建議記錄下來(lái),后面進(jìn)行重新分區(qū)時(shí)會(huì)使用到。
使用free -m命令查看
bay@ubuntu:~$ free -m total used free shared buffers cached Mem: 1508 1065 443 5 74 419 -/+ buffers/cache: 572 936 Swap: 1021 0 1021
我們可以看到交換分區(qū)的大小,先將交換分區(qū)關(guān)掉使用命令
root@ubuntu:# swapoff -a root@ubuntu:# free -m total used free shared buffers cached Mem: 1508 1075 433 5 73 419 -/+ buffers/cache: 581 926 Swap: 0 0 0
這時(shí)候可以看到swap的分區(qū)大小已經(jīng)為0了。
接下來(lái)的步驟就是刪除掉 /dev/sda1 和 /dev/sda2。使用fdisk /dev/sda刪除分區(qū)
root@ubuntu:# fdisk /dev/sda Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ea50f Device Boot Start End Blocks Id System /dev/sda1 * 2048 39845887 19921920 83 Linux /dev/sda2 39847934 41940991 1046529 5 Extended /dev/sda5 39847936 41940991 1046528 82 Linux swap / Solaris Command (m for help): d Partition number (1-5): 1 Command (m for help): d Partition number (1-5): 2 Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ea50f Device Boot Start End Blocks Id System
刪除舊的分區(qū)之后,就開(kāi)始進(jìn)行創(chuàng)建新分區(qū)了,注意這時(shí)候讓之前保存的信息就派上用場(chǎng)了。
Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-83886079, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079): 82869552
注意這是時(shí)候可能會(huì)有人疑惑,這個(gè)大小該如何設(shè)置。
這個(gè)大小是總的大小減去Swap的大?。?3886080 - 1046528 = 82839552。這里的1046528 就是Swap的大小。
接著將分區(qū)的事情做完:
Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (1-4, default 2): 2 First sector (82839553-83886079, default 82839553): Using default value 82839553 Last sector, +sectors or +size{K,M,G} (82839553-83886079, default 83886079): Using default value 83886079 Command (m for help): p Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000ea50f Device Boot Start End Blocks Id System /dev/sda1 2048 82839552 41418752+ 83 Linux /dev/sda2 82839553 83886079 523263+ 83 Linux
這個(gè)時(shí)候分區(qū)大小是正確的了,但是ID還是同一個(gè)值。在這里我們將交換分區(qū)的ID修改為82.
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris)
使用w進(jìn)行保存
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.
將虛擬機(jī)進(jìn)行重啟。
交換分區(qū)使用UUID進(jìn)行掛載。在創(chuàng)建新的分區(qū)之后,UUID將會(huì)不匹配,在reboot之后將沒(méi)有交換分區(qū)可以使用。這里有兩種方式進(jìn)行處理
1)在 /etc/fstab 中使用新的UUID
2)在新的分區(qū)上使用舊的UUID。這里使用第二種方法。
查看UUID:
root@ubuntu:/home/bay# awk '/swap/ { print $1 }' /etc/fstab # UUID=990ae69c-2bbe-425f-bb8f-91200f70c9b9 [html] view plain copy root@ubuntu:# swapoff -a root@ubuntu:# free -m total used free shared buffers cached Mem: 1508 1171 337 6 191 424 -/+ buffers/cache: 555 953 Swap: 0 0 0 root@ubuntu:# dd if=/dev/zero of=/dev/sda2 dd: writing to ‘/dev/sda2': No space left on device 1046528+0 records in 1046527+0 records out 535821824 bytes (536 MB) copied, 1.89975 s, 282 MB/s root@ubuntu:# mkswap -U 990ae69c-2bbe-425f-bb8f-91200f70c9b9 /dev/sda2 Setting up swapspace version 1, size = 523256 KiB no label, UUID=990ae69c-2bbe-425f-bb8f-91200f70c9b9 root@ubuntu:# swapon -a root@ubuntu:# free -m total used free shared buffers cached Mem: 1508 717 790 6 6 164 -/+ buffers/cache: 546 961 Swap: 510 0 510 root@ubuntu:# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 19G 17G 1023M 95% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 745M 12K 745M 1% /dev tmpfs 151M 1.3M 150M 1% /run none 5.0M 0 5.0M 0% /run/lock none 755M 152K 755M 1% /run/shm none 100M 48K 100M 1% /run/user root@ubuntu:# resize2fs /dev/sda1 resize2fs 1.42.9 (4-Feb-2014) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 3 The filesystem on /dev/sda1 is now 10354688 blocks long. root@ubuntu:# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 39G 17G 21G 45% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 745M 12K 745M 1% /dev tmpfs 151M 1.3M 150M 1% /run none 5.0M 0 5.0M 0% /run/lock none 755M 152K 755M 1% /run/shm none 100M 48K 100M 1% /run/user
dd命令僅僅是保證在分區(qū)開(kāi)始的地方?jīng)]有數(shù)據(jù)。
以上所述是小編給大家介紹的VMware下ubuntu擴(kuò)展磁盤(pán)空間的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
虛擬機(jī)網(wǎng)絡(luò)配置(NAT、橋接、Hostonly)詳解
很多人安裝虛擬機(jī)的時(shí)候,經(jīng)常遇到不能上網(wǎng)的問(wèn)題,而vmware有三種網(wǎng)絡(luò)模式,對(duì)初學(xué)者來(lái)說(shuō)也比較眼花聊亂,今天我就來(lái)基于虛擬機(jī)3種網(wǎng)絡(luò)模式,幫大家普及下虛擬機(jī)的網(wǎng)絡(luò)配置知識(shí)2017-02-02VMware虛擬機(jī)開(kāi)機(jī)黑屏的解決方法小結(jié)
在VMware中裝了虛擬機(jī),但是在啟動(dòng)后一直處于黑屏而無(wú)法進(jìn)入系統(tǒng),也沒(méi)有報(bào)錯(cuò)提示,出現(xiàn)這種問(wèn)題的主要原因是VMware軟件跟本地網(wǎng)路規(guī)范有所沖突,解決辦法也簡(jiǎn)單,重置一下網(wǎng)絡(luò)規(guī)范就好了,具體的操作方法如下,需要的朋友可以參考下2024-09-09詳解VMware12安裝centOS8的配置圖文教程(vm虛擬機(jī)安裝centos8教程)
這篇文章主要介紹了VMware12安裝centOS8配置圖文教程(vm虛擬機(jī)安裝centos8教程),本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-11-11VMware虛擬機(jī)三種網(wǎng)絡(luò)模式區(qū)別
提到VMware大家就想起了虛擬機(jī)技術(shù),虛擬機(jī)技術(shù)在最近的幾年中得到了廣泛的發(fā)展,一些大型網(wǎng)絡(luò)服務(wù)商都開(kāi)始采用虛擬機(jī)技術(shù),不僅節(jié)省了投資成本,更節(jié)約了能源的消耗。2016-10-10Vmware虛擬機(jī)安裝Ubuntu 16.04 LTS(長(zhǎng)期支持)版本+VMware tools安裝的圖文教程
這篇文章主要介紹了Vmware虛擬機(jī)安裝Ubuntu 16.04 LTS(長(zhǎng)期支持)版本+VMware tools安裝的圖文教程,需要的朋友可以參考下2017-01-01Vmware虛擬機(jī)設(shè)置主機(jī)端口映射方式
這篇文章主要介紹了Vmware虛擬機(jī)設(shè)置主機(jī)端口映射方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12Vmware?Station安裝Arch?Linux的詳細(xì)流程
這篇文章主要介紹了Vmware?Station安裝Arch?Linux的流程,本文通過(guò)圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04教你如何在Mac上安裝VMware?Fusion和CentOS-7
這篇文章主要介紹了Mac上安裝VMware?Fusion和CentOS-7,其實(shí)安裝過(guò)程很簡(jiǎn)單和安裝其他mac軟件一樣,雙擊app文件就可以,本文分步驟給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01