FDISK linux 磁盘分区
1、fdisk -l
查看磁盘信息(比如我们通过 fdisk -l 得知 /dev/hda 或者 /dev/sda 设备)
2、fdisk /dev/hda
进行分区
3、fdisk 下的 p 可以查看该磁盘大小及状态
Command (m for help): p
Disk /dev/sdc: 1023 GiB, 1098437885952 bytes, 2145386496 sectors
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: dos
Disk identifier: 0x80e01358
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 83 Linux
/dev/sdc2 1048578048 2145386495 1096808448 523G 83 Linux
4、fdisk下的m 可以查看帮助信息
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
5、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):
First sector (2048-2145386495, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-2145386495, default 2145386495): +500G
Created a new partition 1 of type 'Linux' and of size 500 GiB.
6、通过fdisk 下的 p 查看分区情况
Command (m for help): p
Disk /dev/sdc: 1023 GiB, 1098437885952 bytes, 2145386496 sectors
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: dos
Disk identifier: 0x80e01358
Device Boot Start End Sectors Size Id Type
/dev/sdc1 2048 1048578047 1048576000 500G 83 Linux
/dev/sdc2 1048578048 2145386495 1096808448 523G 83 Linux
7、fdisk 下的 w 可以保持分区信息
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
8、mkfs.ext4 /dev/sdc1 格式化磁盘
[email protected]:/# mkfs.ext4 /dev/sdc1
mke2fs 1.42.13 (17-May-2015)
/dev/sdc1 contains a ext4 file system
last mounted on Wed Oct 17 07:50:51 2018
Proceed anyway? (y,n) y
Creating filesystem with 131072000 4k blocks and 32768000 inodes
Filesystem UUID: d3b035e7-d5c9-43ec-9f92-a0fadcd2639a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
9、通过df -h 查看磁盘情况
[email protected]:/# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.4G 0 3.4G 0% /dev
tmpfs 697M 73M 625M 11% /run
/dev/sda1 30G 1.4G 28G 5% /
tmpfs 3.5G 0 3.5G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.5G 0 3.5G 0% /sys/fs/cgroup
/dev/sdb1 99G 60M 94G 1% /mnt
tmpfs 697M 0 697M 0% /run/user/1000
10、通过 vim /etc/fstab 添加系统启动加载该盘(/dev/sdc1 /docker ext4 defaults 0 0)
# CLOUD_IMG: This file was created/modified by the Cloud Image build process
UUID=8ae3d910-2d2a-492d-8667-d0fa24e4d357 / ext4 defaults,discard 0 0
/dev/disk/cloud/azure_resource-part1 /mnt auto defaults,nofail,x-systemd.requires=cloud-init.service,comment=cloudconfig 0 2
/dev/sdc1 /docker ext4 defaults 0 0
11、通过mount -a 完成磁盘挂载
12、通过df-h再次查看,发现已成功挂载到docker目录下
[email protected]:/# df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.4G 0 3.4G 0% /dev
tmpfs 697M 73M 625M 11% /run
/dev/sda1 30G 1.4G 28G 5% /
tmpfs 3.5G 0 3.5G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.5G 0 3.5G 0% /sys/fs/cgroup
/dev/sdb1 99G 60M 94G 1% /mnt
tmpfs 697M 0 697M 0% /run/user/1000
/dev/sdc1 493G 70M 467G 1% /docker
注意:
对分区进行格式化,以及加载;
先提示一下;用 mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs 等命令来格式化分区,比如我想格式化 sda6为ext3文件系统,则输入;
[[email protected] beinan]# mkfs.ext3 /dev/sda6
如果我想加载 sda6到目前系统来存取文件,应该有mount 命令,但首先您得建一个挂载目录;比如 /mnt/sda6 ;
[[email protected] beinan]# mkdir /mnt/sda6
[[email protected] beinan]# mount /dev/sda6 /mnt/sda6
[[email protected] beinan]# df -lh
Filesystem 容量 已用 可用 已用% 挂载点