Part.I 磁盘管理
1.cfdisk #图形化的很简单. 不知道你们用什么 反正我喜欢这个 ^_^
cfdisk – display or manipulate disk partition table
必要参数的具体说明如下:
-a用箭头表示选取,而不是以反白表示
-P显示磁盘分区的内容
-z当作新磁盘直接使用
-c<数目>指定柱面数目,而不考虑BIOS的设置
-h<数目>指定磁头数目,而不考虑BIOS的设置
-s<数目>指定磁盘分区数目,而不考虑BIOS的设置
-v版本信息
cfdisk (util-linux 2.23.2)
Disk Drive: /dev/sda
Size: 21474836480 bytes, 21.4 GB
Heads: 255 Sectors per Track: 63 Cylinders: 2610
Name Flags Part Type FS Type [Label] Size (MB)
—————————————————————————————-
Pri/Log Free Space 1.05 *
sda1 Boot Primary xfs 524.29 *
sda2 Primary LVM2_member 20949.50 *
[ Help ] [ New ] [ Print ] [ Quit ] [ Units ]
[ Write ]
Create new partition from free space
2.sfdisk #sfdisk为硬盘分区工具程序,可显示分区的设定信息,并检查分区是否正常,也可用来建立分区。
-s [or –show-size] 显示一个分区的大小
-c [or –id]显示或者修改文件系统类型ID
-l [or –list]显示每个设备的分区表信息
-d [or –dump]同上,但是以一个格式化的方式输出
-i [or –increment]number cylinders etc. from 1 instead of from 0
-uS, -uB, -uC, -uM 以扇面/块/柱面数/MB为单位 显示或形成报告
-T [or –list-types]显示所有已知的sfdisk能辨识的文件系统ID
-D [or –DOS] 兼容DOS但是会浪费一点磁盘空间
-R [or –re-read]:让内核重新读取分区表
-N# 只改变分区的编号 #
-n 修改但实际上并没有保存到磁盘
-O file 保存扇面修改并写入分区表文件
-I file 重新恢复修改的扇面
sfdisk -d /dev/hda > hda-table 备份分区表并保存到文件
sfdisk /dev/hda < hda-table 从文件中恢复分区表
sfdisk -d /dev/hda | sfdisk /dev/hdb 在两个磁盘间复制分区表
[root@localhost ~]# sfdisk
Usage:
sfdisk [options] <device> […]
Options:
-s, –show-size list size of a partition
-c, –id change or print partition Id
–change-id change Id
–print-id print Id
-l, –list list partitions of each device
-d, –dump idem, but in a format suitable for later input
-i, –increment number cylinders etc. from 1 instead of from 0
-u, –unit <letter> units to be used; <letter> can be one of
S (sectors), C (cylinders), B (blocks), or M (MB)
-1, –one-only reserved option that does nothing currently
-T, –list-types list the known partition types
-D, –DOS for DOS-compatibility: waste a little space
-E, –DOS-extended DOS extended partition compatibility
-R, –re-read make the kernel reread the partition table
-N <number> change only the partition with this <number>
-n do not actually write to disk
-O <file> save the sectors that will be overwritten to <file>
-I <file> restore sectors from <file>
-V, –verify check that the listed partitions are reasonable
-v, –version display version information and exit
-h, –help display this help text and exit
Dangerous options:
-f, –force disable all consistency checking
–no-reread do not check whether the partition is in use
-q, –quiet suppress warning messages
-L, –Linux do not complain about things irrelevant for Linux
-g, –show-geometry print the kernel's idea of the geometry
-G, –show-pt-geometry print geometry guessed from the partition table
-A, –activate[=<device>] activate bootable flag
-U, –unhide[=<dev>] set partition unhidden
-x, –show-extended also list extended partitions in the output,
or expect descriptors for them in the input
–leave-last do not allocate the last cylinder
–IBM same as –leave-last
–in-order partitions are in order
–not-in-order partitions are not in order
–inside-outer all logicals inside outermost extended
–not-inside-outer not all logicals inside outermost extended
–nested every partition is disjoint from all others
–chained like nested, but extended partitions may lie outside
–onesector partitions are mutually disjoint
Override the detected geometry using:
-C, –cylinders <number> set the number of cylinders to use
-H, –heads <number> set the number of heads to use
-S, –sectors <number> set the number of sectors to use
3. parted #磁盘分区和分区大小调整工具,与fdisk不同,它支持调整分区的大小。
-h显示帮助信息
-i交互式模式
-s脚本模式,不提示用户
-v显示版本号
实例<Via http://man.linuxde.net/parted >
红帽企业 Linux 4 Update 4供对大于 2 terabytes(TB)的磁盘设备的支持。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 35.8 GB, 35862976512 bytes
255 heads, 63 sectors/track, 4360 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 144 1052257+ 82 Linux swap
/dev/sda3 145 4360 33865020 83 Linux
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@localhost ~]# parted /dev/sdb
GNU Parted Copyright (C) 1998 – 2004 free Software Foundation, Inc.
This program is free software, covered by the GNU General Public License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
使用/dev/sdb
(parted)mklabel gpt
(parted)print
/dev/sdb的磁盘几何结构:0.000-2048.000兆字节
磁盘标签类型:gpt
Minor 起始点 终止点 文件系统 名称 标志
(parted)mkpart primary 0 2048 <—–上面print显示的数字
(parted)print
/dev/sdb的磁盘几何结构:0.000-2048.000兆字节
磁盘标签类型:gpt
Minor 起始点 终止点 文件系统 名称 标志
1 0.017 2047.983
(parted)quit
如果必要,不要忘记更新/etc/fstab。
[root@localhost ~]# fdisk -l
Disk /dev/sda: 35.8 GB, 35862976512 bytes
255 heads, 63 sectors/track, 4360 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 144 1052257+ 82 Linux swap
/dev/sda3 145 4360 33865020 83 Linux
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 262 2097151+ ee EFI GPT
Partition 1 has different physical/logical beginnings (non-Linux?):
phys=(0, 0, 1) logical=(0,0, 2)
Partition 1 has different physical/logical endings:
phys=(1023, 254, 63) logical=(261, 21, 16)
[root@localhost ~]# mkfs.ext3 /dev/sdb1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524279 blocks
26213 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/sdb1 /mnt
[root@localhost ~]# df -h
Filesystem 容量 已用 可用 已用% 挂载点
/dev/sda3 <?xml:namespace prefix = st1 />32G 2.6G 28G 9% /
/dev/sda1 99M 12M 82M 13% /boot
none 252M 0 252M 0% /dev/shm
/dev/sdb1 2.0G 36M 1.9G 2% /mnt
4.fdisk #老牌分区软件<Via http://man.linuxde.net/fdisk>
-b<分区大小>指定每个分区的大小
-l列出指定的外围设备的分区表状况
-s<分区编号>将指定的分区大小输出到标准输出上,单位为区块
-u搭配"-l"参数列表,会用分区数目取代柱面数目,来表示每个分区的起始地址
-v显示版本信息。
[root@localhost ~]# fdisk /dev/sdb
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1 8001 8e Linux LVM
/dev/sdb2 2 26 200812+ 83 Linux
Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Selected partition 2
Command (m for help): print
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help):
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p //建立主分区
Partition number (1-4): 1 //分区号
First cylinder (1-391, default 1): //分区起始位置
Using default value 1
last cylinder or +size or +sizeM or +sizeK (1-391, default 391): 100 //分区结束位置,单位为扇区
Command (m for help): n //再建立一个分区
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2 //分区号为2
First cylinder (101-391, default 101):
Using default value 101
Last cylinder or +size or +sizeM or +sizeK (101-391, default 391): +200M //分区结束位置,单位为M
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e //选择扩展分区
Partition number (1-4): 3
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391):
Using default value 391
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l //选择逻辑分区
First cylinder (126-391, default 126):
Using default value 126
Last cylinder or +size or +sizeM or +sizeK (126-391, default 391): +400M
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (176-391, default 176):
Using default value 176
Last cylinder or +size or +sizeM or +sizeK (176-391, default 391):
Using default value 391
Command (m for help): p
Disk /dev/sdb: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 100 803218+ 83 Linux
/dev/sdb2 101 125 200812+ 83 Linux
/dev/sdb3 126 391 2136645 5 Extended
/dev/sdb5 126 175 401593+ 83 Linux
/dev/sdb6 176 391 1734988+ 83 Linux
Command (m for help):
在硬盘sdb我们建立了2个主分区(sdb1,sdb2),1个扩展分区(sdb3),2个逻辑分区(sdb5,sdb6)
注意:主分区和扩展分区的磁盘号位1-4,也就是说最多有4个主分区或者扩展分区,逻辑分区开始的磁盘号为5,因此在这个实验中试没有sdb4的。
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.ext2 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
100576 inodes, 200804 blocks
10040 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
14368 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkfs.ext3 /dev/sdb6
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
217280 inodes, 433747 blocks
21687 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=444596224
14 block groups
32768 blocks per group, 32768 fragments per group
15520 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]#
建立两个目录/oracle和/web,将新建好的两个分区挂载到系统:
[root@localhost ~]# mkdir /oracle
[root@localhost ~]# mkdir /web
[root@localhost ~]# mount /dev/sdb1 /oracle
[root@localhost ~]# mount /dev/sdb6 /web
查看分区挂载情况:
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
6.7G 2.8G 3.6G 44% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/sdb1 773M 808K 733M 1% /oracle
/dev/sdb6 1.7G 35M 1.6G 3% /web
如果需要每次开机自动挂载则需要修改/etc/fstab文件,加入两行配置:
[root@localhost ~]# vim /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/VolGroup00/LogVol01 swap swap defaults 0 0
/dev/sdb1 /oracle ext2 defaults 0 0
/dev/sdb6 /web ext3 defaults 0 0
5.df #显示磁盘分区上的可使用的磁盘空间
-a [or –all ]包含全部的文件系统
–block-size=<区块大小>以指定的区块大小来显示区块数目
-h [ or–human-readable ]以可读性较高的方式来显示信息
-H [ or—si ]与-h参数相同,但在计算时是以1000 Bytes为换算单位而非1024 Bytes
-I [or—inodes ]显示inode的信息
-k [ or—kilobytes ]指定区块大小为1024字节
-l [ —local ]仅显示本地端的文件系统
-m [ or—megabytes ]指定区块大小为1048576字节
–no-sync在取得磁盘使用信息前,不要执行sync指令,此为预设值
-P [ or—portability ]使用POSIX的输出格式
–sync在取得磁盘使用信息前,先执行sync指令
-t<文件系统类型>或–type=<文件系统类型>仅显示指定文件系统类型的磁盘信息
-T [ or–print-type ]显示文件系统的类型
-x<文件系统类型>或–exclude-type=<文件系统类型>不要显示指定文件系统类型的磁盘信息
–help显示帮助
–version显示版本信息
[root@LinServ-1 ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda2 146294492 28244432 110498708 21% /
/dev/sda1 1019208 62360 904240 7% /boot
tmpfs 1032204 0 1032204 0% /dev/shm
/dev/sdb1 2884284108 218826068 2518944764 8% /data1
使用-h选项以KB以上的单位来显示,可读性高:
[root@LinServ-1 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 140G 27G 106G 21% /
/dev/sda1 996M 61M 884M 7% /boot
tmpfs 1009M 0 1009M 0% /dev/shm
/dev/sdb1 2.7T 209G 2.4T 8% /data1
查看全部文件系统:
[root@LinServ-1 ~]# df -a
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda2 146294492 28244432 110498708 21% /
proc 0 0 0 – /proc
sysfs 0 0 0 – /sys
devpts 0 0 0 – /dev/pts
/dev/sda1 1019208 62360 904240 7% /boot
tmpfs 1032204 0 1032204 0% /dev/shm
/dev/sdb1 2884284108 218826068 2518944764 8% /data1
none 0 0 0 – /proc/sys/fs/binfmt_misc
6.du #显示目录下所有文件和子目录占用磁盘空间大小
-a [ or-all ] 显示目录中个别文件的大小
-b [ or-bytes ] 显示目录或文件大小时,以byte为单位
-c [ or—total ] 除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和
-k [ or—kilobytes ] 以KB(1024bytes)为单位输出
-m [ or—megabytes ] 以MB为单位输出
-s [ or–summarize ]仅显示总计,只列出最后加总的值
-h [ or–human-readable ] 以K,M,G为单位,提高信息的可读性
-x [ or–one-file-xystem ] 以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过
-L<符号链接> [ or–dereference<符号链接> ] 显示选项中所指定符号链接的源文件大小
-S [ or–separate-dirs ] 显示个别目录的大小时,并不含其子目录的大小
-X<文件> [ or–exclude-from=<文件> ] 在<文件>指定目录或文件
–exclude=<目录或文件> 略过指定的目录或文件
-D [ or–dereference-args ] 显示指定符号链接的源文件大小
-H [ or—si ] 与-h参数相同,但是K,M,G是以1000为换算单位
-l [ or –count-links ] 重复计算硬件链接的文件
[root@localhost ~]# du /tmp –max-depth=2
0 /tmp/.X11-unix
0 /tmp/.XIM-unix
0 /tmp/.Test-unix
0 /tmp/.ICE-unix
0 /tmp/.font-unix
32 /tmp/hsperfdata_root
0 /tmp/.esd-0
0 /tmp/tracker-extract-files.0
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS/tmp
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g/tmp
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g
0 /tmp/.esd-988
0 /tmp/.esd-1000
0 /tmp/tracker-extract-files.1000
0 /tmp/hsperfdata_lethe
0 /tmp/kde-root
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a/tmp
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a
0 /tmp/akonadi-root.m8CZHQ
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH/tmp
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL/tmp
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB/tmp
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc/tmp
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA/tmp
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT/tmp
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR/tmp
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4/tmp
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ/tmp
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ
48 /tmp
[root@localhost ~]# du /tmp –max-depth=1
0 /tmp/.X11-unix
0 /tmp/.XIM-unix
0 /tmp/.Test-unix
0 /tmp/.ICE-unix
0 /tmp/.font-unix
32 /tmp/hsperfdata_root
0 /tmp/.esd-0
0 /tmp/tracker-extract-files.0
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-vmtoolsd.service-6B52wS
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-cups.service-NRAW9g
0 /tmp/.esd-988
0 /tmp/.esd-1000
0 /tmp/tracker-extract-files.1000
0 /tmp/hsperfdata_lethe
0 /tmp/kde-root
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-colord.service-8pFC1a
0 /tmp/akonadi-root.m8CZHQ
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-rtkit-daemon.service-rJ2EvH
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-vmtoolsd.service-YnwnWL
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-cups.service-5FlgDB
0 /tmp/systemd-private-e242a57c129540489ff194eb40a95b9e-colord.service-KmmVvc
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-rtkit-daemon.service-K7mkBA
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-vmtoolsd.service-zUafAT
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-cups.service-X0i2eR
0 /tmp/systemd-private-93b078bb14234a13b6c780a3235d7f48-colord.service-M4XbD4
0 /tmp/systemd-private-4600be2ef5184890a45864550edac96b-rtkit-daemon.service-qO3RUJ
48 /tmp
7.dd #吊炸天的好东西作用:“可从标准输入或文件读取数据,依指定的用法来转换数据,再输出到文件、 设备或标准输出。
bs <字节数〉设置输入/输出的字节数
cbs <字节数〉设置转换的字节数
conv <关键字〉转换方式
cout=<区块数〉指定读取的区块数。
ibs <字节数〉设置每次读取的字节数。
If=〈文件〉指定文件作为读取的对象
obs <字节数〉设置每次输出的字节数
of=<文件> 将结果输出到指定的文件
seek <区块数〉忽略指定的区块数,不进行输出
skip <区块数〉忽略指定的区块数,不进行读取
help 显示帮助信息
version 显示版本信息
实例
( 1) 软盘互相复制
要把一张软盘的内容复制到另一张软盘上 ,利用/tmp 作为临时存储区。把源盘插入驱 动据中,输入下述命令:
$ dd if =/dev/fd0 of = / tmp/ tmpf ile
复制完成后,将源盘从驱动器中取出,把目标盘插入 ,输入命令 :
$ dd if = / tmp/ tmpf ile of =/dev /f d0
复制完成后,应该将临时文件删除=
(2) 把 net.i 这个文件写入盘中,并设定读/写缓冲区的数目 〈注意:软盘中的内容会
被完全覆盖掉〉
$ dd if = net.i of = /dev /fd0 bs = 16384
(3) 将文件 sflle 复制到文件 dfile 中
$ dd if =sfile of =dfile
(4 ) 整盘数据备份与恢复
整盘数据备份
将本地的/dev/hdx 整盘备份到/dev/hdy:
dd if =/dev/hdx of =/dev/hdy
将/dev/hdx 全盘数据备份到指定路径的 image 文件:
dd if =/dev/hdx of=/path/to/image
备份/dev/hdx 金盘数据,并利用 gzip 工具进行压缩,保存到指定路径:
dd if=/dev/hdx | gzip /path/to/image .gz
将备份文件恢复到指定盘:
dd if=/path/to/ image of =/dev/hdx
将压缩的备份文件恢复到指定盘:
gzip -dc /path/to/ image.gz | dd of=/dev/hdx
(5) 备份恢复 MBR 记录
① 备份 MBR 记录
备份磁盘开始的 5128 大小的队在BR 信息到指定文件:
dd if=/dev/hdx of=/path/to/image count=l bs=512
② 恢复 MBR 记录
将备份的MBR 信息写到磁盘开始部分:
dd if =/path/to/image of =/dev/hdx
(6) 复制内存资料到硬盘
将内存里的数据复制到 root 目录下的 mem.bin 文件:
dd if =/dev/ mem of =/ root /mem .bin bs= 1024
耍从光盘复制 iso 镜像,可复制光盘数据到 root 文件夹下,并保存为cd.iso 文件:
dd if =/dev/cdrom of =/root/cd.iso
(7 ) 增加 swap 分区文件大小 创建一个足够大的文件 (此处为 256MB )
dd if =/dev/ zero of =/swapfile bsa1024 count= 262144
把这个文件变成 swap 文件: mkswap /swa2file
启用这个 swap 文件: swapon /swapfile
在每次开机的时候自动加载 swap 文件,需要在/etc/fstab 文件中增加一行:
/swapfile swap swap defaults O O
( 8 ) 销毁磁盘数据 利用随机的数据填充硬盘:
dd if =/dev/urandom of =/dev/hdal
在某些必要的场合可以用来销毁数据。执行此操作以后 ,dev/hdal 将无法挂载,创建 和复制操作无法执行。
( 9) 修复硬盘
当硬盘较长时 间 〈比如一两年〉 放置不使用后,磁盘上会产生 magnetic flux point 。当 磁头读到这些区域时会遇到困难,并可能导致 1/0 错误。当这种情况影响到硬盘的第一个 扇区时,可能导致硬盘报废。下面的命令有可能使这些数据起死回生:
dd if=/dev/sda of =/dev/sda
8.
未完待续明天再写
ByLethe
20160X0X
勘误:
暂无 mailto:lethe@lethe.com
原创文章,作者:双庆 李,如若转载,请注明出处:http://www.178linux.com/14134
评论列表(1条)
写标签提高文章收录率,样式上建议使用markdown