Linux 下挂载硬盘的 方法

装虚拟机时空间划小了,于是又加了 5G 的空间,折腾了半天,挂上去了。整理下弄个笔记,备用。

  1. 添加磁盘,查看磁盘状况

root@db1 /\]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 \* 512 = 8225280 bytes |-----------|------|-------|-----|---|---|--------|----|------------| | Device | Boot | Start | End || Blocks || Id | System | | /dev/sda1 | \* | 151 | 1305 || 9277537+ || 83 | Linux | | /dev/sda2 | | 1 | 150 || 1204843+ || 82 | Linux swap | | Partition table entries are not in disk order Disk /dev/sdb: 5368 MB, 5368709120 bytes ||||||| | | | 255 heads, 63 sectors/track, ||| 652 | cylinders || | | | | Units = cylinders of 16065 \* ||| 512 | = 8225280 || bytes | | | | Device Boot Start ||| | End || Blocks | Id | System | 从查询结果看出,多了一个/dev/sdb的盘 1. ****用**** ****fdisk**** ****对**** ****/dev/sdb**** ****进展分区**** \[root@db1 /\]# fdisk /dev/sdb Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-652, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): Using default value 652 Command (m for help): w The partition table has been altered! Calling ioctl to re-read partition table. Syncing disks. 再次查看分区状况,多出来一个/dev/sdb1 的区,这个 1 是我们在前面指定的,假设我们指定 2,就变成 sdb2 了。 \[root@db1 /\]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 \* 512 = 8225280 bytes |-----------|-------|-------------|-------------|----------|----|------------| | Device | Boot | Start | End | Blocks | Id | System | | /dev/sda1 | \* | 151 | 1305 | 9277537+ | 83 | Linux | | /dev/sda2 | | 1 | 150 | 1204843+ | 82 | Linux swap | | Partition | table | entries are | not in disk | order | | | Disk /dev/sdb: 5368 MB, 5368709120 bytes 255 heads, 63 sectors/track, 652 cylinders Units = cylinders of 16065 \* 512 = 8225280 bytes |------------|------|-------|-----|----------|----|--------| | Device | Boot | Start | End | Blocks | Id | System | | /dev/sdb1 | | 1 | 652 | 5237158+ | 83 | Linux | | \[root@db1 | /\]# | | | | | | 假设创立完之后,/proc/partitions 查看不到对应的分区,使用 parprobe 命令刷一下就可以了: \[root@web1 \~\]# cat /proc/partitions major minor #blocks name |---|---|---------------| | 8 | 0 | 175825944 sda | | 8 | 1 | 1020236 sda1 | | 8 | 2 | 30716280 sda2 | 8 3 8193150 sda3 \[root@web1 \~\]# partprobe /dev/sda \[root@web1 \~\]# cat /proc/partitions major minor #blocks name |---|---|----------------| | 8 | 0 | 175825944 sda | | 8 | 1 | 1020236 sda1 | | 8 | 2 | 30716280 sda2 | | 8 | 3 | 8193150 sda3 | | 8 | 4 | 135893835 sda4 | \[root@web1 \~\]# 1. ****格式化**** ****/dev/sdb1**** ****分区**** \[root@db1 /\]# mkfs -t ext3 /dev/sdb1 mke2fs 1.35 (28-Feb-2023) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 655360 inodes, 1309289 blocks 65464 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 16384 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 30 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. 1. ****创立名目 并将**** ****/dev/sdb1**** ****挂在到该名目下**** \[root@db1 /\]# ls |--------|------|------------|-------|------|---------|----------|-----| | backup | dev | initrd | media | opt | sbin | sys | usr | | bin | etc | lib | misc | proc | selinux | tftpboot | var | | boot | home | lost+found | mnt | root | srv | tmp | | | \[root@db1 /\]# || mkdir /u01 | | | | | | | \[root@db1 /\]# || ls | | | | | | | backup dev || initrd | media | opt | sbin | sys | u01 | | bin etc || lib | misc | proc | selinux | tftpboot | usr | | boot home || lost+found | mnt | root | srv | tmp | var | \[root@db1 /\]# mount /dev/sdb1 /u01 1. ****验证挂载是否成功**** |----------------------------|----|----|-----------|---------|-----------|------|------------| | \[root@db1 /\]# Filesystem | df | -k | 1K-blocks | Used | Available | Use% | Mounted on | | /dev/sda1 | | | 9131772 | 7066884 | 1601012 | 82% | / | | none | | | 454256 | 0 | 454256 | 0% | /dev/shm | | /dev/sdb1 | | | 5154852 | 43040 | 4849956 | 1% | /backup | 1. **设置开机自动挂载** \[root@db1 /\]# vi /etc/fstab # This file is edited by fstab-sync - see "man fstab-sync" for details |-----------------|----------|--------|----------------|---|---| | LABEL=/ | / | ext3 | defaults | 1 | 1 | | none | /dev/pts | devpts | gid=5,mode=620 | 0 | 0 | | none | /dev/shm | tmpfs | defaults | 0 | 0 | | none | /proc | proc | defaults | 0 | 0 | | none | /sys | sysfs | defaults | 0 | 0 | | LABEL=SWAP-sda2 | swap | swap | defaults | 0 | 0 |

相关推荐
Alex艾力的IT数字空间2 小时前
在 Kylin(麒麟)操作系统上搭建 Docker 环境
大数据·运维·缓存·docker·容器·负载均衡·kylin
嵌入式学习和实践2 小时前
虚拟机 Ubuntu 磁盘扩容完全指南:从原理到实践,一步到位
linux·ubuntu·磁盘扩容
陳10302 小时前
Linux:进程间切换与调度
linux·运维·服务器
lcreek2 小时前
Linux 虚拟文件系统的建立与使用全过程解析
linux·虚拟文件系统·vfs
寒秋花开曾相惜3 小时前
(学习笔记)第四章 处理器体系结构
linux·网络·数据结构·笔记·学习
疏星浅月3 小时前
虚拟内存三大核心作用详解
linux·c语言·arm开发·嵌入式硬件
邂逅星河浪漫4 小时前
【银行内网开发-管理端】Vue管理端+Auth后台开发+Nginx配置+Linux部署(详细解析)
linux·javascript·css·vue.js·nginx·html·前后端联调
JJay.4 小时前
Android BLE 稳定连接的关键,不是扫描,而是 GATT 操作队列
android·服务器·前端
SilentSamsara4 小时前
TCP 三次握手:连接建立失败的那些坑
运维·服务器·网络·网络协议·tcp/ip
码农小钻风5 小时前
利用Samba实现局域网跨平台共享文件
linux·samba·共享