1、编辑虚拟机设置,新增一块虚拟硬盘,同新安装虚拟机之前;
2、查看磁盘容量和分区情况,但是不能查看未挂载分区
df -Th
3、查看未挂载分区
fdisk -llsblk -f
4、创建分区
ls /dev/sd*
此命令能看到硬盘设备情况,例如我的电脑,原来有一个硬盘,对应/dev/sda;现在多了一个硬盘,对应/dev/sdb,确保sdb为新硬盘(否则格式化的时候,里面的文件会丢失)
sudo fdisk /dev/sdb
此命令进行创建分区,会出现类似如下内容,具体fdisk用法这里不详细介绍了:
Command (m for help): 这里按m获得帮助a toggle a bootable flag 将分区设置为启动区b edit bsd disklabel 编辑bsd的disklabelc toggle the dos compatibility flag 设置该分区为dos分区d delete a partition 删除分区l list known partition types 列出已知的分区类型m print this menu 打印帮助列表n add a new partition 创建新分区o create a new empty DOS partition tablep print the partition table查看分区信息q quit without saving changes 退出不保存s create a new empty Sun disklabelt change a partition's system id改变分区类型u change display/entry unitsv verify the partition tablew write table to disk and exit 保存退出x extra functionality (experts only)
按照步骤创建分区,我这里创建一个,按下n后,依照提示做即可,这里会创建/dev/sdb分区,按下p命令可以查看
d先删除,然后w保存退出
5、格式化分区
sudo mkfs -t ext4 /dev/sdbeg:mkfs.ext4 /dev/sdb
格式化为ext4格式
6、设置挂载点
sudo mkdir /home/NewPartion
在你想要的目录下设置要挂载的目录,我这里设置为/home/NewPartition
eg:mkdir /mnt/data
7、挂载
mount /dev/sdb /mnt/data
8、设置开机挂载
ls -l /dev/disk/by-uuid/
首先查看sdb所对应的UUID,我的是28618a8e-9573-4b2a-b5dd-f91f462a1e23
sudo vim /etc/fstab
我这里在fstab的最后一行添加如下设置:
UUID=28618a8e-9573-4b2a-b5dd-f91f462a1e23 /mnt/data ext4 defaults 0 2
附:
root@ubuntu:~# lsblk -fNAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINTloop0 squashfs 0 100% /snap/core18/1880loop1 squashfs 0 100% /snap/lxd/18150loop2 squashfs 0 100% /snap/core18/1932loop3 squashfs 0 100% /snap/snapd/8542loop4 squashfs 0 100% /snap/lxd/16099loop5 squashfs 0 100% /snap/snapd/9721sda ├─sda1 ├─sda2 ext4 edd57483-2395-491f-bbeb-7099d01fee37 805.3M 11% /boot└─sda3 LVM2_member yYQ8O6-aXWf-CQHX-c1BY-cGLS-TfyR-KuqvaB └─ubuntu--vg-ubuntu--lv ext4 98ed31c8-c164-4437-b454-fba947a22a94 7.3G 57% /sdb ext4 28618a8e-9573-4b2a-b5dd-f91f462a1e23 18.5G 0% /mnt/datasr0 iso9660 Ubuntu-Server 20.04.1 LTS amd64 2020-07-31-17-35-29-00 root@ubuntu:~#
或者:
在/etc/fstab中追加
/dev/sdb /mnt/data ext4 defaults 0 0
附:
# /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/ubuntu-vg/ubuntu-lv during curtin installation/dev/disk/by-id/dm-uuid-LVM-A1e9XMIhqWgtODAmCtD1QYGRkMzCUd347w2AKX6OfGvNmh4v3Xl6KdjAj0MaE8tn / ext4 defaults 0 0# /boot was on /dev/sda2 during curtin installation/dev/disk/by-uuid/edd57483-2395-491f-bbeb-7099d01fee37 /boot ext4 defaults 0 0/swap.img none swap sw 0 0/dev/sdb /mnt/data ext4 defaults 0 0
9、设置完成后重启即可
用df -h查看是否挂载成功