跳到主要内容

挂载新磁盘分区

查找新磁盘

fdisk -l
root@ubuntu-mssql:/home/wengtx# fdisk -l

Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: QEMU HARDDISK
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: gpt
Disk identifier: B829DE96-F76E-4A36-B50B-5A53DF1949C2

Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 104855551 100657152 48G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 24 GiB, 25765609472 bytes, 50323456 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


Disk /dev/mapper/ubuntu--vg-lv--0: 24 GiB, 25769803776 bytes, 50331648 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


Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

创建并格式化分区

例如: 新挂载的磁盘是/dev/sdb,现在开始对该硬盘进行分区:

fdisk /dev/sdb
root@ubuntu-mssql:/home/wengtx# fdisk /dev/sdb

# 输入“n”创建新分区
# 输入“p”将新分区设置为主分区
# 按默认将整个磁盘设置为一个主分区
# 输入“w”保存并退出

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

Device does not contain a recognized partition table.
Created a new DOS (MBR) disklabel with disk identifier 0x91f36f64.

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

Created a new partition 1 of type 'Linux' and of size 500 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

重新查询磁盘

fdisk -l
root@ubuntu-mssql:/home/wengtx# fdisk -l
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Disk model: QEMU HARDDISK
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: gpt
Disk identifier: B829DE96-F76E-4A36-B50B-5A53DF1949C2

Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 4198399 4194304 2G Linux filesystem
/dev/sda3 4198400 104855551 100657152 48G Linux filesystem


Disk /dev/mapper/ubuntu--vg-ubuntu--lv: 24 GiB, 25765609472 bytes, 50323456 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


Disk /dev/mapper/ubuntu--vg-lv--0: 24 GiB, 25769803776 bytes, 50331648 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


Disk /dev/sdb: 500 GiB, 536870912000 bytes, 1048576000 sectors
Disk model: QEMU HARDDISK
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: 0x91f36f64

Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 1048575999 1048573952 500G 83 Linux

fdisk相关介绍

也可以输入“m”进入帮助:

a:指定启动分区
d:删除原分区
l:显示分区ID号列表
m:查看fdisk帮助
n:创建新分区
p:显示分区列表
t:修改分区类型ID号
w:保存配置并生效
分区模式说明:
p:创建主分区
e:创建扩展分区

格式化磁盘

mkfs.ext3 /dev/sdb1

格式化后就可以使用了,下面开始介绍挂载至新目录和扩容至某个原分区。

挂载至新目录

以下是将磁盘挂载至新目录的命令:

mkdir /data
mount /dev/sdb1 /data

设置开机自动挂载,否则重启就找不到磁盘了,编辑 /etc/fstab 加入:

cat >> /etc/fstab <<EOF
# 挂载data磁盘
/dev/sdb1 /data ext3 defaults 0 0
EOF