Linux分区之路:从零开始(linux分区1)
Linux的分区实现,是将多个物理硬盘,网络磁盘,及其他存储设备,抽象为一个或多个逻辑卷,用户可以自由指定每个逻辑卷的大小。因此,Linux分区是操作系统中避免硬盘浪费和文件管理混乱的很好方法。
分区操作,需要使用fdisk工具,进入Linux终端,执行”fdisk -l”查看当前可分区的硬盘:
$ fdisk -l
Disk /dev/sda: 6 TB, 600037355589 bytes, 11717883720 sectorsUnits: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dosDisk identifier: 0x9fbd0556
Device Boot Start End Sectors Size Id Type/dev/sda1 * 4980738544 5344331775 356253224 170G 7 HPFS/NTFS/exFAT
/dev/sda2 5344332032 11717883391 6373551360 3TB 7 HPFS/NTFS/exFAT
其中,/dev/sda为可以分区的硬盘;可以看到当前/dev/sda有两个分区,/dev/sda1和/dev/sda2。
接下来就可以执行fdisk 进行分区操作了,在终端内执行`fdisk /dev/Sda`,进入fdisk 的交互界面:
$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.34).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help):
在fdisk的命令菜单中,可以使用n创建新的分区,可以指定新的分区的大小,新的分区将被创建在未使用的空间里:
Command (m for help): n
Partition type p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)Select (default p): p
Partition number (1-4, default 1): 1First sector (2048-11717883391, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-11717883391, default 11717883391): +10G
Created a new partition 1 of type 'Linux' and of size 10 GiB.
接下来,可以使用w将分区写入分区表,fdisk才能生效,新的分区将被挂载:
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.Syncing disks.
最后输入mount,新建的分区/dev/sda1就完成挂载了:
$ mount /dev/sda1 /mnt/new_partition
总的来说,Linux的分区非常简单,只需要使用fdisk工具,按照规则进行操作,就可以完成对硬盘的分区,有效的管理硬盘以及避免硬盘浪费。