一、磁盘挂载回忆小结
1、挂载磁盘可用的方法
1)设备名进行挂载 2)卷标挂载 3)UUID挂载(此方法常用,UUID为随机生成,唯一性确保挂载成功)
2、文件挂载配置文件详解
/etc/fstab每行代表的意义,如下:
1)挂载的设备或伪文件系统 2)挂载点 3)文件系统类型 4)挂载选项 5)转储频率 6)自检次序
演示:
tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 UUID="39208cf4-4d84-430b-ab53-7a26ad9d786d" /mnt/lv0 ext4 defaults 0 0 UUID=240533cf-b37f-4460-974f-702bab867da5 / ext4 defaults 1 1
二、挂载交换分区
swapon命令:
swapon, swapoff - enable/disable devices and files for paging and swapping
启用:swapon swapon [OPTOIONS] [DEVICE]
禁用:swapoff [OPTOINS] [DEVICE]
选项:
-a:激活所有的交换分区
-p:priority,设置优先级
-s:查看swapon分区
使用mkswap写入特殊签名
swap优先级:
用户可以给某个swap指定一个0到32767的优先级,如果用户没有指定,那么核心会自动给swap指定一个优 先级,这个优先级从-1开始,每加入一个新的没有用户 指定优先级的swap,会给这个优先级减一。
演示:
[root@centos6 ~]# fdisk /dev/sdb WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (command ‘u‘). Command (m for help): p Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x9d14d54e Device Boot Start End Blocks Id System Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-15665, default 1): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-15665, default 15665): +2G Command (m for help): p Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x9d14d54e Device Boot Start End Blocks Id System /dev/sdb1 1 262 2104483+ 83 Linux Command (m for help): t Selected partition 1 Hex code (type L to list codes): 82 Changed system type of partition 1 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sdb: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x9d14d54e Device Boot Start End Blocks Id System /dev/sdb1 1 262 2104483+ 82 Linux swap / Solaris Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@centos6 ~]# mkswap /dev/sdb1 Setting up swapspace version 1, size = 2104476 KiB no label, UUID=443bb126-8dc0-45a3-acfe-9a37629bb511 [root@centos6 ~]# vi /etc/fstab [root@centos6 ~]# blkid /dev/sdb1 /dev/sdb1: UUID="443bb126-8dc0-45a3-acfe-9a37629bb511" TYPE="swap" [root@centos6 ~]# tail -1 /etc/fstab UUID=443bb126-8dc0-45a3-acfe-9a37629bb511 swap swap defaults 0 0 [root@centos6 ~]# mount -a [root@centos6 ~]# swapon -s FilenameTypeSizeUsedPriority /dev/sda5 partition41943000-1 [root@centos6 ~]# swpapon -a -bash: swpapon: command not found [root@centos6 ~]# swapon -a [root@centos6 ~]# swapon -s FilenameTypeSizeUsedPriority /dev/sda5 partition41943000-1 /dev/sdb1 partition21044760-2 [root@centos6 ~]# cat /etc/fstab |grep "/dev/sdb1" /dev/sdb1 swap swap defaults,pri=100 0 0 [root@centos6 ~]# swapon -a [root@centos6 ~]# swapon -s FilenameTypeSizeUsedPriority /dev/sda5 partition41943000-1 /dev/sdb1 partition21044760-2 [root@centos6 ~]# swapoff /dev/sdb1 [root@centos6 ~]# swapon -p 100 /dev/sdb1 [root@centos6 ~]# swapon -a [root@centos6 ~]# swapon -s FilenameTypeSizeUsedPriority /dev/sda5 partition41943000-1 /dev/sdb1 partition21044760100 [root@centos6 ~]# free -m total used free shared buffers cached Mem: 980 455 525 0 30 273 -/+ buffers/cache: 151 829 Swap: 6151 0 6151 [root@centos6 ~]# touch /swapfile [root@centos6 ~]# mkswap /swapfile mkswap: error: swap area needs to be at least 40 KiB Usage: mkswap [-c] [-pPAGESZ] [-L label] [-U UUID] /dev/name [blocks] [root@centos6 ~]# dd if=/dev/sda1 of=/swapfile bs=1M count=2 记录了2+0 的读入 记录了2+0 的写出 2097152字节(2.1 MB)已复制,0.0225383 秒,93.0 MB/秒 [root@centos6 ~]# [root@centos6 ~]# mkswap /swapfile mkswap: /swapfile: warning: don‘t erase bootbits sectors on whole disk. Use -f to force. Setting up swapspace version 1, size = 2044 KiB no label, UUID=c865d3b4-0edb-4d31-9a1a-985e74f1c2a5 [root@centos6 ~]# swapon -a [root@centos6 ~]# swapon -s Filename Type Size Used Priority /dev/sda5 partition 4194300 0 -1 /dev/sdb1 partition 2104476 0 100 /swapfile file 2044 0 100 [root@centos6 ~]#
三、dd工具
dd命令:
dd - convert and copy a file
用法:dd=if=/path/from/src of=/path/to/desti
bs=block size count=#
示例:
磁盘拷贝:
dd if=/dev/sdb of=/dev/sdc
备份MBR:
dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
破坏MBR中的扇区:
dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446
实战练习:
有一个大于2K的二进制文件fileA。现在想从第64个字节位置 开始读取,需要读取的大小是128Byts。又有fileB, 想把上 面读取到的128Bytes写到第32个字节开始的位置,替换 128Bytes,请问如何实现?
答案:dd if=fielA of=fileB bs=1 count=128 skip=63 seek=31 conv=notrunc
备份:
dd if=/dev/sdz of=/dev/sdy #将本地的/dev/sdz备份到/dev/sdy
dd if=/dev/sdx of=/path/to/image #将本地的sdx备份到相应的文件
dd if=/dev/sda|gzip >/path/to/images.gz #备份并压缩
恢复:
dd if=/path/to/images.gz of=/dev/sdz #将备份文件恢复到指定盘
gzip -dc /path/to/image.gz | dd of=/dev/sdx #将压缩的备份文件恢复到指定盘
四、磁盘修复小技巧
注意:/etc/fstab 设备名出错,自检非0,开机会导致无法启动,修复方法如下:小编就不一一演示,想要成功的掌握知识点,就得多动手。。
方法一:
1)关机重启输入密码
2)输入如下命令,并修改/etc/fstab文件,重启即可。
mount -o remount,rw /
方法二:
进入救援模式,重新修改/etc/fstab配置文件
本文出自小耳朵,如有错误希望大家指出,也可以点赞哦,哈哈,记得给管理员留言哦:)
本文出自 “小耳朵” 博客,请务必保留此出处http://purify.blog.51cto.com/10572011/1844054
原文地址:http://purify.blog.51cto.com/10572011/1844054