一、准备
- 扩展虚拟机的磁盘空间
在虚拟机关闭状态下,点击虚拟机>设置>硬盘>扩展:扩展自己需要的容量。
二、开始扩展
idriver@ubuntu:~$ su // 1.切换至root用户
root@ubuntu:/home/idriver# fdisk -l // 2.查看系统的磁盘分区情况
root@ubuntu:/home/idriver# df -TH // 3.查看哪个分区挂载在根目录下
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.1G 0 1.1G 0% /dev
tmpfs tmpfs 207M 6.5M 201M 4% /run
/dev/sda1 ext4 212G 43G 160G 22% /
tmpfs tmpfs 1.1G 218k 1.1G 1% /dev/shm
tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock
tmpfs tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup
tmpfs tmpfs 207M 50k 207M 1% /run/user/1000
root@ubuntu:/home/idriver# fdisk /dev/sda // 4.删除其中的所有分区包括 /dev/sda1,然后在重新建立该分区
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
// 常用命令:
// m 获取帮助
// n 添加新分区
// d 删除分区
// p 打印分区表
// t 更改分区类型
// w 将分区表写入磁盘并保存
Command (m for help): d // 5.删除分区
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n // 6.新建分区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p // 7.选择主分区
Partition number (1-4, default 1):
First sector (2048-419430399, default 2048): // 默认
Last sector, +sectors or +size{K,M,G,T,P} (2048-419430399, default 419430399): //默认
Created a new partition 1 of type 'Linux' and of size 200 GiB.
Command (m for help): p
Disk /dev/sda: 200 GiB, 214748364800 bytes, 419430400 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: 0xe4e5e6cb
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 419430399 419428352 200G 83 Linux
Command (m for help): w // 8.保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy
The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).
保存后出现错误:无视它继续往下执行
root@ubuntu:/home/idriver# partprobe /dev/sda // 9.通知系统内核分区表的变化
root@ubuntu:/home/idriver# resize2fs /dev/sda1 // 10.对文件系统进行扩容
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 13
The filesystem on /dev/sda1 is now 52428544 (4k) blocks long.
root@ubuntu:/home/idriver# df -TH // 11.查看是否扩容成功
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 1.1G 0 1.1G 0% /dev
tmpfs tmpfs 207M 6.6M 201M 4% /run
/dev/sda1 ext4 212G 43G 160G 22% /
tmpfs tmpfs 1.1G 218k 1.1G 1% /dev/shm
tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock
tmpfs tmpfs 1.1G 0 1.1G 0% /sys/fs/cgroup
tmpfs tmpfs 207M 4.1k 207M 1% /run/user/108
tmpfs tmpfs 207M 50k 207M 1% /run/user/1000
三、扩容后造成开机启动等待1分30秒问题解决办法
说明:虚拟机扩容后,使用fdisk /dev/sda 更改新建分区后,重启系统出现一分30秒等待,是由于分区时删除了swap交换分区,造成系统启动过程中无法找到swap分区。
在root用户下创建swap分区:
1.创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)。
# dd if=/dev/zero of=/root/swapfile bs=1M count=1024
2.格式化为交换分区文件:
# mkswap /root/swapfile #建立swap的文件系统
3.启用交换分区文件:
# swapon /root/swapfile #启用swap文件
4.使系统开机时自启用,在文件/etc/fstab中添加一行:
/root/swapfile swap swap defaults 0 0
查看swap分区是否创建成功,看到如下信息说明创建成功:
文章来源:https://www.toymoban.com/news/detail-515482.html
注意要屏蔽/etc/fstab文件内以前的swap:文章来源地址https://www.toymoban.com/news/detail-515482.html
# /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).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda1 during installation
UUID=4c68a6b8-470e-426c-bc69-0fb601719e42 / ext4 errors=remount-ro 0 1
# swap was on /dev/sda5 during installation
#UUID=d19075cc-07e2-472c-b59d-247a15ba333e none swap sw 0 0 // 屏蔽
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0
/root/swapfile swap swap defaults 0 0 // 新增
到了这里,关于linux扩展/dev/sda1分区方法的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!