Linux下添加新硬盘,分区及挂载

本文详细介绍了如何查看硬盘、分区、格式化分区以及挂载硬盘的过程,包括使用fdisk命令进行分区和格式化,以及如何通过mount命令挂载分区。同时,文章还演示了如何将分区挂载到特定目录,并通过编辑fstab文件实现开机自动挂载。

1:查看挂载好的硬盘

   

[root@localhost ~]# fdisk -l

#-------------- 第一块硬盘 /dev/xvda --------------------------
Disk /dev/xvda: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 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: 0x000af342

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64       26109   209202176   8e  Linux LVM

Disk /dev/xvdd: 118 MB, 118593536 bytes
255 heads, 63 sectors/track, 14 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: 0x00000000


Disk /dev/mapper/VolGroup-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 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: 0x00000000


Disk /dev/mapper/VolGroup-lv_home: 158.4 GB, 158418862080 bytes
255 heads, 63 sectors/track, 19259 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: 0x00000000

#-------------- 第二块硬盘 /dev/xvdb --------------------------
Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000

#-------------- 第三块硬盘 /dev/xvdc --------------------------
Disk /dev/xvdc: 63.4 GB, 63350767616 bytes
255 heads, 63 sectors/track, 7701 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: 0x00000000

 

2:硬盘分区

上面很清楚,是三块硬盘。

第一块已经在使用了,第二,第三块还为分区。那我们下面来格式化(格式化命令: fdisk 挂载盘)

 

 

#fdisk /dev/xvdb 格式化这块硬盘

[root@localhost ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x40a24247.
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').

# fdisk 如果你不熟悉的话,就输入m,就是menu的意思。所有的fdisk命令尽收眼底
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

#对照上面 我是想新增一个分区
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
#主分区我已经有了,这里我就做逻辑分区吧。 
e

#这里没有什么意思,就是分几个区,每个区大小事多少。我这里就一个区,大小全部。具体操作见下面
Partition number (1-4): 1
First cylinder (1-6527, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): 
Using default value 6527

#其实到这里,分区并没完成。 需要写入。 这里w 对照上面的菜单看
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
# 不用说了,到此已经创建完成了。

 

比较一下分区前后的硬盘信息 还是用fdisk -l

 

#这里是分区前的信息

Disk /dev/xvdc: 63.4 GB, 63350767616 bytes
255 heads, 63 sectors/track, 7701 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: 0x00000000

 

 

 

# 这里是分区后的信息

Disk /dev/xvdb: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x40a24247

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdb1               1        6527    52428096    5  Extended

 

 

3:格式化分区

输入fdisk -l 查看以前的新创建的分区。 然后用mkfs -t ext3 -c [新分区] 进行格式化。

#查询硬盘上的分区

Disk /dev/xvdc: 63.4 GB, 63350767616 bytes
255 heads, 63 sectors/track, 7701 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: 0x210fa633

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1               1        7701    61858251   83  Linux

 

格式化/dev/xvdc1

[root@localhost ~]# mkfs -t ext3 -c /dev/xvdc1
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
3866624 inodes, 15464562 blocks
773228 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
472 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

Checking for bad blocks (read-only test): done                                
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

 

4:挂载

我们现在来看一下硬盘的目录信息 df -h

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  1.1G   46G   3% /
tmpfs                 497M     0  497M   0% /dev/shm
/dev/xvda1            485M   32M  428M   7% /boot
/dev/mapper/VolGroup-lv_home
                      146G  3.4G  135G   3% /home

 

挂载:

将/dev/xvdc1 挂载到 /disk2 下
[root@localhost /]# mkdir /disk2
[root@localhost /]# mount /dev/xvdc1 /disk2

 

我们现在再来看一下硬盘的目录信息

[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  1.1G   46G   3% /
tmpfs                 497M     0  497M   0% /dev/shm
/dev/xvda1            485M   32M  428M   7% /boot
/dev/mapper/VolGroup-lv_home
                      146G  3.4G  135G   3% /home
/dev/xvdc1             59G  180M   55G   1% /disk2

 

到此挂载就完成了。如果你重启机器以后,你会发现。disk2的目录又没了。不得重新挂载一次;当然这个肯定不是长久的解决方法

[root@localhost /]# vi /etc/fstab

增加一行:
/dev/xvdc1	/disk2	ext3	defaults	0 0

 

现在才真正的完成了。

 

 

 

 

 

 

 

 

 

 

采用PyQt5框架与Python编程语言构建图书信息管理平台 本项目基于Python编程环境,结合PyQt5图形界面开发库,设计实现了一套完整的图书信息管理解决方案。该系统主要面向图书馆、书店等机构的日常运营需求,通过模块化设计实现了图书信息的标准化管理流程。 系统架构采用典型的三层设计模式,包含数据存储层、业务逻辑层和用户界面层。数据持久化方案支持SQLite轻量级数据库与MySQL企业级数据库的双重配置选项,通过统一的数据库操作接口实现数据存取隔离。在数据建模方面,设计了包含图书基本信息、读者档案、借阅记录等核心数据实体,各实体间通过主外键约束建立关联关系。 核心功能模块包含六大子系统: 1. 图书编目管理:支持国际标准书号、中国图书馆分类法等专业元数据的规范化著录,提供批量导入与单条录入两种数据采集方式 2. 库存动态监控:实时追踪在架数量、借出状态、预约队列等流通指标,设置库存预警阈值自动提醒补货 3. 读者服务管理:建立完整的读者信用评价体系,记录借阅历史与违规行为,实施差异化借阅权限管理 4. 流通业务处理:涵盖借书登记、归还处理、续借申请、逾期计算等标准业务流程,支持射频识别技术设备集成 5. 统计报表生成:按日/月/年周期自动生成流通统计、热门图书排行、读者活跃度等多维度分析图表 6. 系统维护配置:提供用户权限分级管理、数据备份恢复、操作日志审计等管理功能 在技术实现层面,界面设计遵循Material Design设计规范,采用QSS样式表实现视觉定制化。通过信号槽机制实现前后端数据双向绑定,运用多线程处理技术保障界面响应流畅度。数据验证机制包含前端格式校验与后端业务规则双重保障,关键操作均设有二次确认流程。 该系统适用于中小型图书管理场景,通过可扩展的插件架构支持功能模块的灵活组合。开发过程中特别注重代码的可维护性,采用面向对象编程范式实现高内聚低耦合的组件设计,为后续功能迭代奠定技术基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值