Ubuntu 扩展分区

1,063 阅读2分钟

根目录扩展

输入命令无法自动补全,报错了

cannot create temp file for here-document: No space left on device

查看分区,发现分区2的磁盘满了,并且挂载在根目录下,所以需要对根目录进行分区

oyaji@oyaji:/home/gass/client$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   12G     0   12G   0% /dev
tmpfs          tmpfs     2.3G  2.5M  2.3G   1% /run
/dev/sda2      ext4      591G   21G   21G   100% /
tmpfs          tmpfs      12G     0   12G   0% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      12G     0   12G   0% /sys/fs/cgroup
/dev/loop1     squashfs  100M  100M     0 100% /snap/core/10958
/dev/loop0     squashfs  100M  100M     0 100% /snap/core/10908
tmpfs          tmpfs     2.3G     0  2.3G   0% /run/user/1000

扩展磁盘 image.png

注意:由于磁盘是由扇区组成的,并且是连续的,所以在vm然后进行扩展的时候,是在末尾添加的,如果扩展的分区在前面(比如现在有分区1、分区2、分区3),现在分区1满了,需要扩展,则先需要删除分区3、分区2,然后在分区1,然后重新划分各个分区,这个过程需要备份分区3,分区2的数据(如果分区挂载在其他目录的话),不然会数据丢失

oyaji@oyaji:/home$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (1048575999 != 1258291199) will be corrected by w(rite).
GPT PMBR size mismatch (1048575999 != 1258291199) will be corrected by w(rite).

Command (m for help): F

Unpartitioned space /dev/sda: 100 GiB, 107374165504 bytes, 209715167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

     Start        End   Sectors  Size
1048576000 1258291166 209715167  100G

Command (m for help): d
Partition number (1-3, default 3): 

Partition 3 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 

Partition 2 has been deleted.

Command (m for help): n
Partition number (2-128, default 2): 
First sector (4096-1258291166, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-1258291166, default 1258291166): 

Created a new partition 2 of type 'Linux filesystem' and of size 600 GiB.

通知

partprobe /dev/sda

重启

sudo reboot

刷新

sudo resize2fs /dev/sda2

查看

df -TH

扩展新分区

直接进行外载分区

oyaji@oyaji:/home$ sudo fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

GPT PMBR size mismatch (1048575999 != 1258291199) will be corrected by w(rite).
GPT PMBR size mismatch (1048575999 != 1258291199) will be corrected by w(rite).

Command (m for help): F

Unpartitioned space /dev/sda: 100 GiB, 107374165504 bytes, 209715167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

     Start        End   Sectors  Size
1048576000 1258291166 209715167  100G

Partition 2 has been deleted.

Command (m for help): n
Partition number (2-128, default 2): 
First sector (4096-1258291166, default 4096): 
Last sector, +sectors or +size{K,M,G,T,P} (4096-1258291166, default 1258291166): 

Created a new partition 2 of type 'Linux filesystem' and of size 600 GiB.


sudo mkfs.ext4 /dev/sda3  ##修改文件类型
sudo mkdir gass           ##创建挂载目录
sudo mount -t ext4 /dev/sda3  gass   ##挂载