首页 > 其他分享 >磁盘管理--学习笔记

磁盘管理--学习笔记

时间:2024-03-19 12:22:23浏览次数:27  
标签:UUID -- dev master 笔记 rc 磁盘 xfs root

磁盘管理--学习笔记

磁盘分区

磁盘分区组成

主分区  只能创建4个  
扩展分区




比如 安排的工作 新买一个硬盘 磁盘 挂载

第一步 买硬盘 插到物理机

第二步 分区 格式化

虚拟机演示 新增一个硬盘

  1. fdisk常用选项

    在 `fdisk` 的交互界面中,提供了很多命令供用户操作:
    
    - `m`:显示帮助菜单,显示上述列出的各项操作命令说明。
    - `n`:创建新的分区。
    - `d`:删除已有的分区。
    - `p`:打印当前的分区表信息。
    - `q`:退出 `fdisk` 不保存更改。
    - `w`:保存并退出,将更改写入磁盘分区表。
    - 其他命令:分别对应不同的功能,例如设置启动标志、更改分区类型、验证分区表等。
    
    如果你想在 `/dev/sdb` 上创建一个新的分区,可以按照以下步骤进行:
    
    1. 输入 `n` 创建新分区。
    2. 选择分区类型(主分区 `p` 或扩展分区 `e`)并回车。
    3. 设置分区编号(默认会选择未分配的最小编号)并回车。
    4. 设置分区开始扇区(可以直接回车使用默认值,或者自定义)。
    5. 设置分区结束扇区(同样可以选择默认值或自定义)。
    6. 输入 `w` 保存并退出,完成分区创建。
    
[root@master ~]# fdisk -l

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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
Disk label type: dos
Disk identifier: 0x0008aa2b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   197410815    97655808   83  Linux
/dev/sda3       197410816   295065599    48827392   83  Linux
/dev/sda4       295065600   419430399    62182400    5  Extended
/dev/sda5       295067648   303456255     4194304   82  Linux swap / Solaris

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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

[root@master ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x064ecb51.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   删除分区
   
   g   create a new empty GPT partition table
   大于2T 磁盘分区方法
   
   G   create an IRIX (SGI) partition table
   l   list known partition types
   列出磁盘分区类型
   
   m   print this menu
   菜单
   
   n   add a new partition
   新增分区
   
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   不保存退出
   
   s   create a new empty Sun disklabel
   t   change a partition's system id
   磁盘扩容  改变磁盘类型
   
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   保存退出
   
   x   extra functionality (experts only)

Command (m for help): 



n

p


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +5G
Partition 1 of type Linux and of size 5 GiB is set

w   保存即可




磁盘格式化

mkfs.xfs /dev/sdb1

或者
mkfs -t xfs /dev/sdb1




文件系统 :存储的数据方式


xfs   





centos6 系统常用格式
ext3
ext4







挂载

如果没有/mnt01目录 可以创建
mkdir /mnt01 

mount /dev/sdb1 /mnt01



刷新加载磁盘分区
partprobe
partprobe /dev/sdb





挂载第二个分区方法

fdisk /dev/sdb

n
p

w



开机自动挂载
vi /etc/rc.local

mount /dev/sdb1 /mnt01
mount /dev/sdb2 /mnt02


如果开机不能自动挂载 要检查 配置文件权限
 
chmod +x 
chmod +777
要给原文件权限 




第二种方法自动挂载

vi /etc/fstab


UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0
UUID=04cb4c4e-727f-43e6-bd0a-0063bf3268a4 /boot                   xfs     defaults        0 0
UUID=df895761-902b-4692-81f7-d76e08aa18c3 /data                   xfs     defaults        0 0
UUID=e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd swap                    swap    defaults        0 0
磁盘文件                                      挂载目录              文件系统类型  是否备份      是否检查                                  







UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0

UID=12981d89-222f-4ee2-b1c7-5dc7560cd13c 是根分区 / 对应的唯一标识符,表示系统根目录所在分区

/   挂载点
xfs 文件系统类型
defaults  挂载选项  --表示使用默认的挂载选项
0  dump选项 --0 表示不使用 dump 工具备份这个分区
0  fsck选项 --0 表示在系统启动时按照优先级顺序检查文件系统,0 表示较低的优先级,通常 / 会被设置为 1,表示在启动时最先进行检查


如何知道用uuid  
可以用blkid

[root@master ~]# blkid
/dev/sdb1: UUID="2c707329-23fe-4bb1-a359-9551fb802051" TYPE="xfs" 
/dev/sdb2: UUID="42acc4f4-053b-4d74-985a-a15808d2b921" TYPE="xfs" 
/dev/sda1: UUID="04cb4c4e-727f-43e6-bd0a-0063bf3268a4" TYPE="xfs" 
/dev/sda2: UUID="12981d89-222f-4ee2-b1c7-5dc7560cd13c" TYPE="xfs" 
/dev/sda3: UUID="df895761-902b-4692-81f7-d76e08aa18c3" TYPE="xfs" 
/dev/sda5: UUID="e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd" TYPE="swap" 
/dev/sr0: UUID="2015-03-31-23-15-10-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 



一般情况下我们不用uuid来进行配置,都是直接指定目录


/dev/sdb1                        /mnt01           xfs          default     0 0
/dev/sdb2                        /mnt02           xfs           default     0 0













如何删除分区

fdisk /dev/sdc

d

1

w












[root@master ~]# fdisk /dev/sdc

WARNING: The size of this disk is 2.3 TB (2254857830400 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).

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): d   
Selected partition 1
Partition 1 is deleted

