
正文
Linux磁盘分区、格式化和挂载
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、查看磁盘使用
[root@iZ88rvassw1Z ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 40G 2.3G 36G 7% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
二、查看磁盘分区
[root@iZ88rvassw1Z ~]# fdisk -lDisk /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 LinuxDisk /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
目前系统存在了两块磁盘,分别为“/dev/vda”和“/dev/vdb”;
“/dev/vda”已经存在了一个分区“/dev/vda1”;
“/dev/vda1”没有分区。
三、磁盘分区命令

四、执行分区操作
[root@iZ88rvassw1Z ~]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3d7d21d6.
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').Command (m for help): pDisk /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: 0x3d7d21d6 Device Boot Start End Blocks Id SystemCommand (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
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 2130440Command (m for help): pDisk /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: 0x3d7d21d6 Device Boot Start End Blocks Id System
/dev/vdb1 1 2130440 1073741728+ 83 LinuxCommand (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
No free sectors availableCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ88rvassw1Z ~]#
再次查看分区:

五、查看原有分区格式

为ext4格式。
六、格式化分区

七、挂载分区

八、开机自动挂载
修改/etc/fstab,添加记录即可。









