Centos7.9 挂载磁盘
FCAT 2023/12/14 docker
# 1 查看磁盘列表
[root@iZwz9fvttmu9vq3q9suje6Z ~]# fdisk -l
1
Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078f9c
Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41940992 83 Linux
Disk /dev/vdb: 1099.5 GB, 1099511627776 bytes
16 heads, 63 sectors/track, 2130440 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/vdc: 1099.5 GB, 1099511627776 bytes
16 heads, 63 sectors/track, 2130440 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
可以看出有一个系统盘/dev/vda 创建了一个分区/dev/vda1
还有两个磁盘/dev/vdb 和/dev/vdc ,这两个磁盘没有分区
#2 创建分区
[root@iZwz9fvttmu9vq3q9suje6Z dev]# fdisk /dev/vdb
1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x66dab213.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
### 按提示操作 p打印 n新增 d 删除 w操作生效 q退出
Command (m for help): d
No partition is defined yet!
Command (m for help): p
Disk /dev/vdb: 1099.5 GB, 1099511627776 bytes
16 heads, 63 sectors/track, 2130440 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x66dab213
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (1-2130440, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2130440, default 2130440):
Using default value 2130440
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZwz9fvttmu9vq3q9suje6Z dev]# df -h
1
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 38G 0 100% /
tmpfs 16G 0 16G 0% /dev/shm
# 3 格式化分区
[root@iZwz9fvttmu9vq3q9suje6Z mnt]# mkfs.ext3 /dev/vdb2
1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
67108864 inodes, 268435432 blocks
13421771 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
8192 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# 4 挂载/dev/vdb2到/mnt
[root@iZwz9fvttmu9vq3q9suje6Z mnt]# mount -t ext3 /dev/vdb2 /mnt
[root@iZwz9fvttmu9vq3q9suje6Z mnt]# df -h
1
2
2
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 16G 22G 42% /
tmpfs 16G 0 16G 0% /dev/shm
/dev/vdb2 1008G 200M 957G 1% /mnt
# 5 设置开机挂载
[root@iZwz9fvttmu9vq3q9suje6Z mnt]# echo "/dev/vdb2 /mnt ext3 defaults 1 2" >> /etc/fstab
[root@iZwz9fvttmu9vq3q9suje6Z mnt]# mount
1
2
2
# 6 将新硬盘临时挂载到home目录下
#cd /
#umount /dev/vdb2
#cd /mnt/
#mkdir home
#mount /dev/vdb2 /mnt/home #挂载到/mnt/home
#df -h 查看
#cp -a /home/* /mnt/home/ #把home下的东西拷到挂载的目录下,备份
#rm -rf /home/* #把home下的东西删干净
#umount /dev/vdb2 #卸载硬盘
#df -h #查看
#mount /dev/vdb2 /home
#vim /etc/fstab
修改/dev/vdb2 /home ext3 defaults 1 2
#mount
#reboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 扩展
在挂载超过2T,需要使用gpt分区
sudo parted /dev/sdb
mklabel gpt # 创建 GPT 分区表
unit TB # 设置单位为 TB
mkpart primary 0.00TB 8.00TB # 创建一个从 0TB 到 8TB 的主分区
输入 quit 退出 parted。
对分区进行格式化:sudo mkfs.ext4 /dev/sdb
再挂载:mount /dev/sdb /docker
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9