Command (m for help): 1
1: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@master ~]# fdisk -l

Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 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
Disk label type: dos
Disk identifier: 0x4077e66d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
/dev/sdb2        10487808    18876415     4194304   83  Linux
/dev/sdb3        18876416    20971519     1047552   83  Linux

Disk /dev/sdc: 2254.9 GB, 2254857830400 bytes, 4404019200 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
Disk label type: dos
Disk identifier: 0x651b59ca

   Device Boot      Start         End      Blocks   Id  System

Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 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
Disk label type: dos
Disk identifier: 0x0008aa2b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   197410815    97655808   83  Linux
/dev/sda3       197410816   295065599    48827392   83  Linux
/dev/sda4       295065600   419430399    62182400    5  Extended
/dev/sda5       295067648   303456255     4194304   82  Linux swap / Solaris

实战

如果工作中业务量已经大于2t了?fdisk不够用了?怎么办?
[root@master ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        94G  1.7G   92G   2% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           490M     0  490M   0% /dev/shm
tmpfs           490M  6.8M  484M   2% /run
tmpfs           490M     0  490M   0% /sys/fs/cgroup
/dev/sda3        47G   33M   47G   1% /data
/dev/sda1      1014M  124M  891M  13% /boot
tmpfs            98M     0   98M   0% /run/user/0
/dev/sdc1       2.0T   33M  2.0T   1% /mnt03


可以看到 我新加了一个2.1t的硬盘  用fdisk 分区 最后只显示2t 



fdisk 支持 小于 2t
parted 命令分区 支持 大于2t
parted方法步骤

修改磁盘分区的类型  

原mbr改为gpt类型

mklabel gpt



增加主分区为2100g-2.1t

mkpart paimary 0 2100G


print     打印信息  查看一下



加载一下分区
partprobe /dev/sdc



格式化
mkfs.xfs /dev/sdc1



挂载
mount /dev/sdc1 /mnt04








开机自动挂载  永久挂载




开机自动挂载
vi /etc/rc.local

mount /dev/sdb1 /mnt01
mount /dev/sdb2 /mnt02


如果开机不能自动挂载 要检查 配置文件权限
 
chmod +x 
chmod +777
要给原文件权限 







第二种方法自动挂载

vi /etc/fstab


UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0
UUID=04cb4c4e-727f-43e6-bd0a-0063bf3268a4 /boot                   xfs     defaults        0 0
UUID=df895761-902b-4692-81f7-d76e08aa18c3 /data                   xfs     defaults        0 0
UUID=e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd swap                    swap    defaults        0 0
磁盘文件                                      挂载目录              文件系统类型  是否备份      是否检查                                  







UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0

UID=12981d89-222f-4ee2-b1c7-5dc7560cd13c 是根分区 / 对应的唯一标识符,表示系统根目录所在分区

/   挂载点
xfs 文件系统类型
defaults  挂载选项  --表示使用默认的挂载选项
0  dump选项 --0 表示不使用 dump 工具备份这个分区
0  fsck选项 --0 表示在系统启动时按照优先级顺序检查文件系统,0 表示较低的优先级,通常 / 会被设置为 1,表示在启动时最先进行检查


如何知道用uuid  
可以用blkid

[root@master ~]# blkid
/dev/sdb1: UUID="2c707329-23fe-4bb1-a359-9551fb802051" TYPE="xfs" 
/dev/sdb2: UUID="42acc4f4-053b-4d74-985a-a15808d2b921" TYPE="xfs" 
/dev/sda1: UUID="04cb4c4e-727f-43e6-bd0a-0063bf3268a4" TYPE="xfs" 
/dev/sda2: UUID="12981d89-222f-4ee2-b1c7-5dc7560cd13c" TYPE="xfs" 
/dev/sda3: UUID="df895761-902b-4692-81f7-d76e08aa18c3" TYPE="xfs" 
/dev/sda5: UUID="e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd" TYPE="swap" 
/dev/sr0: UUID="2015-03-31-23-15-10-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 



一般情况下我们不用uuid来进行配置,都是直接指定目录


/dev/sdb1                        /mnt01           xfs          default     0 0
/dev/sdb2                        /mnt02           xfs           default     0 0















实现永久挂载
开机自动挂载
vi /etc/rc.local

mount /dev/sdb1 /mnt01
mount /dev/sdb2 /mnt02


如果开机不能自动挂载 要检查 配置文件权限
 
chmod +x 
chmod +777
要给原文件权限 




第二种方法自动挂载

vi /etc/fstab


UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0
UUID=04cb4c4e-727f-43e6-bd0a-0063bf3268a4 /boot                   xfs     defaults        0 0
UUID=df895761-902b-4692-81f7-d76e08aa18c3 /data                   xfs     defaults        0 0
UUID=e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd swap                    swap    defaults        0 0
磁盘文件                                      挂载目录              文件系统类型  是否备份      是否检查                                  







UUID=12981d89-222f-4ee2-b1c7-5dc7560cd13c /                       xfs     defaults        0 0

UID=12981d89-222f-4ee2-b1c7-5dc7560cd13c 是根分区 / 对应的唯一标识符,表示系统根目录所在分区

/   挂载点
xfs 文件系统类型
defaults  挂载选项  --表示使用默认的挂载选项
0  dump选项 --0 表示不使用 dump 工具备份这个分区
0  fsck选项 --0 表示在系统启动时按照优先级顺序检查文件系统,0 表示较低的优先级,通常 / 会被设置为 1,表示在启动时最先进行检查


如何知道用uuid  
可以用blkid

[root@master ~]# blkid
/dev/sdb1: UUID="2c707329-23fe-4bb1-a359-9551fb802051" TYPE="xfs" 
/dev/sdb2: UUID="42acc4f4-053b-4d74-985a-a15808d2b921" TYPE="xfs" 
/dev/sda1: UUID="04cb4c4e-727f-43e6-bd0a-0063bf3268a4" TYPE="xfs" 
/dev/sda2: UUID="12981d89-222f-4ee2-b1c7-5dc7560cd13c" TYPE="xfs" 
/dev/sda3: UUID="df895761-902b-4692-81f7-d76e08aa18c3" TYPE="xfs" 
/dev/sda5: UUID="e2b4e0b4-f016-4cd0-a697-5b0eadbe11fd" TYPE="swap" 
/dev/sr0: UUID="2015-03-31-23-15-10-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 



一般情况下我们不用uuid来进行配置,都是直接指定目录


/dev/sdb1                        /mnt01           xfs          default     0 0
/dev/sdb2                        /mnt02           xfs           default     0 0



问题

配置了自动挂载为什么开机还是没有挂载 ?

1.查看配置文件是否出错
2.查看配置文件是否有执行权限







此问题的解决: rc.local 是个软连接 这个时候去真实的目录下查看 发现这个文件本身没有执行权限,基于执行权限  


反思:一般配置文件或者脚本时  后面都要对应看文件是否有执行权限  一般都是基于执行权限 



[root@master ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Mar  1 01:42 /etc/rc.local -> rc.d/rc.local


[root@master rc.d]# ll
-rw-r--r--. 1 root root 519 Mar 16 00:51 rc.local


[root@master rc.d]# chmod +x rc.local

[root@master rc.d]# ll

-rwxr-xr-x. 1 root root 519 Mar 16 00:51 rc.local


[root@master ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 93.1G  0 part /
├─sda3   8:3    0 46.6G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0   10G  0 disk 
├─sdb1   8:17   0    5G  0 part 
├─sdb2   8:18   0    4G  0 part 
└─sdb3   8:19   0 1023M  0 part 
sr0     11:0    1  636M  0 rom  
[root@master ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 Mar  1 01:42 /etc/rc.local -> rc.d/rc.local
[root@master ~]# cd /etc/
[root@master etc]# ls
1.sh                     exports                   mime.types         rpm
adjtime                  favicon.png               mke2fs.conf        rsyslog.conf
aliases                  filesystems               modprobe.d         rsyslog.d
aliases.db               firewalld                 modules-load.d     rwtab
alternatives             fstab                     motd               rwtab.d
anacrontab               gcrypt                    motdy              sasl2
asound.conf              gnupg                     mtab               securetty
audisp                   GREP_COLORS               my.cnf             security
audit                    groff                     my.cnf.d           selinux
autofs.conf              group                     nanorc             services
autofs_ldap_auth.conf    group-                    netconfig          sestatus.conf
auto.master              grub2.cfg                 NetworkManager     shadow
auto.master.d            grub.d                    networks           shadow-
auto.misc                gshadow                   nsswitch.conf      shells
auto.net                 gshadow-                  nsswitch.conf.bak  skel
auto.smb                 gss                       openldap           ssh
avahi                    host.conf                 opt                ssl
bash_completion.d        hostname                  os-release         statetab
bashrc                   hosts                     pam.d              statetab.d
binfmt.d                 hosts.allow               passwd             sudo.conf
centos-release           hosts.deny                passwd-            sudoers
centos-release-upstream  httpd                     pkcs11             sudoers.d
chkconfig.d              init.d                    pki                sudo-ldap.conf
cron.d                   inittab                   plymouth           sysconfig
cron.daily               inputrc                   pm                 sysctl.conf
cron.deny                iproute2                  polkit-1           sysctl.d
cron.hourly              issue                     popt.d             systemd
cron.monthly             issue.net                 postfix            system-release
crontab                  kdump.conf                ppp                system-release-cpe
cron.weekly              kernel                    prelink.conf.d     tcsd.conf
crypttab                 krb5.conf                 printcap           terminfo
csh.cshrc                ld.so.cache               profile            tmpfiles.d
csh.login                ld.so.conf                profile.d          tuned
dbus-1                   ld.so.conf.d              protocols          udev
default                  libaudit.conf             rc0.d              vconsole.conf
depmod.d                 libnl                     rc1.d              vimrc
dhcp                     libuser.conf              rc2.d              virc
DIR_COLORS               locale.conf               rc3.d              wgetrc
DIR_COLORS.256color      localtime                 rc4.d              wpa_supplicant
DIR_COLORS.lightbgcolor  login.defs                rc5.d              X11
dnsmasq.conf             logrotate.conf            rc6.d              xdg
dnsmasq.d                logrotate.d               rc.d               xinetd.d
dracut.conf              machine-id                rc.local           yum
dracut.conf.d            magic                     rdma               yum.conf
e2fsck.conf              mailcap                   redhat-release     yum.repos.d
environment              makedumpfile.conf.sample  resolv.conf
ethertypes               man_db.conf               rpc
[root@master etc]# cd rc.local
-bash: cd: rc.local: Not a directory
[root@master etc]# cd /rc.local
-bash: cd: /rc.local: No such file or directory
[root@master etc]# cd /rc.d
-bash: cd: /rc.d: No such file or directory
[root@master etc]# cd /rc.d
-bash: cd: /rc.d: No such file or directory
[root@master etc]# cd rc.
rc.d/     rc.local  
[root@master etc]# cd rc.d/
[root@master rc.d]# ls
init.d  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rc.local
[root@master rc.d]# ll
total 4
drwxr-xr-x. 2 root root  66 Mar  1 01:43 init.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc0.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc1.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc2.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc3.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc4.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc5.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc6.d
-rw-r--r--. 1 root root 519 Mar 16 00:51 rc.local
[root@master rc.d]# chmod +x rc.local
[root@master rc.d]# ll
total 4
drwxr-xr-x. 2 root root  66 Mar  1 01:43 init.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc0.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc1.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc2.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc3.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc4.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc5.d
drwxr-xr-x. 2 root root  43 Mar  1 01:43 rc6.d
-rwxr-xr-x. 1 root root 519 Mar 16 00:51 rc.local
[root@master rc.d]# reboot




[root@master ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk 
├─sda1   8:1    0    1G  0 part /boot
├─sda2   8:2    0 93.1G  0 part /
├─sda3   8:3    0 46.6G  0 part /data
├─sda4   8:4    0    1K  0 part 
└─sda5   8:5    0    4G  0 part [SWAP]
sdb      8:16   0   10G  0 disk 
├─sdb1   8:17   0    5G  0 part /mnt01
├─sdb2   8:18   0    4G  0 part /mnt02
└─sdb3   8:19   0 1023M  0 part 
sr0     11:0    1  636M  0 rom 


故障案例

模拟磁盘故障案例
模拟磁盘满了
dd if=/dev/zero of=/mnt01/500M bs=100M count=50






命令解释

dd: 是一个用于转换和复制文件的实用程序,常用于低级别硬盘操作,如创建、转换和复制文件。

if=/dev/zero: 指定输入文件(input file)为 /dev/zero,这是一个特殊的设备文件,提供无限的零(NULL)字节流。

of=/mnt01/500M: 指定输出文件(output file)的路径和文件名,这里是 /mnt01/500M,即将创建一个名为“500M”的文件位于 /mnt01 目录下。

bs=100M: 指定每次读写的块大小(block size)为100MB。

count=50: 指定读写操作的次数为50次。

从 /dev/zero 设备读取50次,每次读取100MB的零字节数据,并将这些数据写入到 /mnt01/500M 文件中,总计写入50*100MB=5000MB,也就是5GB的数据,因此最终创建的文件大小将是大约5GB





1.磁盘满了?

[root@master ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        94G  1.7G   92G   2% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           490M     0  490M   0% /dev/shm
tmpfs           490M  6.8M  484M   2% /run
tmpfs           490M     0  490M   0% /sys/fs/cgroup
/dev/sda3        47G   33M   47G   1% /data
/dev/sda1      1014M  124M  891M  13% /boot
/dev/sdb1       5.0G  5.0G   20K 100% /mnt01




/dev/sdb1       5.0G  5.0G   20K 100% /mnt01   显示已用了100%了








如何解决?


du -sh /*   列出根目录的文件目录大小
find . -type f -size +100M  当前目录大于100m的文件
find / -type f  -size +100M  根目录大于100m的文件




找到这个文件把他删掉









[root@master mnt01]# du -sh /*
8.0K	/backup
0	/bin
91M	/boot
4.0K	/data
0	/dev
21M	/etc
1.3M	/home
0	/lib
0	/lib64
0	/media
0	/misc
0	/mnt
5.0G	/mnt01
0	/mnt02
0	/mnt03
0	/mnt04
0	/net
0	/opt
du: cannot access ‘/proc/2211/task/2211/fd/4’: No such file or directory
du: cannot access ‘/proc/2211/task/2211/fdinfo/4’: No such file or directory
du: cannot access ‘/proc/2211/fd/4’: No such file or directory
du: cannot access ‘/proc/2211/fdinfo/4’: No such file or directory
0	/proc
100K	/root
6.8M	/run
0	/sbin
0	/srv
0	/sys
4.0K	/test
388K	/tmp
806M	/usr
816M	/var


[root@master mnt01]# find . -type f -size +100M
./500M


[root@master mnt01]# find / -type f -size +100M
/proc/kcore
find: ‘/proc/2317/task/2317/fdinfo/6’: No such file or directory
find: ‘/proc/2317/fdinfo/6’: No such file or directory
/sys/devices/pci0000:00/0000:00:0f.0/resource1_wc
/sys/devices/pci0000:00/0000:00:0f.0/resource1
/var/cache/yum/x86_64/7/updates/gen/primary_db.sqlite
/var/cache/yum/x86_64/7/updates/gen/filelists_db.sqlite
/usr/lib/locale/locale-archive
/mnt01/500M



找到这个文件把他删掉



2.使用df -h 磁盘还有空间 但是无法新建文件?

故障现象

[root@master ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2        94G  2.0G   92G   3% /
devtmpfs        481M     0  481M   0% /dev
tmpfs           490M     0  490M   0% /dev/shm
tmpfs           490M  6.8M  484M   2% /run
tmpfs           490M     0  490M   0% /sys/fs/cgroup
/dev/sda3        47G   33M   47G   1% /data
/dev/sda1      1014M  124M  891M  13% /boot
/dev/sdb1       5.0G  369M  4.7G   8% /mnt01
/dev/sdb2       4.0G   33M  4.0G   1% /mnt02
/dev/sdd1      1020M  344M  677M  34% /mnt05






/dev/sdd1      1020M  344M  677M  34% /mnt05


[root@master mnt05]# touch nwq21.txt
touch: cannot touch ‘nwq21.txt’: No space left on device





可以看到这个分区还有600m的空间未使用呢  但是无法新建文件了

解决

inode  节点编号满了  大量的小文件造成的

使用df -i     肯定占用100% 

肯定有大量的小文件吧inode号占满了  找到它删除就可以了








删除
 find /mnt05 -type f -name "*.txt" -d

 find /mnt05 -type f -name 'w*' -print0 | xargs -0 rm -f
find /mnt05 -type f -name '*.txt' |rm -f


标签:UUID,--,dev,master,笔记,rc,磁盘,xfs,root
From: https://www.cnblogs.com/nwq1101/p/18082508

相关文章

  • HTML表单标签详解:如何用HTML标签打造互动网页?
    在互联网的世界中,表单是用户与网站进行互动的重要桥梁。无论是注册新账号、提交反馈、还是在线购物,表单都扮演着至关重要的角色。在网页中,我们需要跟用户进行交互,收集用户资料,此时就需要用到表单标签。HTML提供了一系列的表单标签,使得开发者能够轻松地创建出功能丰富的表单。今天......
  • Ubuntu 22.04中挂载硬盘
    背景Ubuntu22.04安装在固态硬盘,现在又添加了一块机械硬盘。添加的机械硬盘的文件系统已经是ext4了步骤1、用fdisk查看设备信息就是为了得到机械硬盘的路径,如下:/dev/sda即是root@cap-server:~#fdisk-lDisk/dev/loop0:63.28MiB,66355200bytes,129600sectorsUnits:......
  • 使用甘特图实现高效时间规划
    甘特图虽然看似简单,却蕴含着规划时间的奥秘。它将复杂的工序分解成逻辑严密的任务链条,每个短小的条形图块都清晰地道出一个任务的起始、持续和终止。就像指挥家挥舞手中的棒,每个动作都精确拍着节奏,确保各个乐手分工合作、行云流水。 制作精良的甘特图需要深入理解项目的血......
  • c# vs注册表可以看到有项,但是只能获取其中一个,另外一个获取不到
    自己的程序写入到注册表后,获取不到值,重启后也不行,但是获取同目录下360Safe项就可以获取到。 写注册表的程序的目标平台(x86/x64的那个)和当前这个获取注册表信息的程序目标平台不一致导致。改用RegistryKey.OpenBaseKey方法获取LocalMachine。如下:RegistryKeyadvanced=null;......
  • XReport通过数据控制控件是否打印
    需求场景:医嘱单在患者出院的时候,需要标记一条红线,表示以下没有医嘱了。数据库中此记录的一个字段属性isRed值来标记这一行。 实现:XReport报表的明细区域增加一个line1对象。然后在明细表格带区添加如下事件代码,就可以实现这条线的可见打印输出通过数据集的属性控制了。priva......
  • linux hadoop106 history 1000
    ls2bin/flinkrun./examples/batch/WordCount.jar-Dexecution.runtime-mode=BATCH--input/opt/module/word.txt--output/opt/module/result.txt3bin/flinkrun./examples/batch/WordCount.jar-Dexecution.runtime-mode=BATCH-yDfs.overwrite-files=......
  • 资源加载和序列化
    一切加载最后都要跑到LoadPackageInternal:创建Linker序列化(LoadAllObjects){ FUObjectSerializeContext*InOutLoadContext=LoadContext; Linker=GetPackageLinker(InOuter,PackagePath,LoadFlags,nullptr,InReaderOverride,&InOutLoadContext,ImportLinker,In......
  • [极客大挑战 2019]web部分题解(sql部分已完结,其他部分正在更新)
    SQL部分:[极客大挑战2019]BabySQL打开环境后有登录界面◕‿◕一眼注入,后先试试万能密码:username:admin'or'1'='1password:1 GG,出大问题,我就会这一招啊O.o??完结撒花(不是꒰ঌ(⌯''⌯)໒꒱开玩笑的,着看着像是过滤了or后来尝试了一下oorr双写发现也不行,那咱继续注入哈:尝试......
  • UI自动化关键字驱动的简单设计思路
    步骤一:定义关键字首先,我们定义一些与登录功能相关的关键字,如:打开页面:用于打开指定的Web页面。输入文本:用于在输入框中输入文本。点击按钮:用于模拟点击按钮的动作。验证文本:用于验证页面上是否显示指定的文本。步骤二:设计测试用例接下来,我们设计一个登录功能的测试用例。这......
  • 数据结构(七)并查集---以题为例
    一共有 n 个数,编号是 1∼n,最开始每个数各自在一个集合中。现在要进行 m 个操作,操作共有两种:Mab,将编号为 a 和 b 的两个数所在的集合合并,如果两个数已经在同一个集合中,则忽略这个操作;Qab,询问编号为 a 和 b 的两个数是否在同一个集合中;输入格式第一行输入整......