Disk format, disk mount, manually increase swap space

disk format

  • /etc/filesystems Check which file system formats are supported by the system
[root@yong-02 ~]# cat /etc/filesystems
xfs           //centos7默认文件系统
ext4        //centos6
ext3        //centos5
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus
*

How to view the system file format mount of a partition:

[root@yong-02 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,seclabel,size=926656k,nr_inodes=231664,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,seclabel)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,seclabel,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=12142)
mqueue on /dev/mqueue type mqueue (rw,relatime,seclabel)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,seclabel)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,seclabel,size=187548k,mode=700)

mke2fs command

  • Set the file system format; common options:
  • -t system file type
  • -b block size, the size of the space occupied by each data block, each database supports 1024B, 2048B and 4096B.
  • -m Reserve size 1 is 1%
  • -L indicates the partition label label
  • -i Set the size of the inode, how many blocks correspond to 1 inode, the default is 4 blocks, 16k
  • -N sets the number of inodes
[root@yong-02 ~]# mke2fs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks  ##大概为4个块对应1个inode
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 
[root@yong-02 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="37275f57-b045-4159-97b3-dfa8fd78cd8d" TYPE="ext4" 
查看分区类型为ext4
  • mke2fs -t ext4 /dev/sdb1====mkfs.ext4 /dev/sdb1 same result
  • mke2fs does not support formatting partitions as xfs type, you can only use mkfs.xfs
[root@yong-02 ~]# mkfs.xfs /dev/sdb1
mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).
mkfs.xfs: Use the -f option to force overwrite.

When mkfs.xfs /dev/sdb1 sets the system type to xfs, an error will be reported, and the -f option must be added;

[root@yong-02 ~]# mkfs.xfs -f /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
  • -i Set the inode, set it to 2 blocks corresponding to 1 inode, and the inode will increase
