VirtualBox 硬盘容量扩充

1. ubuntu 磁盘容量告急,df -h如下:

~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            4.9G     0  4.9G   0% /dev
tmpfs           999M  1.4M  998M   1% /run
/dev/sda1        16G   14G  1.5G  91% /
2. 打开VB的“管理”

VirtualBox 硬盘容量扩充_第1张图片

设置“虚拟介质管理”,扩充16G =》 64GB,并点击 “应用”。这个时候只是虚拟分配了,并未实际分配,要用fdisk 增加新分区来取。

VirtualBox 硬盘容量扩充_第2张图片

3. 进入Ubuntu系统,可以看到fdisk /dev/sda已经有64GB

~$ sudo fdisk -l /dev/sda
Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 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
Disklabel type: dos
Disk identifier: 0xe9acfcdb

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1  *     2048 33552383 33550336  16G 83 Linux
 

新增分区:

~$ 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.


Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 
First sector (33552384-134217727, default 33552384): 
Last sector, +sectors or +size{K,M,G,T,P} (33552384-134217727, default 134217727): 

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

Command (m for help): p
Disk /dev/sda: 64 GiB, 68719476736 bytes, 134217728 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
Disklabel type: dos
Disk identifier: 0xe9acfcdb

Device     Boot    Start       End   Sectors Size Id Type
/dev/sda1  *        2048  33552383  33550336  16G 83 Linux
/dev/sda2       33552384 134217727 100665344  48G 83 Linux

Command (m for help): w
The partition table has been altered.
Syncing disks.

4.格式化并添加到自动挂载列表中:

sudo mkfs -t ext4 /dev/sda2
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 12582912 4k blocks and 3151872 inodes
Filesystem UUID: c9a79c6e-6feb-4877-92e5-28b4e0b7e4c9
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done   

查看uuid

~$ lsblk -f|grep ext4
├─sda1 ext4                    e1a7fa70-ec4b-43d9-9d7f-b736419c9dae /
└─sda2 ext4                    c9a79c6e-6feb-4877-92e5-28b4e0b7e4c9 

添加到自动挂载列表中

sudo vim /etc/fstab

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#            
# / was on /dev/sda1 during installation
UUID=e1a7fa70-ec4b-43d9-9d7f-b736419c9dae /               ext4    errors=remount-ro 0       1
UUID=c9a79c6e-6feb-4877-92e5-28b4e0b7e4c9 /home/yeshang/sda2      ext4    errors=remount-ro 0       1
/swapfile                                 none            swap    sw              0       0
 

建立软连接,把sda1上的数据移动到sda2

bin -> sda2/bin

Downloads -> /home/yeshang/sda2/Downloads/

Projects -> sda2/Projects

~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            4.9G     0  4.9G   0% /dev
tmpfs           999M  1.4M  998M   1% /run
/dev/sda1        16G  9.1G  5.9G  61% /
tmpfs           4.9G     0  4.9G   0% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
...

/dev/sda2        47G  4.6G   41G  11% /home/yeshang/sda2

 

你可能感兴趣的:(VirtualBox 硬盘容量扩充)