国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Ubuntu > 正文

VMware下擴展ubuntu虛擬機根目錄分區

2024-06-28 16:04:28
字體:
來源:轉載
供稿:網友

原文鏈接:http://t.cn/RzCP9E2 翻譯源鏈接:http://imcczy.com/how-to-expand-the-root-filesystem-in-vmware.html

轉載說明:

此文下面的有重新需要分區的操作,分區的操作與正常裝系統分區不同,是需要手動指定扇區(sectors)的起始點的, 這里給出計算方式,其實當打出命令時也是有提示的 類似這樣的提示 Disk /dev/sda: 15 GiB, 16106127360 bytes, 31457280 sectors Units: sectors of 1 * 512 = 512 bytes sectors 就是你的硬盤當前分區總扇區大小 可以先計算出自己打算要分出的分區大小 例如 根分區 需要14G swap分1G 1024*14=14336bytes(1.4mb) *1024*1024 = 15032385536bytes(14G) 15032385536 / 512 = 29360128 sectors 得出了從起始點到此扇區結束就是14G了

年代久遠,謹慎嘗試

虛擬機用著用著空間就不夠了,google了一篇文章,試了一下,有用,征得作者同意,翻譯了下。刪了一些無關的東西。

注:

作者輸入命令時都用“sudo bash”,用sudo或者su就可以了。

再注:

涉及到磁盤分區表刪除,最好先備份整個虛擬機!

檢查文件系統:

cruz@Ubuntu:~$ sudo bash[sudo] passWord for cruz: root@ubuntu:~# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 9.0G 2.7G 5.9G 32% /udev 488M 4.0K 488M 1% /devtmpfs 199M 800K 198M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 497M 76K 496M 1% /run/shmroot@ubuntu:~#

檢查磁盤分區表:

root@ubuntu:~# fdisk -l /dev/sdaDisk /dev/sda: 10.7 GB, 10737418240 bytes255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00001decDevice Boot Start End Blocks Id System/dev/sda1 * 2048 18874367 9436160 83 linux/dev/sda2 18876414 20969471 1046529 5 Extended/dev/sda5 18876416 20969471 1046528 82 Linux swap / Solarisroot@ubuntu:~#

記住上面顯示的交換分區大小(Blocks的數目),這里就是1046528。如果交換分區和根目錄不在一個磁盤(比如/dev/sdb),就不要記了。在本文,交換分區在/dev/sda,需要重新分區。

先關閉linux:

root@ubuntu:~# shutdown -h now

在虛擬機設置,硬盤,實用工具下選擇擴展。擴展虛擬機的最大磁盤大小,這里將磁盤設置為15G,然后重啟。

重新設置分區表要刪除所有的舊分區、關閉系統的swap:

cruz@ubuntu:~$ sudo bash[sudo] password for cruz: root@ubuntu:~# free -m total used free shared buffers cachedMem: 992 924 67 0 43 426 -/+ buffers/cache: 454 537Swap: 1021 0 1021root@ubuntu:~# swapoff -aroot@ubuntu:~# free -m total used free shared buffers cachedMem: 992 924 67 0 43 426 -/+ buffers/cache: 454 537Swap: 0 0 0root@ubuntu:~#

接下來的步驟會刪除/dev/sda1和/dev/sda2,一定要記住分區表的起始位置,這里是2048!

root@ubuntu:~# fdisk /dev/sdaCommand (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00001dec Device Boot Start End Blocks Id System/dev/sda1 * 2048 18874367 9436160 83 Linux/dev/sda2 18876414 20969471 1046529 5 Extended/dev/sda5 18876416 20969471 1046528 82 Linux swap / SolarisCommand (m for help): dPartition number (1-5): 1Command (m for help): dPartition number (1-5): 2Command (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00001dec Device Boot Start End Blocks Id SystemCommand (m for help):

不要退出fdisk,接著創建新分區

