Linux磁盘管理相关操作
磁盘数据查询
- df:查看文件系统的磁盘使用量
df -h
-a, --all include dummy file systems
-B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,
'-BM' prints sizes in units of 1,048,576 bytes;
see SIZE format below
--direct show statistics for a file instead of mount point
--total produce a grand total
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si likewise, but use powers of 1000 not 1024
-i, --inodes list inode information instead of block usage
-k like --block-size=1K
-l, --local limit listing to local file systems
--no-sync do not invoke sync before getting usage info (default)
--output[=FIELD_LIST] use the output format defined by FIELD_LIST,
or print all fields if FIELD_LIST is omitted.
-P, --portability use the POSIX output format
--sync invoke sync before getting usage info
-t, --type=TYPE limit listing to file systems of type TYPE
-T, --print-type print file system type
-x, --exclude-type=TYPE limit listing to file systems not of type TYPE
- fdisk:查看系统分区
fdisk -l
Usage:
fdisk [options] <disk> change partition table
fdisk [options] -l <disk> list partition table(s)
fdisk -s <partition> give partition size(s) in blocks
Options:
-b <size> sector size (512, 1024, 2048 or 4096)
-c[=<mode>] compatible mode: 'dos' or 'nondos' (default)
-h print this help text
-u[=<unit>] display units: 'cylinders' or 'sectors' (default)
-v print program version
-C <number> specify the number of cylinders
-H <number> specify the number of heads
-S <number> specify the number of sectors per track
磁盘操作
新增拓展分区
-
新增拓展磁盘
-
查看磁盘分区状态
fdisk -l
说明:
第一块磁盘叫sda
有两个分区 sda1和sda2
s:接口,例如ssd,scsi,sata d代表disk磁盘 a:第一块 123:第几个分区
- 系统内新增一个分区sda3
fdisk /dev/sda
新增磁盘
-
虚拟机新增硬盘:
-
系统内添加磁盘
fdisk -l
fdisk /dev/sdb
1. 进入命令行交互界面,通过m查看帮助信息
2. 新增分区(n)
3. 新增为主分区(p)
4. 默认为第一个主分区(1)
5. 分区偏移量设置(默认)
6. 保存退出(w)
7.重启系统
8.格式化分区
shell mkfs.ext4 /dev/sdb1
- 磁盘分区挂载
- 创建要挂载的文件目录
mkdir -p /opt/sdb1
- 将分区/dev/sdb1挂载到/opt/sdb1
mount /dev/sdb1 /opt/sdb1
-
查看挂载情况
-
卸载
umount /opt
初心回归,时光已逝!