[root@yong-02 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 1310720 blocks  ##大概为2个块对应1个inode
65536 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 
  • mke2fs -b sets the block size. Under what circumstances should the block be set to a large size, it is generally used for large file videos and the like, and the small file block is best set to a smaller size.
[root@yong-02 ~]# mke2fs -b 8192 -t ext4 /dev/sdb1
Warning: blocksize 8192 not usable on most systems.
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: 8192-byte blocks too big for system (max 4096)
无论如何也要继续? (y,n) y
Warning: 8192-byte blocks too big for system (max 4096), forced to continue
warning: 80 blocks unused.

文件系统标签=
OS type: Linux
块大小=8192 (log=3)
分块大小=8192 (log=3)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 655280 blocks
32764 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=671006720
10 block groups
65528 blocks per group, 65528 fragments per group
32768 inodes per group
Superblock backups stored on blocks: 
	65528, 196584, 327640, 458696, 589752

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 
  • mke2fs -m specifies the space reserved for the partition, mkfs.xfs does not support the -m option.
[root@yong-02 ~]# mke2fs -m 0.1 -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
1310 blocks (0.10%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成 

  • Note: The extended partition cannot be formatted, it is a shell, only the logical partition inside can be formatted
  • We can format directly without partitioning.
  • mkfs.xfs -f /dev/sdb

disk mount

  • After the disk is partitioned and formatted, what we need to do is to mount it. Only after mounting can the data be written to the disk. Before mounting the partition, we need to establish a mount point. This mount point appears in the form of a directory. , once a partition is mounted to this directory, when writing data to this directory, it will be written to the partition, so before mounting the partition, the mount point must be an empty directory. In fact, the fact that the directory is not empty does not affect the use of the mounted partition, but once it is mounted, the previous data in the directory will not be visible (the data is not lost). After the partition is unloaded, the data will be restored.

  • A mount point can only serve one partition. Assuming that there are two partitions placed under one mount point, only the second partition can be served. The second one will overwrite the first one, but the second one will be unloaded. A partition of data will appear

mount command

The mount command can view all the partitions that the current system has mounted, the type of the partition file system, the mount point and some option information.

mount

  • mount [partition] [mount point]
[root@yong-02 ~]# mount /dev/sdb1 /mnt
[root@yong-02 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   18G  1.1G   17G    7% /
devtmpfs                 905M     0  905M    0% /dev
tmpfs                    916M     0  916M    0% /dev/shm
tmpfs                    916M  8.6M  908M    1% /run
tmpfs                    916M     0  916M    0% /sys/fs/cgroup
/dev/sda1                197M  121M   77M   62% /boot
tmpfs                    184M     0  184M    0% /run/user/0
/dev/sdb1                4.8G   20M  4.8G    1% /mnt
  • umount unmount
[root@yong-02 ~]# mount /dev/sdb1 /mnt
[root@yong-02 ~]# cd /mnt
[root@yong-02 mnt]# umount /dev/sdb1
umount: /mnt:目标忙。
        (有些情况下通过 lsof(8) 或 fuser(1) 可以
         找到有关使用该设备的进程的有用信息)

At this time, we have to exit this directory and uninstall it

[root@yong-02 mnt]# cd
[root@yong-02 ~]# umount /dev/sdb1

or use the -l option

[root@yong-02 ~]# mount /dev/sdb1 /mnt
[root@yong-02 ~]# cd /mnt
[root@yong-02 mnt]# umount -l /dev/sdb1


The first method: vim /etc/fstab directly writes the relevant mount information directly into the file mount -a will automatically
load all the configurations of the configuration file
mount -o noatime,rw /dev/sdb1 /mnt use -o specifies some options, if not specified, it is defaults
mount to see which related options are loaded

# /etc/fstab
# Created by anaconda on Tue Mar  6 20:09:24 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#第一段                  第二段              第三段         第四段       第5段       第六段
#设备分区名或UUID        挂载点             系统文件类型    挂在选项     是否数据备份  开机是否检测磁盘
#defaults=rw,suid,dev,exec,auto,nouser,asyc
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=28cfd06d-4704-4964-9522-265bca82e8f8 /boot                   xfs     defaults        0 0
UUID=feb65e38-9bc4-45a1-98a3-1f32f3df9705 swap                    swap    defaults        0 0
~                                                                                               
[root@yong-02 ~]# blkid
/dev/sda1: UUID="28cfd06d-4704-4964-9522-265bca82e8f8" TYPE="xfs" 
/dev/sda2: UUID="feb65e38-9bc4-45a1-98a3-1f32f3df9705" TYPE="swap" 
/dev/sda3: UUID="QKR4ER-jzMu-4zPP-NLgf-bjo3-RzrU-GrPErX" TYPE="LVM2_member" 
/dev/sr0: UUID="2017-09-06-10-51-00-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/centos-root: UUID="5d00946e-bea5-48f1-af3e-5bb66d92c443" TYPE="xfs" 
/dev/sdb: UUID="ecae3cbf-e4ae-49fc-8633-98d33947d12b" TYPE="xfs" 
[root@yong-02 ~]# mount UUID="ecae3cbf-e4ae-49fc-8633-98d33947d12b"
mount: 在 /etc/fstab 中找不到 UUID=ecae3cbf-e4ae-49fc-8633-98d33947d12b
##可以把这个UUID写到 /etc/fstab里面去

After writing the configuration file /etc/fstab, mount -a
-a will mount all partitions in /etc/fstab

The second method: vim /etc/rc.local What settings will be loaded at other startups?
You can directly write the mount /dev/sdb1 /mnt/ command to the /etc/rc.local file, and the file will automatically execute the command to mount when the system is restarted .

blkid gets the uuid and table of the partition

Manually increase swap space

If you need insufficient virtual memory, you must add a virtual disk. The basic idea of ​​adding a virtual disk: Create a swapfile-> Format as swap format-> enable the virtual disk

  1. Create swapfile
[root@yong-02 ~]# dd if=/dev/zero of=/tmp/newdisk2 bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,4.21749 秒,24.9 MB/秒 ##写入快慢和磁盘有关系

dd command: operate the disk; if specifies the source (usually writing /dev/zero, which is a file unique to UNIX systems, it can provide "0" continuously) of specifies the target file, bs defines the block size, and count defines the block The two parameters, bs and count, determine the size of the target file, and the size of the target file = bs*count.

  1. format
[root@yong-02 ~]# mkswap -f /tmp/newdisk2
正在设置交换空间版本 1,大小 = 102396 KiB
无标签,UUID=4750e78f-2452-4d4c-961f-d35df56304f0

After the file is formatted, it can be mounted and used

  • free -m to check memory usage
[root@yong-02 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1831         138        1255           8         437        1509
Swap:          2047           0        2047
  1. load
[root@yong-02 ~]# swapon /tmp/newdisk2
swapon: /tmp/newdisk2:不安全的权限 0644,建议使用 0600。
[root@yong-02 ~]# blkid /tmp/newdisk2
/tmp/newdisk2: UUID="4750e78f-2452-4d4c-961f-d35df56304f0" TYPE="swap" 

[root@yong-02 ~]# chmod 0600 /tmp/newdisk2 ##改权限0600

[root@yong-02 ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1831         138        1255           8         437        1509
Swap:          2147           0        2147

Swap has added 100M

uninstall swap    

[root@yong-02 tmp]# swapoff /tmp/newdisk2 
[root@yong-02 tmp]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1831         138        1408           8         284        1511
Swap:          2047           0        2047

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324453063&siteId=291194637