一、安装硬盘到物理机上。(略)
二、查看硬盘是否正确安装。
使用“fdisk -l”命令查看硬盘代号。
- root@greatms-All-Series:/home/share# fdisk -l
- Disk /dev/sda: 500.1 GB, 500107862016 bytes
- 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
- Units = 扇区 of 1 * 512 = 512 bytes
- Sector size (logical/physical): 512 bytes / 4096 bytes
- I/O size (minimum/optimal): 4096 bytes / 4096 bytes
- Disk identifier: 0x000aab9b
- 设备 启动 起点 终点 块数 Id 系统
- /dev/sda1 * 2048 488282111 244140032 83 Linux
- /dev/sda2 488284158 976771071 244243457 5 扩展
- Partition 2 does not start on physical sector boundary.
- /dev/sda5 488284160 820314111 166014976 83 Linux
- /dev/sda6 820316160 976771071 78227456 82 Linux 交换 / Solaris
- WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
- Disk /dev/sdb: 3000.6 GB, 3000592982016 bytes
- 255 heads, 63 sectors/track, 364801 cylinders, total 5860533168 sectors
- Units = 扇区 of 1 * 512 = 512 bytes
- Sector size (logical/physical): 512 bytes / 4096 bytes
- I/O size (minimum/optimal): 4096 bytes / 4096 bytes
- Disk identifier: 0x00000000
- 设备 启动 起点 终点 块数 Id 系统
- /dev/sdb1 1 4294967295 2147483647+ ee GPT
- Partition 1 does not start on physical sector boundary.
三、将硬盘分区。
1、当硬盘小于等于2T时,可以用fdisk。
- fdisk /dev/sdb
- 1、查看帮助。
- 输入:m
- 2、新建分区。
- 输入:n
- 3、创建逻辑分区
- 输入:p
- 4、输入分区号以及指定分区大小
- 依照提示,回车表示默认。
- 5、检查分区情况(此时还未执行分区操作)
- Command(m for help):p
- 6、保存退出
- Command(m for help):w
2、当硬盘大于2T时,用parted命令。
- parted /dev/sdb (用part命令对3T硬盘进行分区处理)
- mklabel gpt (用gpt格式可以将3TB弄在一个分区里)
- unit TB (设置单位为TB)
- mkpart primary 0 3 (设置为一个主分区,大小为3TB,开始是0,结束是3)
- print (显示设置的分区大小)
- quit (退出parted程序)
四、格式化分区。
mkfs.ext4 /dev/sdb1
五、将硬盘挂载到文件夹下。
1、手动挂载。
新建一个文件夹:mkdir /home/sdb1
挂载:mount /dev/sdb1 /home/sdb1
2、开机自动挂载。
输入:vi /etc/fstab
在最后加入:
- /dev/sdb1 /home/sdb1 ext4 defaults 1 1
Linux扩容时新建分区报错No free sectors available
扩展后执行fdisk -l查看是否成功
[root@localhost ~ ]# fdisk - l
Disk / dev / sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors / track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/ dev / sda1 * 1 6 48163 + 83 Linux
/ dev / sda2 7 515 4088542 + 83 Linux
/ dev / sda3 516 1239 5815530 83 Linux
/ dev / sda4 1240 1305 530145 5 Extended
/ dev / sda5 1240 1305 530113 + 82 Linux swap / Solaris
Disk / dev / sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors / track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/ dev / sda1 * 1 6 48163 + 83 Linux
/ dev / sda2 7 515 4088542 + 83 Linux
/ dev / sda3 516 1239 5815530 83 Linux
/ dev / sda4 1240 1305 530145 5 Extended
/ dev / sda5 1240 1305 530113 + 82 Linux swap / Solaris
可见sda已经扩展成为16G,但是没分配给文件系统
继续执行fdisk /dev/sda进行新建磁盘
[root@localhost ~ ]# fdisk / dev / sda
The number of cylinders for this disk is set to 1958 .
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
No free sectors available
The number of cylinders for this disk is set to 1958 .
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
No free sectors available
前面执行fdisk -l的时候明明最后才是1305柱面,而且应该有1958柱面,为什么说没有空闲的扇区。
再看看fdisk -l执行结果,原来是/dev/sda5分配了作为swap分区,找到原因了就容易解决。
1.关闭swap分区 # swapoff /dev/sda5
2.删除sda4和sda5.
[root@localhost ~ ]# fdisk / dev / sda
The number of cylinders for this disk is set to 1958 .
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): d
Partition number ( 1 - 5 ): 5
Command (m for help): d
Partition number ( 1 - 5 ): 4
The number of cylinders for this disk is set to 1958 .
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): d
Partition number ( 1 - 5 ): 5
Command (m for help): d
Partition number ( 1 - 5 ): 4
3.建立扩展分区4,建立分区sda5,写入
Command (m
for help): n
Command action
e extended
p primary partition ( 1 - 4 )
e
Selected partition 4
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): n
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): w
The partition table has been
Command action
e extended
p primary partition ( 1 - 4 )
e
Selected partition 4
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): n
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): w
The partition table has been
文章来自:
1. http://blog.youkuaiyun.com/season_hangzhou/article/details/36423223
2. http://hchmsguo.iteye.com/blog/1226666
本文详细介绍了如何在物理机上安装硬盘并进行分区的过程。包括使用fdisk命令查看硬盘信息,针对不同大小的硬盘选择合适的分区工具(如fdisk或parted),以及格式化和挂载硬盘的具体步骤。
8124

被折叠的 条评论
为什么被折叠?



