因为运行在VirtualBox中运行的ubuntu虚拟机硬盘空间不够了。所以在停止虚拟机后再设置-》存储中增加了一个虚拟磁盘。完成后重新运行虚拟机。进入ubuntu操作系统。
第一步:ls /dev/sd*
查看新加入的硬盘设备是否已经准备就绪。sda是第一块物理硬盘、sdb是第二块物理硬盘。sdx(x为数字)是该磁盘对应的磁盘分区。
第二步:给磁盘分区
sudo fdisk /dev/sdb
我新加的磁盘是sdb
分区一个例子如下
-
Command
(m for help): -
这里按m获得帮助
-
a
toggle a bootable flag 将分区设置为启动区 -
b
edit bsd disklabel 编辑bsd的disklabel -
c
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 table -
p
print the partition table查看分区信息 -
q
quit without saving changes 退出不保存 -
s
create a new empty Sun disklabel -
t
change a partition's system id改变分区类型 -
u
change display/entry units -
v
verify the partition table -
w
write table to disk and exit 保存退出 -
x
extra functionality (experts only) -
-
Command
(m for help):p //查看新硬盘的分区 -
********************************************************************
- Device Boot Start End Blocks Id System
- /dev/sdb1 * 2048 390625279 195311616 83 Linux
- /dev/sdb2 390627326 1953523711 781448193 5 Extended
- /dev/sdb5 390627328 1936764927 773068800 83 Linux
- /dev/sdb6 1936766976 1953523711 8378368 82 Linux swap / Solaris
-
-
********************************************************************
-
Command
(m for help):n //创建新分区 -
File
system type (default ext2): ext3 //输入想使用的分区格式 -
Partition
name: backup //输入分区的名字 -
First
cylinder (default 0cyl): //第几个柱面,我们按照默认 -
Last
cylinder or +size or +sizeMB or +sizeKB (default 0cyl):+1000000M //这里我们按大小输入 即+1000000M (注意这个M为大写) -
Warning:
You requested a partition from 0cyl to 121576cyl. -
The
closest location we can manage is 1cyl to 121575cyl. Is this still -
acceptable
to you? -
y Yes -
n No -
当然是y
-
-
Command
(m for help): w -
Information:
Don't forget to update /etc/fstab, if necessary. //写入硬盘分区属性并结束
我将整个硬盘分成一个ext2的主分区
第三步:格式化硬盘
sudo mkfs -t ext2 /dev/sdb1
第三步:自动挂载分区
sudo vi /etc/fstab
在其中增加一条
/dev/sdb1 挂载点(即访问的目录) ext2 defaults 1
2
或者手工挂载分区
mount -vl -t ext3 /dev/sdb1 /home/xxxxx