Linux系统分区命令fdisk的使用

查看硬盘设备分区

root@debian:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 320G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 9G 0 part /
sr0 11:0 1 1024M 0 romlsblk

 

查看硬盘详细分区信息

root@debian:~# fdisk -l
Disk /dev/sda: 320 GiB, 343597383680 bytes, 671088640 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 744D726A-2AC1-7744-89B3-072E6920B57A

Device       Start      End  Sectors Size Type
/dev/sda1     2048     6143     4096   2M BIOS boot
/dev/sda2     6144  2103295  2097152   1G Linux filesystem
/dev/sda3  2103296 20971486 18868191   9G Linux filesystem

 

分区步骤

新建并保存分区

root@debian:~# fdisk /dev/sda    ####分区命令

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): n   ####填入n新建分区
Partition number (4-128, default 4):     ####使用默认的分区编号4
First sector (20971487-671086592, default 20971520):  ####使用默认开始sector
Last sector, +/-sectors or +/-size{K,M,G,T,P} (20971520-671086592, default 671086592):  ####使用默认结束sector,相当于将剩余空间全部分配

Created a new partition 4 of type 'Linux filesystem' and of size 310 GiB.

Command (m for help): w    ####写入分区表,保存
The partition table has been altered.
Syncing disks.

格式化分区

root@debian:~# mkfs.ext4 /dev/sda4
mke2fs 1.46.2 (28-Feb-2021)
Discarding device blocks: done
Creating filesystem with 81264384 4k blocks and 20316160 inodes
Filesystem UUID: 117b8c6d-9abe-45c0-a0d1-c65f7b6304d2
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968

Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

挂载分区

#手动挂载,立即生效
root@debian:~# mount /dev/sda4 /opt/

#设置开机自动挂
root@debian:~# vim /etc/fstab
#在文件最后一行下加入,并保存:
/dev/sda4 /opt ext4 defaults 0 0

 

 

 

THE END
分享
二维码
海报
Linux系统分区命令fdisk的使用
查看硬盘设备分区 root@debian:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 320G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 1G 0 pa……
<<上一篇
下一篇>>