我家裡使用的虛擬機器空間不足。運行Ubuntu伺服器,現有空間20G。我決定將其增加到 100G,以確保我有足夠的喘息空間。
所以我按照這裡的說明進行操作:http://www.rootusers.com/use-gparted-to-increase-disk-size-of-a-linux-native-partition/
一切都很順利,直到最後一步。嘗試將/dev/sda1/
分割區大小增加到 99G 在第三步失敗:“檢查檔案系統/dev/sda1
是否有錯誤並(如果可能)修復它們。”
看起來這一步嘗試運行:e2fsck -f -y -v /dev/sda1
這會引發一個錯誤:
無法讀取超級區塊或未描述正確的 ext2 檔案系統。
有問題的分區是 ext3 分區,但我不確定這是否重要。
主分割區仍然沒問題,Ubuntu 仍然可以啟動,所以我認為沒問題。關於我需要做什麼才能讓它變得更大有什麼想法嗎?
編輯 :
fdisk -l
從 gparted live 磁碟啟動時的輸出。
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16064 * 512 = 9225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2481 19921920 83 Linux
/dev/sda2 12924 13054 1052275+ 5 Extended
/dev/sda5 12925 13054 1044225 82 Linux swap / Solaris
編輯2:
fdisk -l
當在 ubuntu 伺服器中啟動時
有趣的是,當我正常啟動虛擬機器後運行時,輸出是不同的。
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 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: 0x00044fd6
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 39845887 19921920 83 Linux
/dev/sda2 207607995 209712509 1052257+ 5 Extended
/dev/sda5 207624060 209712509 1044225 82 Linux swap / Solaris
編輯3:輸出mount | grep " / "
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
答案1
感謝您的fdisk
和mount
輸出。
- 兩個 fdisk 輸出之間的差異僅在於使用的單位,因此數字不同。
- /dev/sda1 分割區尚未調整大小,仍約為 20GB。
您必須先調整它的大小,最好在從 CD 啟動時完成:
~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 2048 39845887 19921920 83 Linux
/dev/sda2 207607995 209712509 1052257+ 5 Extended
/dev/sda5 207611904 209712509 1050303 82 Linux swap / Solaris
如果您沒有看到這些「長」數字的輸出,請使用 fdisk 指令u
將單位變更為磁區,然後p
再次列印。
現在刪除/dev/sda1
並以更大的尺寸重新建立。刪除分割區只會更改分割區表,不會刪除任何數據,但我強烈建議您先拍攝虛擬機器的快照。
Command (m for help): d
Partition number (1,2,5, default 5): 1
Partition 1 is deleted
現在建立一個新的:
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): p
Partition number (1,3,4, default 1): 1
First sector (2048-209715199, default 2048): <==== This MUST be the same as in the original partition table!
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-207607994, default 207607994): <== Use the default, will be maximum it can do
Using default value 207607994
Partition 1 of type Linux and of size 99 GiB is set
驗證它看起來是否正常:
Command (m for help): p
Device Boot Start End Blocks Id System
/dev/sda1 2048 207607994 103802973+ 83 Linux <=== Note the new size
/dev/sda2 207607995 209712509 1052257+ 5 Extended
/dev/sda5 207611904 209712509 1050303 82 Linux swap / Solaris
並寫入磁碟:
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
現在檢查檔案系統的一致性並調整大小:
~# e2fsck -f /dev/sda1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sda1: 11/1245184 files (0.0% non-contiguous), 122210/4980480 blocks
~# resize2fs /dev/sda1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/sda1 to 25950743 (4k) blocks.
The filesystem on /dev/sda1 is now 25950743 blocks long.
這應該夠了吧。
答案2
我使用的是舊版的 GParted Live Disk。我下載了最新版本,它按照我連結的說明運行。