Command (m for help): nPartition type: p PRimary (0 primary, 0 extended, 4 free) e extendedSelect (default p): pPartition number (1-4, default 1): 1First sector (2048-31457279, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-31457279, default 31457279): 30410751Command (m for help): nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): pPartition number (1-4, default 2): Using default value 2First sector (30410752-31457279, default 30410752): Using default value 30410752Last sector, +sectors or +size{K,M,G} (30410752-31457279, default 31457279): Using default value 31457279注意記得創建交換分區,大小別搞錯,這里是1046528(31457279-30410571=1046528),即要留一部分block用于創建swap。修改sda2的分區類型為82,即交換分區。Command (m for help): pDisk /dev/sda: 16.1 GB, 16106127360 bytes255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00001dec Device Boot Start End Blocks Id System/dev/sda1 2048 30410751 15204352 83 Linux/dev/sda2 30410752 31457279 523264 83 LinuxCommand (m for help): tPartition number (1-4): 2Hex code (type L to list codes): 82Changed system type of partition 2 to 82 (Linux swap / Solaris)Command (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.root@ubuntu:~#

重啟虛擬機:

root@ubuntu:~# shutdown -r now

交換分區掛載需要UUID標識符。創建新的交換分區不會匹配舊的UUID,導致重啟無法掛載swap分區。這里主要有兩種解決方法:在/etc/fstab里寫入新的UUID,或者直接將舊的UUID覆蓋在新分區上,這里選擇后者。 awk命令用來顯示舊的UUID,dd命令確保分區沒數據。

cruz@ubuntu:~$ sudo bash[sudo] password for cruz: root@ubuntu:~# awk '/swap/ { print $1 }' /etc/fstab#UUID=8bb62351-4436-47df-92fe-af2865f03461root@ubuntu:~# swapoff -aroot@ubuntu:~# free -m total used free shared buffers cachedMem: 992 695 296 0 23 325-/+ buffers/cache: 346 645Swap: 0 0 0root@ubuntu:~# dd if=/dev/zero of=/dev/sda2dd: writing to '/dev/sda2': No space left on device1046529+0 records in1046528+0 records out535822336 bytes (536 MB) copied, 11.9388 s, 44.9 MB/sroot@ubuntu:~# mkswap -U 8bb62351-4436-47df-92fe-af2865f03461 /dev/sda2Setting up swapspace version 1, size = 523260 KiBno label, UUID=8bb62351-4436-47df-92fe-af2865f03461root@ubuntu:~# swapon -aroot@ubuntu:~# free -m total used free shared buffers cachedMem: 992 693 298 0 23 325-/+ buffers/cache: 345 646Swap: 510 7 503root@ubuntu:~#

最后,調整分區大小:

root@ubuntu:~# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 9.0G 2.8G 5.8G 33% /udev 488M 4.0K 488M 1% /devtmpfs 199M 788K 198M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 497M 200K 496M 1% /run/shmroot@ubuntu:~# resize2fs /dev/sda1resize2fs 1.42 (29-Nov-2011)Filesystem at /dev/sda1 is mounted on /; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 1Performing an on-line resize of /dev/sda1 to 3801088 (4k) blocks.The filesystem on /dev/sda1 is now 3801088 blocks long.root@ubuntu:~# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 15G 2.8G 11G 21% /udev 488M 4.0K 488M 1% /devtmpfs 199M 788K 198M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 497M 200K 496M 1% /run/shmroot@ubuntu:~#
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苗栗市| 房产| 隆化县| 伊宁县| 宁化县| 钟祥市| 盐山县| 蕲春县| 长春市| 开平市| 和硕县| 阿克陶县| 和林格尔县| 兰考县| 博野县| 彭阳县| 西丰县| 司法| 台东县| 新龙县| 铁力市| 康定县| 酒泉市| 霍林郭勒市| 师宗县| 克山县| 罗山县| 东乡县| 龙游县| 吴桥县| 中西区| 招远市| 新巴尔虎右旗| 攀枝花市| 旺苍县| 木兰县| 邛崃市| 丹巴县| 汤阴县| 塘沽区| 张家界市|