Hard disk partition fdisk \ gdisk, mount mount \ swapon

1 dd command Detailed

dd: Convert A File Copy and
dd = IF / the PATH / = of the SOURCE / the PATH / DEST. 1 BS = [K | M] = 100 COUNT
IF = File, reading from a file.
of = offile, written to the file.
ibs a read size of size = byte
OBS a write size of size = byte
BS = write block size specified size
cbs = size disposable conversion of size size
skip = blocks de novo block blocks a negligible size ibs
seek = blocks de novo ignored bolcks a block size obs
//// reads the MBR partition table of the hard disk archive backup, the backup to a hard drive in another place. Disk sector 0 track 0 co 512bytes, 446 stored bootloader, 64bytes partition information, stored last 2bytes 55AA, partitioned marks.

[root@localhost ~]#dd if=/dev/sda of=./fstab_sda.back bs=1  count=64 skip=446
64+0 records in
64+0 records out
64 bytes (64 B) copied, 0.000452712 s, 141 kB/s
[root@localhost ~]#hexdump -C fstab_sda.back 
00000000  80 20 21 00 83 aa 28 82  00 08 00 00 00 00 20 00  |. !...(....... .|
00000010  00 aa 29 82 83 fe ff ff  00 08 20 00 00 00 40 01  |..)....... ...@.|
00000020  00 fe ff ff 83 fe ff ff  00 08 60 01 00 00 40 01  |..........`...@.|
00000030  00 fe ff ff 05 fe ff ff  00 08 a0 02 00 f8 9f 03  |................|
00000040
还原时核对硬盘
dd if=/备份的分区表信息 of=/dev/硬盘 bs=1 seek=446

count = n Copies n BS
CONV = Conversion [parameter] LCASE
notrunc are not cut output, the meaning replacement

abcdefgh
12345678
[root@localhost xuan]#dd if=f1 of=f2 bs=1 skip=5 seek=2 conv=notrunc    //不截断
4+0 records in
4+0 records out
4 bytes (4 B) copied, 0.000169599 s, 23.6 kB/s
[root@localhost xuan]#cat -A f2
12fgh$
78$
此处换行来源于f1本身

2 partitions and file format

Check before Supported file systems: cat / proc / filesystems

2.1 gdisk/fdisk

Add a new hard disk or the original hard drive with room to spare. If the newly added hard disk is not recognized by the
echo - - -> / SYS / class / scsi_host / host0 / Scan;
echo - - -> / SYS / class / scsi_host / host1 / Scan;
newly added hard disk partition and format examples:

[root@cenots7 ~]#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  100G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]
├─sda4   8:4    0  512B  0 part             //扩展分区,所以无挂载点
└─sda5   8:5    0   50G  0 part /data       //逻辑分区,编号从**5开始
sdb      8:16   0   20G  0 disk             //新增的硬盘,无挂挂载点,接下来的主角
-------------------------------------------------------------------------------
[root@cenots7 ~]#gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.

Command (? for help): n                                         //n新建分区
Partition number (1-128, default 1): 1                          //默认分区号1
First sector (34-41943006, default = 2048) or {+-}size{KMGTP}:  //其实扇区位置,一般默认。回车即可
Last sector (2048-41943006, default = 41943006) or {+-}size{KMGTP}: +5G         //+5G表示划分5G空间
Command (? for help): p                                           //p打印,核对分区信息
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        10487807   5.0 GiB     8300  Linux filesystem

Command (? for help): w                             //w写盘,真正把分区表信息写入硬盘

Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!

Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
--------------------------------------------------------------------------------------
[root@cenots7 ~]#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  100G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]
├─sda4   8:4    0  512B  0 part 
└─sda5   8:5    0   50G  0 part /data
sdb      8:16   0   20G  0 disk 
└─sdb1   8:17   0    5G  0 part                     ////lsblk查看,确实分区已经有了
sdc      8:32   0    2G  0 disk 

----------------------------------------------------------------------------------------
[root@cenots7 ~]#mkfs.ext4 -L gpt_001 /dev/sdb1         //格式化文件系统 -L给个标记,
----------------------------------------------------------------------------------------
[root@cenots7 ~]#blkid
/dev/sda1: UUID="f3dea6d9-de61-40d2-af58-25fc9e3d9e57" TYPE="xfs" 
/dev/sda2: UUID="0a85448e-2b97-4f3a-afc2-f9288c0bd490" TYPE="xfs" 
/dev/sda3: UUID="f6c52d33-a0ee-4f65-8fe0-360cd1e20317" TYPE="swap" 
/dev/sda5: UUID="2ffec095-ca75-4d76-9303-56bbb23aff73" TYPE="xfs" 
/dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/sdb1: LABEL="gpt_001" UUID="1cbd73f6-0438-4c92-b244-164d3cd6e3f4" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="b7fc8331-eb4c-4d16-b7d4-bc116a26cc9d"
--------------------------------------------------------------------------------------
[root@cenots7 ~]#tune2fs -l /dev/sdb1                   //查看分区块的详细信息
[root@cenots7 ~]#dumpe2fs /dev/sdb1 -h                     //显示超级块信息
[root@cenots7 ~]#tune2fs -m1 /dev/sdb1                      //m1修改默认预留的管理员空间为1%
tune2fs 1.42.9 (28-Dec-2013)
Setting reserved blocks percentage to 1% (13107 blocks)
-------------------------------------------------------
vim /etc/fstab
UUID=1cbd73f6-0438-4c92-b244-164d3cd6e3f4 /gpt001       ext4      acl        0 0 //赋予acl权限
mount -a                                                                       //重读配置文件,挂载
[root@cenots7 ~]#df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/sdb1      ext4      4.8G   20M  4.8G   1% /gpt001
//产看文件系统是否被挂载,若被挂载,再往该目录挂载设备B时候,会挤掉原来的设备A,B卸载后,原来的A还会自动挂载回来。(临时有效)
[root@localhost xuan]#findmnt /home/
TARGET SOURCE    FSTYPE OPTIONS
/home  /dev/sda3 xfs    rw,relatime,attr2,inode64,noquota

Formatting is completed, notify the kernel reread partition table
centos6
new partition partx -a / dev / sda5 kpartx -a / dev / sda5 -f
delete partitions -d --NR the MN partx / dev / the DEVICE
centos7 use partprobe [/ dev / DEVICE ]

2.2 swap partition use

Creating a new independent swap partition time to use a t parameter, specify 82 types. After the system is also installed in order to use large empty file, formatted into a swap with a swap tool format, used for swap swap, this approach is very flexible, no, modify fstab to mount information, nmount, delete large files.

2.2.1 The new hard drive plus a separate partition as a swap use
#####2.2.1.1 分区---------------------------
[root@cenots7 ~]#lsblk                                              //查看块设备是否已经识别新加硬盘
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdc      8:32   0    2G  0 disk 
[root@cenots7 ~]#fdisk /dev/sdc                                     //采用fdisk分区
Command (m for help): n                                             //n 新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                                               //p主分区
Partition number (1-4, default 1): 1                                //分区号
First sector (2048-4194303, default 2048):                          //默认起始扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): //默认终止扇区
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): t                                             //指定分区类型。
Selected partition 1
Hex code (type L to list all codes): 82                             //82为swap分区
Changed type of partition 'Linux' to 'Linux swap / Solaris'

Command (m for help): p                                             //查看分区信息
Disk /dev/sdc: 2147 MB, 2147483648 bytes, 4194304 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: 0x5ea8522e

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4194303     2096128   82  Linux swap / Solaris

Command (m for help): w                                             //分区表写入磁盘
The partition table has been altered!
[root@cenots7 ~]#partprobe                                          //同步分区信息至内核
#####2.2.1.2-格式化为swap-------------------------------
[root@cenots7 ~]#mkswap -L extend_swap /dev/sdc1                    //mkswap -L(标签) 格式化成swap
Setting up swapspace version 1, size = 2096124 KiB
LABEL=extend_swap, UUID=8fa013a8-f906-4094-a933-467872df6763
[root@cenots7 ~]#swapon /dev/sdc1                                   //挂载swap分区
[root@cenots7 ~]#lsblk                                               
sdc      8:32   0    2G  0 disk 
└─sdc1   8:33   0    2G  0 part [SWAP]
[root@cenots7 ~]#free -h                                            //查看内存,已经启用
              total        used        free      shared  buff/cache   available
Mem:           1.9G        752M        200M         42M        1.0G        963M
Swap:          6.0G          0B        6.0G
2.2.2 the establishment of large files, for use when the swap partition
###### 2.2.2.1 建立大文件
[root@cenots7 data]#dd if=/dev/zero of=./bigfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 5.72137 s, 188 MB/s
[root@cenots7 data]#ll -h
total 1.1G
-rw-r--r--   1 root root  1.0G Aug 13 12:57 bigfiel
###### 2.2.2.3 格式化文件系统
[root@cenots7 data]#chmod 0600 bigfile
[root@cenots7 data]#mkswap -L bigfile_swap bigfile 
Setting up swapspace version 1, size = 1048572 KiB
LABEL=bigfile_swap, UUID=c493c55b-6e9d-46bb-9543-38b72f410478
###### 2.2.2.3 挂载swap
[root@cenots7 data]#swapon /data/bigfile
[root@cenots7 data]#free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        753M         76M         42M        1.1G        965M
Swap:          7.0G          0B        7.0G
[root@cenots7 data]#echo "/data/bigfile swap swap defaults 0 0 ">> /etc/fstab 
//写入分区表,可以开机自动挂载。mount -a 对swap或者文件无效。
/data/bigfile swap swap defaults 0 0 

2.2.3 remove the swap partition

Ensure that the swap partition is not used. Delete the / etc / fstab file swap mount information

[root@cenots7 data]#swapoff /data/bigfile
[root@cenots7 data]#swapoff /dev/sdc1
[root@cenots7 data]#free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        749M        115M         42M        1.1G        970M
Swap:          4.0G          0B        4.0G
[root@cenots7 data]#lsblk                           //查看只有一个swap分区了
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  100G  0 part /
├─sda3   8:3    0    4G  0 part [SWAP]

Guess you like

Origin blog.51cto.com/14420400/2429098