标签:lca 剩余空间 备份 setting point using abc nta source
1 dd命令详解dd:convert and copy a file
dd if=/PATH/SOURCE of=/PATH/DEST bs=1[k|M] count=100
if=file,从文件读入内容。
of=offile,写入文件。
ibs=size 一次读size个byte
obs=size 一次写size个byte
bs=size 指定读写块大小
cbs=size 一次性转化size个大小
skip=blocks 从头忽略blocks个ibs大小的块
seek=blocks 从头忽略bolcks个obs大小的块
////读入硬盘的MBR分区表存档备份,备份要放置在另外一块硬盘。磁盘0磁道0扇区共512bytes,446存放bootloader,64bytes分区信息,最后2bytes存放55aa,已分区标记。
[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 复制n个bs
conv=conversion[参数] lcase
notrunc 不截断输出,替换的意思
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本身
查前支持的文件系统:cat /proc/filesystems
加入新的硬盘或者原硬盘有剩余空间。若新加入硬盘不识别,则用
echo - - - > /sys/class/scsi_host/host0/scan;
echo - - - > /sys/class/scsi_host/host1/scan;
新加硬盘分区并格式化实例:
[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
格式化完毕,通知内核重读分区表
centos6
新增分区 partx -a /dev/sda5 kpartx -a /dev/sda5 -f
删除分区 partx -d --nr M-N /dev/DEVICE
centos7 使用 partprobe [/dev/DEVICE]
创建新的独立swap分区时候要用 t 参数,指定82类型。系统装好后还以用大的空文件,用swap工具格式化成swap格式,用来做swap交换区,这种做法很灵活,不用了,修改fstab挂载信息,nmount,删除大文件即可。
#####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.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
确保swap分区没有使用。删除/etc/fstab文件里swap的挂载信息
[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]
硬盘分区fdisk\gdisk ,挂载mount \swapon
标签:lca 剩余空间 备份 setting point using abc nta source
原文地址:https://blog.51cto.com/14420400/2429098