在脚本中使用fdisk
[root@CENTOS7 ~]#echo -e “n\n\n\n\n+1G\nw\n” | fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x4c45a428.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Using default response p
Partition number (1-4, default 1): First sector (2048-167772159, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159): Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@CENTOS7 ~]#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 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 1G 0 part
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 1G 0 part
├─sdb2 8:18 0 1K 0 part
├─sdb3 8:19 0 2G 0 part
└─sdb5 8:21 0 200M 0 part
sdc 8:32 0 80G 0 disk
└─sdc1 8:33 0 1G 0 part
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
[root@CENTOS7 ~]#echo -e “n\n\n\n\n+1G\nw\n” | fdisk /dev/sdc 从定向方式
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x4c45a428.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Using default response p
Partition number (1-4, default 1): First sector (2048-167772159, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159): Partition 1 of type Linux and of size 1 GiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@CENTOS7 ~]#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 50G 0 part /
├─sda3 8:3 0 30G 0 part /data
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 1G 0 part
sdb 8:16 0 100G 0 disk
├─sdb1 8:17 0 1G 0 part
├─sdb2 8:18 0 1K 0 part
├─sdb3 8:19 0 2G 0 part
└─sdb5 8:21 0 200M 0 part
sdc 8:32 0 80G 0 disk
└─sdc1 8:33 0 1G 0 part
sdd 8:48 0 60G 0 disk
sr0 11:0 1 8.1G 0 rom /run/media/root/CentOS 7 x86_64
查看centos6上sda有多少个块组,一个块组就多少个块组成
dumpe2fs /dev/sda1
[root@centos ~]#dumpe2fs /dev/sda1
dumpe2fs 1.41.12 (17-May-2010)
Filesystem volume name: <none>
Last mounted on: /boot
Filesystem UUID: 414ab9ee-af40-44f1-b300-d29fc674eb8e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 262144
Reserved block count: 13107
Free blocks: 241094
Free inodes: 65498
First block: 0
Block size: 4096
Fragment size: 4096
Reserved GDT blocks: 63
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Tue Mar 27 16:56:37 2018
Last mount time: Mon Apr 23 08:47:13 2018
Last write time: Mon Apr 23 08:47:13 2018
Mount count: 52
Maximum mount count: -1
Last checked: Tue Mar 27 16:56:37 2018
Check interval: 0 (<none>)
Lifetime writes: 82 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 1ae4dcb2-74ba-4214-955b-ae990ad39f42
Journal backup: inode blocks
Journal features: (none)
Journal size: 32M
Journal length: 8192
Journal sequence: 0x00000038
Journal start: 0
Group 0: (Blocks 0-32767) [ITABLE_ZEROED]
Checksum 0xf60c, unused inodes 8155
Primary superblock at 0, Group descriptors at 1-1
Reserved GDT blocks at 2-64
Block bitmap at 65 (+65), Inode bitmap at 81 (+81)
Inode table at 97-608 (+97)
28581 free blocks, 8155 free inodes, 5 directories, 8155 unused inodes
Free blocks: 79, 90-95, 4194-32767
Free inodes: 38-8192
Group 1: (Blocks 32768-65535) [ITABLE_ZEROED]
Checksum 0x2122, unused inodes 8191
Backup superblock at 32768, Group descriptors at 32769-32769
Reserved GDT blocks at 32770-32832
Block bitmap at 66 (+4294934594), Inode bitmap at 82 (+4294934610)
Inode table at 609-1120 (+4294935137)
24292 free blocks, 8191 free inodes, 1 directories, 8191 unused inodes
Free blocks: 34666-34667, 34682-34683, 34688-34815, 41362-41363, 41374-41375, 41380-65535
Free inodes: 8194-16384
Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x4789, unused inodes 8192
Block bitmap at 67 (+4294901827), Inode bitmap at 83 (+4294901843)
Inode table at 1121-1632 (+4294902881)
32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 65536-98303
Free inodes: 16385-24576
Group 3: (Blocks 98304-131071) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x30dc, unused inodes 8192
Backup superblock at 98304, Group descriptors at 98305-98305
Reserved GDT blocks at 98306-98368
Block bitmap at 68 (+4294869060), Inode bitmap at 84 (+4294869076)
Inode table at 1633-2144 (+4294870625)
32703 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 98369-131071
Free inodes: 24577-32768
Group 4: (Blocks 131072-163839) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x74e6, unused inodes 8192
Block bitmap at 69 (+4294836293), Inode bitmap at 85 (+4294836309)
Inode table at 2145-2656 (+4294838369)
24576 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 139264-163839
Free inodes: 32769-40960
Group 5: (Blocks 163840-196607) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x0de1, unused inodes 8192
Backup superblock at 163840, Group descriptors at 163841-163841
Reserved GDT blocks at 163842-163904
Block bitmap at 70 (+4294803526), Inode bitmap at 86 (+4294803542)
Inode table at 2657-3168 (+4294806113)
32703 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 163905-196607
Free inodes: 40961-49152
Group 6: (Blocks 196608-229375) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
Checksum 0x44e3, unused inodes 8192
Block bitmap at 71 (+4294770759), Inode bitmap at 87 (+4294770775)
Inode table at 3169-3680 (+4294773857)
32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 196608-229375
Free inodes: 49153-57344
Group 7: (Blocks 229376-262143) [INODE_UNINIT, ITABLE_ZEROED]
Checksum 0x4c72, unused inodes 8192
Backup superblock at 229376, Group descriptors at 229377-229377
Reserved GDT blocks at 229378-229440
Block bitmap at 72 (+4294737992), Inode bitmap at 88 (+4294738008)
Inode table at 3681-4192 (+4294741601)
32703 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
Free blocks: 229441-262143
Free inodes: 57345-65536
superblock 很重要其中存放着分区的元数据和块组的划分,所以在奇数1,3..9….都有备份
[root@CENTOS7 ~]#mkfs.ext4 /dev/sdc1 -b 1024 创建一个文件系统指定这个文件系统的块大小是1k,块的大小只有在创建文件系统的时候可以指定,一但创建完毕则无法修改。默认的是4k
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 1048576 blocks
52428 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=34603008
128 block groups
8192 blocks per group, 8192 fragments per group
512 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553,
1024001
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#tune2fs -l /dev/sdc1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: e3982c14-ce5c-4285-8fb0-26816d691b6e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 1048576
Reserved block count: 52428
Free blocks: 996238
Free inodes: 65525
First block: 1
Block size: 1024
Fragment size: 1024
Group descriptor size: 64
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 512
Inode blocks per group: 128
Flex block group size: 16
Filesystem created: Mon Apr 23 19:35:25 2018
Last mount time: n/a
Last write time: Mon Apr 23 19:35:25 2018
Mount count: 0
Maximum mount count: -1
Last checked: Mon Apr 23 19:35:25 2018
Check interval: 0 (<none>)
Lifetime writes: 32 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 74c87523-34f1-4be2-864c-d515d4425a22
Journal backup: inode blocks
Inode count: 65536 节点编号
Block count: 1048576 块数量
Reserved block count: 52428 默认百分之5,保留的块数量留给id为0的用户使用
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
mkfs.ext4 /dev/sdc1 -b 1024 -m 1
mke2fs:ext系列文件系统专用管理工具
-t {ext2|ext3|ext4}
-b {1024|2048|4096}
-L ‘LABEL’
-j: 相当于 -t ext3
mkfs.ext3 = mkfs -t ext3 = mke2fs -j = mke2fs -t ext3
-i #: 为数据空间中每多少个字节创建一个inode;此大小
不应该小于block的大小
-N #:指定分区中创建多少个inode
-I 一个inode记录占用的磁盘空间大小,128—4096
-m #: 默认5%,为管理人员预留空间占总空间的百分比
-O FEATURE[,…]:启用指定特性
-O ^FEATURE:关闭指定特性
[root@CENTOS7 ~]#mkfs.ext4 /dev/sdc1 -b 1024 -m 0.1 创建一个块是1k,为id0预留千分之一个块的文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 1048576 blocks
1048 blocks (0.10%) reserved for the super user
First data block=1
Maximum filesystem blocks=34603008
128 block groups
8192 blocks per group, 8192 fragments per group
512 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553,
1024001
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#tune2fs -l /dev/sdc1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 884dac1d-3d83-4685-8b98-53bcb1619452
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 1048576
Reserved block count: 1048
Free blocks: 996238
Free inodes: 65525
First block: 1
Block size: 1024
Fragment size: 1024
Group descriptor size: 64
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 512
Inode blocks per group: 128
Flex block group size: 16
Filesystem created: Mon Apr 23 19:42:10 2018
Last mount time: n/a
Last write time: Mon Apr 23 19:42:11 2018
Mount count: 0
Maximum mount count: -1
Last checked: Mon Apr 23 19:42:10 2018
Check interval: 0 (<none>)
Lifetime writes: 32 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: 0940f0ee-880e-40a1-bc8c-21bb6677114a
Journal backup: inode blocks
[root@CENTOS7 ~]#mkfs.ext4 /dev/sdc2 -b 1024 -i 1024 -m 1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2097152 inodes, 2097152 blocks
20971 blocks (1.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=35651584
256 block groups
8192 blocks per group, 8192 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409, 663553,
1024001, 1990657
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#tune2fs -l /dev/sdc2
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 381e389c-a0a7-4b8d-bc7e-5c29152162ce
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 2097152
Block count: 2097152
Reserved block count: 20971
Free blocks: 1536293
Free inodes: 2097141
First block: 1
Block size: 1024
Fragment size: 1024
Group descriptor size: 64
Reserved GDT blocks: 256
Blocks per group: 8192
Fragments per group: 8192
Inodes per group: 8192
Inode blocks per group: 2048
Flex block group size: 16
Filesystem created: Mon Apr 23 19:48:03 2018
Last mount time: n/a
Last write time: Mon Apr 23 19:48:04 2018
Mount count: 0
Maximum mount count: -1
Last checked: Mon Apr 23 19:48:03 2018
Check interval: 0 (<none>)
Lifetime writes: 32 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: f5054342-a203-4d51-b668-67f26b90ae0e
Journal backup: inode blocks
[root@CENTOS7 ~]#mkfs.ext4 /dev/sdc2 -N 209715 指定多少个inodes,实际要多一些可能是因为取整.
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
209920 inodes, 524288 blocks
26214 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
13120 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#tune2fs -l /dev/sdc2
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: <none>
Last mounted on: <not available>
Filesystem UUID: 60be96b2-617c-4a8d-90f4-4f6fe194333e
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 209920
Block count: 524288
Reserved block count: 26214
Free blocks: 493204
Free inodes: 209909
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 255
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 13120
Inode blocks per group: 820
Flex block group size: 16
Filesystem created: Mon Apr 23 19:55:26 2018
Last mount time: n/a
Last write time: Mon Apr 23 19:55:27 2018
Mount count: 0
Maximum mount count: -1
Last checked: Mon Apr 23 19:55:26 2018
Check interval: 0 (<none>)
Lifetime writes: 65 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: e3845910-09be-4b48-a8e4-aef809454480
Journal backup: inode blocks
[root@CENTOS7 ~]#mkfs.ext2 /dev/sdc1 -O has_journal 添加日志功能
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#blkid /dev/sdc1
/dev/sdc1: UUID=”34cacf85-0038-42c5-9ce5-0d77bba36d43″ SEC_TYPE=”ext2″ TYPE=”ext3″
[root@CENTOS7 ~]#tune2fs -O ^has_journal /dev/sdc1 取消日志功能
tune2fs 1.42.9 (28-Dec-2013)
[root@CENTOS7 ~]#blkid /dev/sdc1
/dev/sdc1: UUID=”8980fe3c-2c14-4db8-b623-b4f0bfcc3cba” TYPE=”ext2″
[root@CENTOS7 ~]#mkfs.ext4 /dev/sdc1 -L data 创建文件系统时起(卷标),最好用挂载点的名字
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=data
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[root@CENTOS7 ~]#tune2fs -l /dev/sdc1
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: data
[root@CENTOS7 ~]#blkid /dev/sdc1
/dev/sdc1: LABEL=”data” UUID=”70496471-2329-49d7-8524-5ba956fbb040″ TYPE=”ext4″
文件系统标签
指向设备的另一种方法
与设备无关
blkid:块设备属性信息查看
blkid [OPTION]… [DEVICE]
-U UUID: 根据指定的UUID来查找对应的设备 通用
-L LABEL:根据指定的LABEL来查找对应的设备
e2label:管理ext系列文件系统的LABEL
e2label DEVICE [LABEL] 只适合ext系列
findfs :查找分区
findfs [options] LABEL=<label> 通用
findfs [options] UUID=<uuid>
[root@CENTOS7 ~]#blkid -U c837ab44-edcb-43af-b4fa-c26832a7af7e 用uuid查看设备名
/dev/sdb1
[root@CENTOS7 ~]#blkid -L “data” 用卷标查看设备名
/dev/sdc1
[root@centos ~]#cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Mar 27 16:59:39 2018
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=408b65d7-7551-480b-8916-5eff4cca1b00 / ext4 defaults 1 1
UUID=414ab9ee-af40-44f1-b300-d29fc674eb8e /boot ext4 defaults 1 2
UUID=37d5cf25-ead4-427b-9655-40fc1602b5df /data ext4 defaults 1 2
UUID=9fc26932-7094-4948-b395-24ab05d8ea73 swap swap defaults 0 0
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
[root@centos ~]#cat /etc/fstab | grep -o “data”
data
[root@centos ~]#cat /etc/fstab | grep “data”
UUID=37d5cf25-ead4-427b-9655-40fc1602b5df /data ext4 defaults 1 2
[root@centos ~]#cat /etc/fstab | grep “data” | sed -r ‘s@.*=(.*) /.*@\1@’
37d5cf25-ead4-427b-9655-40fc1602b5df
[root@centos ~]#blkid -U `cat /etc/fstab | grep “data” | sed -r ‘s@.*=(.*) /.*@\1@’` 查看data对应的设备名
/dev/sda3
root@CENTOS7 ~]#e2label /dev/sdc1 /data/sdc1 修改卷标名字 只识别ext4
[root@CENTOS7 ~]#e2label /dev/sdc1
/data/sdc1
[root@CENTOS7 ~]#findfs LABEL=/data/sdc1
/dev/sdc1
[root@CENTOS7 ~]#findfs UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″
/dev/sda1
tune2fs
tune2fs:重新设定ext系列文件系统可调整参数的值
-l:查看指定文件系统超级块信息;super block
-L ‘LABEL’:修改卷标
-m #:修预留给管理员的空间百分比
-j: 将ext2升级为ext3
-O: 文件系统属性启用或禁用, –O ^has_journal
-o: 调整文件系统的默认挂载选项,–o ^acl
-U UUID: 修改UUID号
dumpe2fs:
块分组管理,32768块
-h:查看超级块信息,不显示分组信息
/dev/sdc1: LABEL=”/data/sdc1″ UUID=”c2188236-fd12-4348-b372-7ee9003ae378″ TYPE=”ext4″
/dev/sdc2: UUID=”60be96b2-617c-4a8d-90f4-4f6fe194333e” TYPE=”ext4″
[root@CENTOS7 ~]#tune2fs -U `uuidgen` /dev/sdc1 修改UUID,一般不要修改
tune2fs 1.42.9 (28-Dec-2013)
[root@CENTOS7 ~]#blkid
/dev/sdb1: UUID=”c837ab44-edcb-43af-b4fa-c26832a7af7e” TYPE=”ext4″
/dev/sdb3: UUID=”8eeacb99-2062-4604-89c5-6518d832bec8″ TYPE=”ext2″
/dev/sda1: UUID=”4d8d9214-eeed-4758-8c34-f05492b9ea73″ TYPE=”xfs”
/dev/sda2: UUID=”0a1bc23e-06e5-4210-9b32-0edbff09ca1a” TYPE=”xfs”
/dev/sda3: UUID=”fb669d84-551f-4a70-a11e-f61deec0fd86″ TYPE=”xfs”
/dev/sda5: UUID=”906330a5-2af1-4bf4-8b2d-9337eaf92250″ TYPE=”swap”
/dev/sr0: UUID=”2017-09-06-10-53-42-00″ LABEL=”CentOS 7 x86_64″ TYPE=”iso9660″ PTTYPE=”dos”
/dev/sdc1: LABEL=”/data/sdc1″ UUID=”ad468b62-a818-493d-911f-4f8a871986b9″ TYPE=”ext4″
文件系统检测和修复
常发生于死机或者非正常关机之后
挂载为文件系统标记为“no clean”
注意:一定不要在挂载状态下修复
fsck: File System Check
fsck.FS_TYPE
fsck -t FS_TYPE
-p: 自动修复错误
-r: 交互式修复错误
FS_TYPE一定要与分区上已经文件类型相同
e2fsck:ext系列文件专用的检测修复工具
-y:自动回答为yes
-f:强制修复
[root@CENTOS7 ~]#dd if=/dev/zero of=/dev/sdc1 bs=1M count=20 破坏一个文件系统
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.186818 s, 112 MB/s
[root@CENTOS7 ~]#tune2fs -l /dev/sdc1 已经破坏无法查看
tune2fs 1.42.9 (28-Dec-2013)
tune2fs: Bad magic number in super-block while trying to open /dev/sdc1
Couldn’t find valid filesystem superblock.
[root@CENTOS7 ~]#fsck /dev/sdc1 -y 修复
fsck from util-linux 2.23.2
e2fsck 1.42.9 (28-Dec-2013)
ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks…
Superblock has an invalid journal (inode 8).
Clear? yes
*** ext3 journal has been deleted – filesystem is now ext2 only ***
/data/sdc1 was not cleanly unmounted, check forced.
Resize inode not valid. Recreate? yes
Pass 1: Checking inodes, blocks, and sizes
Root inode is not a directory. Clear? yes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Root inode not allocated. Allocate? yes
/lost+found not found. Create? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Block bitmap differences: +(0–136) +(145–152) +(161–4257) +(32768–32896) +(98304–98432) +(163840–163968) +(229376–229504)
Fix? yes
Free blocks count wrong for group #0 (28519, counted=28524).
Fix? yes
Free blocks count wrong for group #4 (24576, counted=32768).
Fix? yes
Free blocks count wrong (249187, counted=257384).
Fix? yes
Inode bitmap differences: +1 +(3–10)
Fix? yes
Free inodes count wrong for group #0 (8180, counted=8181).
Fix? yes
Directories count wrong for group #0 (3, counted=2).
Fix? yes
Free inodes count wrong (65524, counted=65525).
Fix? yes
Recreate journal? yes
Creating journal (8192 blocks): Done.
*** journal has been re-created – filesystem is now ext3 again ***
/data/sdc1: ***** FILE SYSTEM WAS MODIFIED *****
/data/sdc1: 11/65536 files (0.0% non-contiguous), 12952/262144 blocks
[root@CENTOS7 ~]#tune2fs -l /dev/sdc1 修复成功显示为clean
tune2fs 1.42.9 (28-Dec-2013)
Filesystem volume name: /data/sdc1
Last mounted on: <not available>
Filesystem UUID: ad468b62-a818-493d-911f-4f8a871986b9
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags: signed_directory_hash
Default mount options: user_xattr acl
Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
Inode count: 65536
Block count: 262144
Reserved block count: 13107
Free blocks: 249192
Free inodes: 65525
First block: 0
Block size: 4096
Fragment size: 4096
Group descriptor size: 64
Reserved GDT blocks: 127
Blocks per group: 32768
Fragments per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Flex block group size: 16
Filesystem created: Mon Apr 23 20:11:09 2018
Last mount time: n/a
Last write time: Mon Apr 23 20:46:23 2018
Mount count: 0
Maximum mount count: -1
Last checked: Mon Apr 23 20:46:23 2018
Check interval: 0 (<none>)
Lifetime writes: 65 MB
Reserved blocks uid: 0 (user root)
Reserved blocks gid: 0 (group root)
First inode: 11
Inode size: 256
Required extra isize: 28
Desired extra isize: 28
Journal inode: 8
Default directory hash: half_md4
Directory Hash Seed: bfa8a27e-378a-4cdc-8184-6a2dd5f92ac6
Journal backup: inode blocks
[root@CENTOS7 ~]#e2fsck -f /dev/sdc1 强制检查全盘文件系统
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/data/sdc1: 11/65536 files (0.0% non-contiguous), 12952/262144 blocks
在centos7上修复文件系统用的命令是
xfs_repair
[root@CENTOS7 ~]#xfs_ 双击Tan查看觉得其他功能
xfs_admin xfs_db xfs_fsr xfs_io xfs_metadump xfs_quota
xfs_bmap xfs_estimate xfs_growfs xfs_logprint xfs_mkfile xfs_repair
xfs_copy xfs_freeze xfs_info xfs_mdrestore xfs_ncheck xfs_rtcp
[root@CENTOS7 ~]#xfs_info /dev/sda3 显示信息 但是必须是挂载状态才能查询
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1966080 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7864320, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3840, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
挂载mount
挂载:将额外文件系统与根文件系统某现存的目录建立起关联关系,进而使得此
目录做为其它文件访问入口的行为
卸载:为解除此关联关系的过程
把设备关联挂载点:mount Point
mount
卸载时:可使用设备,也可以使用挂载点
umount
挂载点下原有文件在挂载完成后会被临时隐藏
挂载点目录一般为空
一个挂载点不能挂载多个设备。作为挂载点最好是空文件夹,如果不是空里面的文件会被挂载的设备遮盖导致无法查看,但是文件没有消失当取消挂载的时候还会显示出来。一个设备可以挂载在多个挂载点上,挂载点显示的文件内容是一样的(比如光盘挂载在/misc和/run),有点像硬链接,但是连接数并不增多
用mount命令挂载文件系统
挂载方法:mount DEVICE MOUNT_POINT
mount:通过查看/etc/mtab文件显示当前已挂载的所有设备
mount [-fnrsvw] [-t vfstype] [-o options] device dir
device:指明要挂载的设备;
(1) 设备文件:例如/dev/sda5
(2) 卷标:-L ‘LABEL’, 例如 -L ‘MYDATA’
(3) UUID, -U ‘UUID’:例如 -U ‘0c50523c-43f1-45e7-
85c0-a126711d406e’
(4) 伪文件系统名称:proc, sysfs, devtmpfs, configfs
dir:挂载点
事先存在;建议使用空目录
进程正在使用中的设备无法被卸载
[root@CENTOS7 data]#mkdir sdc1
[root@CENTOS7 ~]#mount /dev/sdc1 /data/sdc1
[root@CENTOS7 ~]#df
dev/sdc1 999320 2552 927956 1% /data/sdc1
[root@CENTOS7 ~]#mount
/dev/sdc1 on /data/sdc1 type ext4 (rw,relatime,seclabel,data=ordered)
[root@CENTOS7 ~]#ll /etc/mtab 挂载的信息存放的地方
lrwxrwxrwx. 1 root root 17 Apr 19 20:35 /etc/mtab -> /proc/self/mounts
[root@CENTOS7 ~]#umount /dev/sdc1 取消挂载,可以写设备名,卷标
[root@CENTOS7 ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 52403200 3898416 48504784 8% /
devtmpfs 535296 0 535296 0% /dev
tmpfs 550036 0 550036 0% /dev/shm
tmpfs 550036 7964 542072 2% /run
tmpfs 550036 0 550036 0% /sys/fs/cgroup
/dev/sda3 31441920 161500 31280420 1% /data
/dev/sda1 1038336 161620 876716 16% /boot
tmpfs 110008 24 109984 1% /run/user/0
/dev/sr0 8490330 8490330 0 100% /run/media/root/CentOS 7 x86_64
tmpfs 110008 0 110008 0% /run/user/1000
[root@CENTOS7 ~]#umount LABEL=/data/sdc1
[root@CENTOS7 ~]#mount LABEL=/data/sdc1 /data/sdc1
[root@CENTOS7 ~]#mkdir /data/sdc11
[root@CENTOS7 ~]#mount /dev/sdc1 /data/sdc11
[root@CENTOS7 ~]#cd /data/sdc1
[root@CENTOS7 sdc1]#touch f1
[root@CENTOS7 sdc1]#ls
f1 lost+found
[root@CENTOS7 sdc1]#cd
[root@CENTOS7 ~]#cd /data/sdc11
[root@CENTOS7 sdc11]#ls
f1 lost+found
[root@CENTOS7 sdc1]#mount /dev/sdc2 /data/sdc1 多个设备挂载到同一个文件夹
[root@CENTOS7 sdc1]#ls
f1 lost+found
[root@CENTOS7 sdc1]#cd ..
[root@CENTOS7 data]#ls ./sdc1
lost+found
普通用户没有权限挂载,也没有权限卸载挂载
[root@CENTOS7 data]#mount -r /dev/sdc2 /data/sdc2 只读
[root@CENTOS7 data]#mount
/dev/sdc2 on /data/sdc2 type ext4 (ro,
[root@CENTOS7 sdc2]#mount -t ext2 /dev/sdc2 /data/sdc2
已ext2文件系统去挂载,除非有必要,不然系统会自动识别文件系统类型,不需要指明
mount常用命令选项
-t vsftype:指定要挂载的设备上的文件系统类型
-r: readonly,只读挂载
-w: read and write, 读写挂载 默认就是可读可写
-n: 不更新/etc/mtab,mount不可见
-a:自动挂载所有支持自动挂载的设备(定义在了/etc/fstab文件中,且挂载选
项中有auto功能)
-L ‘LABEL’: 以卷标指定挂载设备
-U ‘UUID’: 以UUID指定要挂载的设备
-B, –bind: 绑定目录到另一个目录上
查看内核追踪到的已挂载的所有设备
cat /proc/mounts
mount -n /dev/sdc2 /data/sdc2 只在centos6上好用
df cat/dtc/mtab mount查看不到,但是cat/proc/mounts可以查看
[root@CENTOS7 dir]#mount -B /data/dir /data/sdc2
[root@CENTOS7 dir]#touch /data/sdc2/ff
[root@CENTOS7 dir]#ls /data/dir
ff
mount常用命令选项
-o options:(挂载文件系统的选项),多个选项使用逗号分隔
async:异步模式
sync:同步模式,内存更改时,同时写磁盘
atime/noatime:包含目录和文件
diratime/nodiratime:目录的访问时间戳
auto/noauto:是否支持自动挂载,是否支持-a选项
exec/noexec:是否支持将文件系统上运行应用程序
dev/nodev:是否支持在此文件系统上使用设备文件
suid/nosuid:是否支持suid和sgid权限
remount:重新挂载
ro:只读
rw:读写
user/nouser:是否允许普通用户挂载此设备,/etc/fstab使用
acl:启用此文件系统上的acl功能
loop: 使用loop设备
defaults:相当于rw, suid, dev, exec, auto, nouser, async
Mount count: 4 当达到20次时会检查
Maximum mount count: 20
Check interval: 0 (<none>) 到达指定时间检查
[root@CENTOS7 ~]#tune2fs -c 20 /dev/sdc2 调整最大挂载次数,-C调整当前挂载次数
tune2fs 1.42.9 (28-Dec-2013)
Setting maximal mount count to 20
tune2fs -o acl /dev/sdc2 添加 acl权限
tune2fs -o ^acl /dev/sdc2 取消acl权限都需要从新挂载才能生效
mount -o acl /dev/sdc2 /data/sdc2 也可以添加acl权限
mount -o noacl,remount /dev/sdc2 /data/sdc2 不用卸载挂载,直接修改acl权限
卸载命令
查看挂载情况
findmnt MOUNT_POINT|device
查看正在访问指定文件系统的进程
lsof MOUNT_POINT
fuser -v MOUNT_POINT
终止所有在正访问指定的文件系统的进程
fuser -km MOUNT_POINT
卸载
umount DEVICE
umount MOUNT_POINT
[root@centos ~]#fuser -v /data/sdb1 查看谁在使用
USER PID ACCESS COMMAND
/data/sdb1: root 3543 ..c.. bash
[root@centos ~]#fuser -km /data/sdb1 结束所有正在访问这个文件夹的进程
/data/sdb1: 3543c
[root@centos ~]#lsof /data/sdb1 查看谁在使用这个文件夹
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 3574 root cwd DIR 8,17 4096 2 /data/sdb1
root@centos ~]#findmnt /dev/sdb1
TARGET SOURCE FSTYPE OPTIONS
/data/sdb1 /dev/sdb1 ext4 rw,relatime,seclabel,barrier=1,data=ordered
[root@centos ~]#findmnt /dev/sdb2 查看一个设备是否被挂载
[root@centos ~]#
[root@centos ~]#findmnt /data/sdb2 &>/dev/null || mount /dev/sdb2 /data/sdb2
[root@centos ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 50264772 5516120 42188652 12% /
tmpfs 502056 76 501980 1% /dev/shm
/dev/sda1 999320 34944 911948 4% /boot
/dev/sda3 30106576 99960 28470616 1% /data
/dev/sr0 3878870 3878870 0 100% /media/CentOS_6.9_Final
/dev/sdb1 1010780 1304 956464 1% /data/sdb1
/dev/sdb2 2005880 3096 1897560 1% /data/sdb2
[root@centos ~]#dd if=/dev/zero of=/root/p1 bs=1M count=100
100+0 records in
100+0 records out
104857600 bytes (105 MB) copied, 4.87694 s, 21.5 MB/s
[root@centos ~]#mkfs.ext4 /root/p1
mke2fs 1.41.12 (17-May-2010)
/root/p1 is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
[root@centos ~]#mount /root/p1 /data/mm
mount: /root/p1 is not a block device (maybe try `-o loop’?)
[root@centos ~]#mount -o loop /root/p1 /data/mm 将一个文件模拟一个分区使用
[root@centos ~]#touch /data/mm/f1 在这个目录下创建的文件都放在p1里面
想把p1里的所有文件移走直接卸载挂载,远程复制到别的机器上,然后在挂载就可以将里面的文件导出来
[root@centos ~]#losetup -a 查看所有loop设备
/dev/loop0: [0802]:3014775 (/root/p1)
[root@centos ~]#ls /dev/loop*
/dev/loop0 /dev/loop1 /dev/loop2 /dev/loop3 /dev/loop4 /dev/loop5 /dev/loop6 /dev/loop7
[root@centos ~]#mknod /dev/loop8 b 7 8
[root@centos ~]#ls /dev/loop*
/dev/loop0 /dev/loop2 /dev/loop4 /dev/loop6 /dev/loop8
/dev/loop1 /dev/loop3 /dev/loop5 /dev/loop7
[root@centos ~]#cp p1 p2
[root@centos ~]#blkid p1 p2
p1: UUID=”7871347f-da18-4f67-9759-503c43a9cf76″ TYPE=”ext4″
p2: UUID=”7871347f-da18-4f67-9759-503c43a9cf76″ TYPE=”ext4″
[root@centos ~]#losetup /dev/loop8 p2
[root@centos ~]#mkdir /data/loop8; mount /dev/loop8 /data/loop8
[root@centos ~]#df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 50264772 5720948 41983824 12% /
tmpfs 502056 76 501980 1% /dev/shm
/dev/sda1 999320 34944 911948 4% /boot
/dev/sda3 30106576 99968 28470608 1% /data
/dev/sr0 3878870 3878870 0 100% /media/CentOS_6.9_Final
/dev/sdb1 1010780 1304 956464 1% /data/sdb1
/dev/sdb2 2005880 3096 1897560 1% /data/sdb2
/root/p1 95054 1551 88383 2% /data/mm
/dev/loop8 95054 1551 88383 2% /data/loop8
[root@centos ~]#ls /data/loop8
f1 lost+found
[root@centos ~]#vim /boot/grub/grub.conf 从新启动生效
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS 6 (2.6.32-696.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-696.el6.x86_64 ro root=UUID=408b65d7-7551-480b-8916-5eff4cca1b00 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet max_loop=100 使loop自动生成100个
initrd /initramfs-2.6.32-696.el6.x86_64.img
平时使用mount挂载,是在内存中挂载,exit不会丢失,重启会丢失
挂载点和/etc/fstab
配置文件系统体系
被mount、fsck和其它程序使用
系统重启时保留文件系统体系
可以在设备栏使用文件系统卷标
使用mount -a 命令挂载/etc/fstab中的所有文件系统
修改配置文件使启动后自动挂载
[root@centos ~]#vim /etc/fstab
UUID=49002741-38ea-4585-9ef9-3f85cb99ae2c /data/sdb2 ext4 acl,nosuid 0 3
uuid 挂载点 文件类型 默认权限 几天备份(需要配合备份命令) 启动时按顺序检查文件完整性
mount -a 不用重启直接生效
在配置文件中新加入的项可以用mount -a,已经生效的项想要修改不能直接使用mount -a
可以先卸载挂载然后在mount -a 或者 mount -o remount /data/sdb2
[root@centos ~]#tune2fs -U `uuidgen` /dev/sdb2 修改uuid,没有写入配置文件中,重启
tune2fs 1.41.12 (17-May-2010)
系统无法正常启动
输入root口令
vim /etc/fatab 发现是只读模式。
mount -o remount,rw / 将/重新挂载为rw模式
vim /etc/fatab 将错误行的最后一项3改成0.
重新启动
已经可以启动
连接xshell修改配置文件,改成正确的uuid,mount -a
想把/home分到一个独立的分区上
1.备份
2.找一个大的硬盘分区,这个分区的大小要提前规划好,一点分区完成无法修改
fdisk /dev/sdc
3.创建文件系统
mkfs.ext4 /dev/sdc1 -L /home
4.临时创建一个文件夹,将/dev/sdc1挂载上去
mkdir /mnt/home ;mount /dev/sdc1 /mnt/home
5.发通知告知所有用户不要登录,切换到单用户模式init 1
6.cp -a /home/* /mnt/home/中 确保所有文件都已经复制完成
7.rm -rf /home/*
8.vim /etc/fstab 添加/dev/sdc1的uuid 卷标,文件系统 默认项 0 0
9.mount -a
10.init 5
11.umount /mnt/home
12.rm -rf /mnt/home
根目录无法迁移到别的硬盘以为根一直在被访问
文件挂载配置文件
/etc/fstab每行定义一个要挂载的文件系统
要挂载的设备或伪文件系统
设备文件
LABEL:LABEL=””
UUID:UUID=””
伪文件系统名称:proc, sysfs
挂载点
文件系统类型
挂载选项:defaults
转储频率:0:不做备份 1:每天转储 2:每隔一天转储
自检次序: 0:不自检
1:首先自检;一般只有rootfs才用1
特殊挂载关系
1.用文件当分区用 /root/p1 /mnt/p1 ext4 loop 0 0
2.挂载光胖 /dev/sr0 /mnt/cdrom iso9660 0 0
文件夹挂载文件夹 /boot /mnt/boot none bind 0 0
挂载交换分区
启用:swapon
swapon [OPTION]… [DEVICE]
-a:激活所有的交换分区
-p PRIORITY:指定优先级
/etc/fstab:pri=value
禁用:swapoff [OPTION]… [DEVICE]
SWAP的优先级
可以指定swap分区0到32767的优先级,值越大优先级越高
如果用户没有指定,那么核心会自动给swap指定一个优先级,这个优先级从
-1开始,每加入一个新的没有用户指定优先级的swap,会给这个优先级减一
先添加的swap的缺省优先级比较高,除非用户自己指定一个优先级,而用户
指定的优先级(是正数)永远高于核心缺省指定的优先级(是负数)
优化性能:分布存放,高性能磁盘存放
free -m 查看内存和swap
root@centos ~]#free -m
total used free shared buffers cached
Mem: 980 338 641 2 8 44
-/+ buffers/cache: 285 694
Swap: 2047 0 2047
让swap使用一下 dd if=/dev/zero of=/dev/null bs=1024M count=1
现在新加入一个内存条,使内存变成2G,这是swap需要变成4G
想使swap变成4个G有两个方法
1.删除原来的swap在分化成4个G,但是如果swap正在被使用会使数据丢失
2.在添加一个2个G得swap,这个swap最好用一个快速的磁盘,或者用机械磁盘的外圈
[root@centos ~]#free -h
total used free shared buffers cached
Mem: 2.0G 361M 1.6G 2.4M 8.5M 53M
-/+ buffers/cache: 300M 1.7G
Swap: 2.0G 0B 2.0G
[root@centos ~]#fdisk /dev/sdc
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): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): +2G
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/sdc: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0xe72db920
Device Boot Start End Blocks Id System
/dev/sdc1 1 262 2104483+ 82 Linux swap / Solaris
[root@centos ~]#mkswap /dev/sdc1 -L swap_sdc1
Setting up swapspace version 1, size = 2104476 KiB
LABEL=swap_sdc1, UUID=ca1c9c9d-7ed6-45b3-89a4-e8ff36548d0b
[root@centos ~]#vim /etc/fstab
UUID=ca1c9c9d-7ed6-45b3-89a4-e8ff36548d0b swap swap defaults 0 0
[root@centos ~]#swapon -a
[root@centos ~]#free -h
total used free shared buffers cached
Mem: 2.0G 385M 1.6G 2.4M 9.2M 56M
-/+ buffers/cache: 319M 1.6G
Swap: 4.0G 0B 4.0G
[root@centos ~]#swapon -s 查看swap 优先级 数字越大优先越高
Filename Type Size Used Priority
/dev/sda5 partition 2097148 0 -1
/dev/sdc1 partition 2104476 0 -2
修改swap的优先级
[root@centos ~]#vim /etc/fstab
UUID=ca1c9c9d-7ed6-45b3-89a4-e8ff36548d0b swap swap defaults,pri=100 0 0
[root@centos ~]#swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 2097148 0 -1
/dev/sdc1 partition 2104476 0 -2
[root@centos ~]#swapoff /dev/sdc1
[root@centos ~]#swapon -a
[root@centos ~]#swapon -s
Filename Type Size Used Priority
/dev/sda5 partition 2097148 0 -1
/dev/sdc1 partition 2104476 0 100
用文件做swap用
dd if=/dev/zero of=/swapfile bs=1024M count=2
mkswap /swapfile
vim /etc/fstab
/swapfile swap swap defaults 0 0
swapon -a
查看swap
swapon -s =cat /proc/swaps
删除swap
swapoff /dev/sdc1
swapoff /swapfile
删除vim /etc/fstab中相应的行
rm -rf /swapfile
fdisk /dev/sdc
d
1
w
使用光盘
在图形环境下自动启动挂载/run/media/<user>/<label>
否则就必须被手工挂载
mount /dev/cdrom /mnt/
eject命令卸载或弹出磁盘 弹入eject -t
创建ISO文件
cp /dev/cdrom /root/centos7.iso
mkisofs -r -o /root/etc.iso /etc
刻录光盘
wodim –v –eject centos.iso
cp /dev/cdrom /root/centos7.iso制作一个ios文件
dd if=/dev/sr0 of=/root/centos7.iso
也可以将文件夹制作成iso文件
mkisofs -r -o etc.ios /etc/
挂载USB介质
查看USB设备是否识别
lsusb
被内核探测为SCSI设备
/dev/sdaX、/dev/sdbX、或类似的设备文件
在图形环境中自动挂载
图标在[计算机]窗口中创建
挂载在/run/media/<user>/<label>
手动挂载
mount /dev/sdb1 /mnt
tail -f /var/log/messages插入U盘时跟中
挂载U盘的时候 往U盘中传输文件需要多敲几次 ,防止数据放在buffs中没有传过去
sync;sync;sync
常见工具
文件系统空间占用等信息的查看工具:
df [OPTION]… [FILE]…
-H 以1000为单位
-T 文件系统类型
-h: human-readable
-i:inodes instead of blocks
-P: 以Posix兼容的格式输出 当设备名过长时自动对齐
查看某目录总体空间占用状态:
du [OPTION]… DIR
-h: human-readable
-s: summary –max-depth
[root@centos ~]#du -sh /*
27M /app
7.7M /bin
33M /boot
54M /data
704K /dev
42M /etc
672K /home
209M /lib
28M /lib64
16K /lost+found
5.8G /media
0 /misc
4.0K /mnt
0 /net
8.0K /opt
du: cannot access `/proc/4149/task/4149/fd/4′: No such file or directory
du: cannot access `/proc/4149/task/4149/fdinfo/4′: No such file or directory
du: cannot access `/proc/4149/fd/4′: No such file or directory
du: cannot access `/proc/4149/fdinfo/4′: No such file or directory
0 /proc
286M /root
17M /sbin
0 /selinux
4.0K /srv
0 /sys
1.4M /tmp
4.1G /usr
823M /var
[root@centos ~]#du -h –max-depth 0 /etc
42M /etc
工具dd
dd命令:convert and copy a file
用法:
dd if=/PATH/FROM/SRC of=/PATH/TO/DEST
bs=#:block size, 复制单元大小
count=#:复制多少个bs
of=file 写到所命名的文件而不是到标准输出
if=file 从所命名文件读取而不是从标准输入
bs=size 指定块大小(既是是ibs也是obs)
ibs=size 一次读size个byte
obs=size 一次写size个byte
cbs=size 一次转化size个byte
skip=blocks 从开头忽略blocks个ibs大小的块
seek=blocks 从开头忽略blocks个obs大小的块
count=n 只拷贝n个记录
工具dd
conv=conversion[,conversion…] 用指定的参数转换文件
转换参数:
ascii 转换 EBCDIC 为 ASCII
ebcdic 转换 ASCII 为 EBCDIC
lcase 把大写字符转换为小写字符
ucase 把小写字符转换为大写字符
nocreat 不创建输出文件
noerror 出错时不停止
notrunc 不截短输出文件
sync 把每个输入块填充到ibs个字节,不足部分用空(NUL)字
符补齐
[root@centos data]#cat f2
abcdefgh
[root@centos data]#dd if=f1 of=f2
0+1 records in
0+1 records out
7 bytes (7 B) copied, 0.000258348 s, 27.1 kB/s
[root@centos data]#cat f2 截断模式,后面的统统干掉
123456
设备文件不截断
[root@centos data]#dd if=f1 of=f2 bs=1 count=2 skip=3 seek=4 conv=notrunc
2+0 records in
2+0 records out
2 bytes (2 B) copied, 0.000281923 s, 7.1 kB/s
[root@centos data]#cat f2
abcd45gh
[root@centos data]#dd if=f2 of=f3 conv=ucase
0+1 records in
0+1 records out
9 bytes (9 B) copied, 0.000288186 s, 31.2 kB/s
[root@centos data]#cat f3
ABCD45GH
工具dd
备份MBR:
dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
破坏MBR中的bootloader:
dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446
有一个大与2K的二进制文件fileA。现在想从第64个字节位置开始读取,需要读
取的大小是128Byts。又有fileB, 想把上面读取到的128Bytes写到第32个字节开
始的位置,替换128Bytes,实现如下:
dd if=fileA of=fileB bs=1 count=128 skip=63 seek=31 conv=notrunc
工具dd
备份:
dd if=/dev/sdx of=/dev/sdy sdy硬盘一定比sdx大
将本地的/dev/sdx整盘备份到/dev/sdy
dd if=/dev/sdx of=/path/to/image
将/dev/sdx全盘数据备份到指定路径的image文件
dd if=/dev/sdx | gzip >/path/to/image.gz
备份/dev/sdx全盘数据,并利用gzip压缩,保存到指定路径
恢复:
dd if=/path/to/image of=/dev/sdx
将备份文件恢复到指定盘
gzip -dc /path/to/image.gz | dd of=/dev/sdx
将压缩的备份文件恢复到指定盘
工具dd
拷贝内存资料到硬盘
dd if=/dev/mem of=/root/mem.bin bs=1024
将内存里的数据拷贝到root目录下的mem.bin文件
从光盘拷贝iso镜像
dd if=/dev/cdrom of=/root/cd.iso
拷贝光盘数据到root文件夹下,并保存为cd.iso文件
销毁磁盘数据
dd if=/dev/urandom of=/dev/sda1
利用随机的数据填充硬盘,在某些必要的场合可以用来销毁数据,执行此操作以后,
/dev/sda1将无法挂载,创建和拷贝操作无法执行
工具dd
得到最恰当的block size
dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
dd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file
dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
通过比较dd指令输出中命令的执行时间,即可确定系统最佳的block size大小
[root@CENTOS7 ~]#dd if=/dev/zero of=f1 bs=1024 count=1024000
1024000+0 records in
1024000+0 records out
1048576000 bytes (1.0 GB) copied, 27.7282 s, 37.8 MB/s
[root@CENTOS7 ~]#dd if=/dev/zero of=f1 bs=2048 count=512000
512000+0 records in
512000+0 records out
1048576000 bytes (1.0 GB) copied, 28.0448 s, 37.4 MB/s
[root@CENTOS7 ~]#dd if=/dev/zero of=f1 bs=4k count=256000
256000+0 records in
256000+0 records out
1048576000 bytes (1.0 GB) copied, 14.9327 s, 70.2 MB/s
工具dd
修复硬盘
dd if=/dev/sda of=/dev/sda
当硬盘较长时间(比如1,2年)放置不使用后,磁盘上会产生消磁点。当磁头读
到这些区域时会遇到困难,并可能导致I/O错误。当这种情况影响到硬盘的第一
个扇区时,可能导致硬盘报废。上边的命令有可能使这些数据起死回生,且这个
过程是安全高效的
什么是RAID
RAID:Redundant Arrays of Inexpensive(Independent) Disks
1988年由加利福尼亚大学伯克利分校(University of California-
Berkeley) “A Case for Redundant Arrays of Inexpensive Disks”
多个磁盘合成一个“阵列”来提供更好的性能、冗余,或者两者都提供
RAID
提高IO能力
磁盘并行读写
提高耐用性
磁盘冗余来实现
级别:多块磁盘组织在一起的工作方式有所不同
RAID实现的方式:
外接式磁盘阵列:通过扩展卡提供适配能力
内接式RAID:主板集成RAID控制器
安装OS前在BIOS里配置
软件RAID:通过OS实现
RAID级别
RAID-0:
读、写性能提升;
可用空间:N*min(S1,S2,…)
无容错能力
最少磁盘数:2, 2+
RAID0又叫条带集 假设有3块硬盘,已3块硬盘中最小的一个为准假设是100G,那么通过raid0就组成了一个300G的大硬盘,然后对这个300G的硬盘分区创建文件系统。
挂载。在挂载文件夹中创建一个100M的文件,将100M的文件分解成chunk,chunk的大小可以指定
假设是256k。
存储时是1 2 3
4 5 6
……
读写速度快,但是没有冗余,一但有一块硬盘坏了,数据就被破坏了
RAID4 最少3块硬盘才能实现
假设有3块硬盘,已3块硬盘中最小的一个为准假设是100G,那么通过raid0就组成了一个300G的大硬盘,然后对这个300G的硬盘分区创建文件系统。
挂载。在挂载文件夹中创建一个100M的文件,将100M的文件分解成chunk,chunk的大小可以指定
假设是256k。
存储时是1 2 x x是校验位,x1^2
3 4 x
…….
读写速度变快,一但有一块硬盘坏了,可以继续工作,但是由于校验位运算太频繁导致经常损坏
RAID5 最少3块硬盘才能实现
假设有3块硬盘,已3块硬盘中最小的一个为准假设是100G,那么通过raid0就组成了一个300G的大硬盘,然后对这个300G的硬盘分区创建文件系统。
挂载。在挂载文件夹中创建一个100M的文件,将100M的文件分解成chunk,chunk的大小可以指定
假设是256k。
存储时是1 2 3 x x是校验位,x1^2^3
4 5 x 6
7 x 8 9
x 10 11 12
………….
读写速度变快,一但有一块硬盘坏了,可以继续工作,一但有一块硬盘坏了,会导致服务器负载急剧增大,可能导致系统崩溃
所以一但有硬盘坏了要迅速更换.有一块备用硬盘(spare disk)平时监视raid,一但有硬盘损坏则自己替换。
RAID6 最少4块硬盘才能实现
假设有3块硬盘,已3块硬盘中最小的一个为准假设是100G,那么通过raid0就组成了一个300G的大硬盘,然后对这个300G的硬盘分区创建文件系统。
挂载。在挂载文件夹中创建一个100M的文件,将100M的文件分解成chunk,chunk的大小可以指定
假设是256k。
存储时是1 2 x x x是校验位,
3 x x 4 x的算法a+b=c
x x 5 6 na+mb=d
x 7 8 x
RAID-1:
读性能提升、写性能略有下降;
可用空间:1*min(S1,S2,…)
有冗余能力
最少磁盘数:2, 2N
就是两两互为镜像. 一但删除文件无法恢复
RAID级别
JBOD:Just a Bunch Of Disks
功能:将多块磁盘的空间合并一个大的连续空间使用
可用空间:sum(S1,S2,…)
就是把几块硬盘组合在一起当一个大的硬盘使用,假设 1 2 3个
硬盘,1存满在存2.
硬raid组合的硬盘在linux中只能看到一块sda,别的看不到
软raid可以看到有几块硬盘生成的设备名通常为/dev/md#
RAID级别
RAID7
可以理解为一个独立存储计算机,自身带有操作系统和管理工具,可以独立
运行,理论上性能最高的RAID模式
常用级别:
RAID-0, RAID-1, RAID-5, RAID-10, RAID-50, JBOD
软RAID
mdadm:为软RAID提供管理界面
为空余磁盘添加冗余
结合内核中的md(multi devices)
RAID设备可命名为/dev/md0、/dev/md1、/dev/md2、/dev/md3等
系统默认没有raid
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/97270