Skip to content

挂载

挂载新硬盘

1.查看硬盘

root@ubuntu:~# fdisk -lu
Disk /dev/sda: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x3c78b7a1

Device     Boot    Start      End  Sectors Size Id Type
/dev/sda1  *        2048 16777215 16775168   8G 83 Linux
/dev/sda2       16779262 20969471  4190210   2G  5 Extended
/dev/sda5       16779264 20969471  4190208   2G 82 Linux swap / Solaris

Partition 2 does not start on physical sector boundary.


Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

2.创建分区

root@ubuntu:~# fdisk /dev/sdb

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.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xdf96fde2.

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):
First sector (2048-104857599, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):

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

Command (m for help): p
Disk /dev/sdb: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xdf96fde2

Device     Boot Start       End   Sectors Size Id Type
/dev/sdb1        2048 104857599 104855552  50G 83 Linux

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

3.格式化分区

root@ubuntu:~# mkfs.ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Discarding device blocks: 完成
Creating filesystem with 13106944 4k blocks and 3276800 inodes
Filesystem UUID: c0887faa-eed2-4f38-9f18-6e3059261202
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624, 11239424

Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

4.挂载和查看分区表

root@ubuntu:~# mount /dev/sdb1 /data
root@ubuntu:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            2.0G     0  2.0G   0% /dev
tmpfs           395M  5.5M  389M   2% /run
/dev/sda1       7.8G  1.2G  6.2G  16% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs           395M     0  395M   0% /run/user/0
/dev/sdb1        50G   52M   47G   1% /data

5.永久挂载

# 执行前一定要进行备份,以免误操作
echo '/dev/sdb1       /data   ext4    defaults        0       0' >> /etc/fstab

映射硬盘

eg: 将 docker lib 目录映射到 /data/lib/docker

echo '/data/lib/docker /var/lib/docker none defaults,bind 0 0'>>/etc/fstab

fstab 立即生效

mount -a

Comments