Linux Disk Command

磁盘-分区-格式化-挂载

df -h 查看磁盘空间

du -h ./ --max-depth=1 查看当前目录下,每个子目录的磁盘空间

fdisk -l 查看硬盘(已格式化和未格式化都能看到)

fdisk /dev/sda,sdb,sdc (格式化或者重写磁盘分区)

分区


Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x22badbc1.
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: The size of this disk is 2.2 TB (2199023255552 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).

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): u
Changing display/entry units to sectors

Command (m for help): d
No partition is defined yet!

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-4294967295, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-4294967294, default 4294967294):
Using default value 4294967294

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

创建文件系统格式

mkfs.ext4 /dev/xvdb1
mkfs.xfs /dev/xvdb1
mkdir /storage

查看文件系统格式

parted /dev/xvdb1
(parted) print list

挂载

mount /dev/xvdb1 /storage
df -h

设置开机启动

ll /dev/disk/by-uuid/
vi /etc/fstab

UUID=0e85f57a-1f21-411d-afab-c5c976bc5659 /nfs_file ext4 defaults 0 0

======swap=====


dd if=/dev/zero of=/swapfile bs=1M count=1024
chown root:root /swapfile
chmod 0600 /swapfile
mkswap -f /swapfile

echo '/swapfile none swap defaults,nofail 0 0' >> /etc/fstab
swapon -a
free -mt

磁盘空间没释放

df -h
du -h ./ --max-depth=1

查看当前占用,发现和磁盘不一致,文件删除了,仍在被占用,磁盘空间没释放

lsof | grep ‘delete’|head -50

LogStash: 1912 1965 root 136r REG 259,0 3490517867 402677903 /data/logs/2019/12/15/app-1b-node2/apache-access.log (deleted)

发现是LogStash进程占用,考虑业务情况是否重启logstash服务

systemctl status logstash

你可能感兴趣的