Linux command - fdisk disk partition

fdisk (only disks under 2TB can be partitioned)
Disk partitioning steps:
prepare disk --> partition --> format --> mount

分配1个分区
[root@www ~]# fdisk /dev/sdb 
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):         
First sector (2048-41943039, default 2048):     #开始的扇区 回车即可
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +1G    #当前分区的大小
Partition 1 of type Linux and of size 1 GiB is set

Command (m for help): p     #查看当前磁盘的分区情况

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x44d0ef75

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2099199     1048576   83  Linux

4.挂载
[root@www /]# mount /dev/sdb1 /soft/        #将/soft作为/dev/sdb1分区的一个入口目录
[root@www /]# touch /soft/1111              #添加111文件,实际上是在/dev/sdb1分区上添加的数据
[root@www /]# ls /soft/
1111
[root@www /]# umount /soft/                 #卸载/soft挂载信息

------------------------------------永久操作 /etc/fstab-----------------------------------------

format

/etc/fstab configuration file format
The mount point (entry) of the device to be mounted Is the file system type mount parameter backed up? Check
/dev/sdb1 /db1 xfs defaults 0 0

演示临时挂在时参数的使用,只读文件系统

[root@www ~]# mount -o ro /dev/sdc1 /datac/


It is recommended to use UUID when hanging

1. How to use UUID of disk partition
[root@www ~]# blkid|grep sdc1
/dev/sdc1: UUID="c7c940b3-277b-49fa-960b-eef5ed6e9b1b"

2. Manually test whether it can be mounted normally
[root@www ~]# mount UUID="c7c940b3-277b-49fa-960b-eef5ed6e9b1b" /datac

3. Write the information into the /etc/fstab file to ensure that the system will automatically mount
UUID="c7c940b3-277b-49fa-960b-eef5ed6e9b1b" /datac xfs defaults 0 0

4. Unmount the /datac mount information, and then use mount -a to check whether the /etc/fstab file is ok
[root@www ~]# mount -a

PS: If you restart without checking and writing errors, the system will not start. Unable to start-->prompt-->enter password-->modify configuration-->save-->restart

---------------------------- Extend swap partition ------------------- -----------------------------------
1. Create a partition and format it as a swap partition.
[root@www ~]# fdisk /dev/sdb # is divided into 1 G size
[root@www ~]# mkswap /dev/sdb1 #formatted as swap

2. Check the current swap partition size, and then expand and shrink
[root@www ~]# free -m
total used free shared buff/cache available
Mem: 1980 1475 80 10 424 242
Swap: 2047 4 2043

#1. Expand the swap partition size
[root@www ~]# swapon /dev/sdb2
[root@www ~]# free -m
total used free shared buff/cache available
Mem: 1980 1475 80 10 424 242
Swap: 3047 4 2043

#2. Reduce the size of the swap partition
[root@www ~]# swapoff /dev/sdb1
[root@www ~]# free -m
total used free shared buff/cache available
Mem: 1980 1475 80 10 424 242
Swap: 2047 4 2043
[root@www ~]# swapoff -a # means to close all swap

3. Check which devices are in the current swap partition
[root@www ~]# swapon -s
file name type size used permission
/dev/dm-1 partition 2097148 4616 -2
/dev/sdb1 partition 1048572 0 -2

---------------Use file to extend swap partition---------------------
dd if=/dev/zero of =/opt/swap_file bo=1M count=500
chmod 0600 /opt/swap_file
mkswap -f /opt/swap_file
swapon /opt/swap_file

If you want to automatically mount at boot, you need to write to /etc/fstab

Guess you like

Origin blog.51cto.com/paitoubing/2544458