如何更改ubuntu的磁碟分割?

如何更改ubuntu的磁碟分割?

安裝 ubuntu 後我可以將其移至使用不同的磁碟空間嗎?

答案1

您可以嘗試使用 GParted。有一個關於 Live USB 和 GParted 的非常好的指南這裡

另外,對於分割區移動,也可以使用 GParted。建立一個比目前 Ubuntu 分割區更大的新分割區,然後使用 GParted 複製所有資料。這是相當粗糙的,並且可能無法完全工作,但運氣好的話應該可以解決問題。

答案2

是的,我們可以使用 resize2fs 來做到這一點:

首先,我們需要了解可用空間:

root@server:/# df -h
Filesystem                       Size  Used Avail Use% Mounted on
/dev/sdb1                        3,7T  1,5T  2,1T  42% /users/home

現在繼續調整大小:

root@server:~# resize2fs /dev/sdb1 2500G
resize2fs 1.42 (29-Nov-2011)
Por favor ejecute antes 'e2fsck -f /dev/sdb1'.

所以,好吧,我們需要在繼續之前驗證我們的磁碟。所以,它的邏輯是:

root@server:~# e2fsck -f /dev/sdb1
e2fsck 1.42 (29-Nov-2011)
Paso 1: Verificando nodos-i, bloques y tamaños
Paso 2: Verificando la estructura de directorios
Paso 3: Revisando la conectividad de directorios
No se encontró /lost+found.  Crear? no
Paso 4: Revisando las cuentas de referencia
Paso 5: Revisando el resumen de información de grupos
/dev/sdb1: ***** EL SISTEMA DE FICHEROS FUE MODIFICADO *****

/dev/sdb1: 3281220/244064256 files (0.4% non-contiguous), 383150021/976236032 blocks

現在可以了!

resize2fs 1.42 (29-Nov-2011)
Resizing the filesystem on /dev/sdb1 to 655360000 (4k) blocks.
The filesystem on /dev/sdb1 is now 655360000 blocks long.

現在,我們需要刪除分割區,並以新的大小還原分割區。

我們可以使用Fdisk,但是如果我們的硬碟“大”,可能我們必須使用parted。

WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.


WARNING: The size of this disk is 4.0 TB (3998663944192 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).

Using fdsik, we must put start from block 1 to last block that resize2fs, in our case was   655360000 and multiply by 4 (its k in every block). To get some safe margin, We can multiply this again by 1.05 and in this way you got a little more of space.

In parted, is very similar, like fdisk:

root@server:~# parted /dev/sdb
GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt                                                      
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? Yes

Warning: /dev/sdb contains GPT signatures, indicating that it has a GPT table.  However, it does not have a valid fake msdos partition table, as it should.  Perhaps it was
corrupted -- possibly by a program that doesn't understand GPT partition tables.  Or perhaps you deleted the GPT table, and are now using an msdos partition table.  Is this a GPT
partition table?
Yes/No? Yes  

(parted)                                                                  
(parted) print                                                            
Model: DELL MD32xxi (scsi)
Disk /dev/sdb: 3999GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 0GB 3000GB
(parted) print                                                            
Model: DELL MD32xxi (scsi)
Disk /dev/sdb: 3999GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  3000GB  3000GB  ext4         primary

(parted) quit                                                             
Information: You may need to update /etc/fstab.

準備好!現在我們有了一個新的分割區...

答案3

您可以使用 gparted 或 fdisk 來實現此目的。使用 resize2fs、e2fsck 找出可用空間來轉儲已安裝的空間。使用 --help 以獲得最佳結果。

以下是您可以嘗試的命令範例集:

df -h (列出所有可用的驅動器)

resize2fs /dev/sdx xG(將 x 替換為您的實際值,其中 xG 定義您要壓縮到的新磁碟空間(以 GB 為單位))

e2fsck -f /dev/sdb(檔案系統檢查以檢查奇偶校驗和同步記憶體)現在使用 fdisk 工具開始分割區:

fdisk -l/ 列出所有可用設備的所有分區詳細信息

sudo fdisk /dev/sdx/* 為 sdx 設備選擇 fdisk 工具

p/* 顯示目前分區

d(直到不存在分割區) /* 刪除現有分割區

n/* 建立新分割區

p/* 選擇分割區作為主分割區

1/* 給出分區號

(default)/* 偏移位元組

(select size)/* 需要的分割區大小 */

w/* 寫入變更 */

sudo mkfs.(filesystem type) /dev/sdx1/* 將新分割區格式化為檔案系統類型 */

如需更多詳細協助,此連結可能會對您有所幫助: http://noohonlinux.blogspot.qa/2014/10/1.html

相關內容