查看已有硬盘
localhost:~# fdisk -l
Disk /dev/sdb: 20 GB, 21474836480 bytes, 41943040 sectors
2610 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sda: 16 GB, 17179869184 bytes, 33554432 sectors
2088 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 0,32,33 38,94,56 2048 616447 614400 300M 83 Linux
/dev/sda2 38,94,57 299,116,9 616448 4810751 4194304 2048M 82 Linux swap
/dev/sda3 299,116,10 1023,254,63 4810752 16777215 11966464 5843M 83 Linux
格式化新硬盘
localhost:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI, OSF or GPT disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that the previous content
won't be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Partition type
p primary partition (1-4)
e extended
p
Partition number (1-4): 1
First sector (63-41943039, default 63): 63
Last sector or +size{,K,M,G,T} (63-41943039, default 41943039):
Using default value 41943039
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table
查看操作效果:
localhost:~# fdisk -l
Disk /dev/sdb: 20 GB, 21474836480 bytes, 41943040 sectors
2610 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sdb1 0,1,1 1023,254,63 63 41943039 41942977 19.9G 83 Linux
Disk /dev/sda: 16 GB, 17179869184 bytes, 33554432 sectors
2088 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes
Device Boot StartCHS EndCHS StartLBA EndLBA Sectors Size Id Type
/dev/sda1 * 0,32,33 38,94,56 2048 616447 614400 300M 83 Linux
/dev/sda2 38,94,57 299,116,9 616448 4810751 4194304 2048M 82 Linux swap
/dev/sda3 299,116,10 1023,254,63 4810752 16777215 11966464 5843M 83 Linux
格式化sdb1分区为ext4文件格式:
mke2fs -t ext4 /dev/sdb1
挂载新硬盘
- 创建用来挂载新磁盘的目录:
mkdir -p /mnt/dockerdata
- 挂载新磁盘到目录:
mount /dev/sdb1 /mnt/dockerdata
输入以下命令,配置永久性挂载:
# 追加硬盘挂载配置到配置文件中
echo "/dev/sdb1 /mnt/dockerdata ext4 defaults 0 0" >> /etc/fstab
这样关机再开机就不会掉盘了。
输入 df -h
命令, 验证操作结果