码迷,mamicode.com
首页 > 其他好文 > 详细

格式化、挂载、手动增加swap

时间:2017-11-03 15:16:59      阅读:579      评论:0      收藏:0      [点我收藏+]

标签:格式化 挂载 swap

4.5 磁盘格式化

[root@localhost ~]# cat /etc/filesystems  //查看分区支持的文件系统格式

ext4

ext3

ext2

nodev proc

nodev devpts

iso9660

vfat

hfs

hfsplus

 

[root@localhost ~]# mount //查看分区的文件系统是什么(挂载之后才能看到)

/dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota

/dev/sda1 on /boot type xfs

 

mke2fs

-t 表示你要格式化成什么系统()

-b 指定块大小

-m 预留空间给root

-i  多少字节对应一个inode

 

mkfs.ext4=====mke2fs -t ext4

 

[root@localhost ~]# mke2fs -t xfs -b 2048 /dev/sdb1 //还不支持xfs系统

mke2fs 1.42.9 (28-Dec-2013)

 

Your mke2fs.conf file does not define the xfs filesystem type.

Aborting...

 

[root@localhost ~]# mke2fs -t ext4 -b 2048 /dev/sdb1 //格式化成ext4文件系统 每块2k

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=2048 (log=1)

分块大小=2048 (log=1)

Stride=0 blocks, Stripe width=0 blocks

196608 inodes, 1572864 blocks

78643 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=270008320

96 block groups

16384 blocks per group, 16384 fragments per group

2048 inodes per group

Superblock backups stored on blocks:

16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104

 

Allocating group tables: 完成                            

正在写入inode: 完成                            

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

 

[root@localhost ~]# mkfs.ext4 -b 2048 /dev/sdb1 //当系统存档的是比较大的文件、视频、音乐可以使用大点8kb

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=2048 (log=1)

分块大小=2048 (log=1)

Stride=0 blocks, Stripe width=0 blocks

196608 inodes, 1572864 blocks

78643 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=270008320

96 block groups

16384 blocks per group, 16384 fragments per group

2048 inodes per group

Superblock backups stored on blocks:

16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104

 

Allocating group tables: 完成                            

正在写入inode: 完成                            

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

 

[root@localhost ~]# mkfs.xfs /dev/sdb1 //

mkfs.xfs: /dev/sdb1 appears to contain an existing filesystem (ext4).

mkfs.xfs: Use the -f option to force overwrite.

 

[root@localhost ~]# mkfs.xfs -f /dev/sdb1  //强制覆盖(前面已经格式化过了)

meta-data=/dev/sdb1              isize=256    agcount=4, agsize=196608 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=786432, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

 

 

[root@localhost ~]# blkid /dev/sdb1  //查看一个未挂载的分区文件系统(UUID)

/dev/sdb1: UUID="ac545dff-22fb-4fd6-8f76-d238fc6c1b72" TYPE="xfs"

 

[root@localhost ~]# mke2fs -t ext4 -b 2046 -m 1 /dev/sdb1  ///===mkfs.ext4 -m 1

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=1024 (log=0)

分块大小=1024 (log=0)

Stride=0 blocks, Stripe width=0 blocks

196608 inodes, 3145728 blocks

31457 blocks (1.00%) reserved for the super user

 

[root@localhost ~]# mke2fs -t ext4 -i 8192 -m 1 /dev/sdb1  //多少字节对应一个inode

mke2fs 1.42.9 (28-Dec-2013)

文件系统标签=

OS type: Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

393216 inodes, 786432 blocks  //2块对应一个inode  1:2

7864 blocks (1.00%) reserved for the super user

第一个数据块=0

 

没有分区也可以直接格式化

4.7 磁盘挂载

[root@localhost ~]# fdisk -l

 

[root@localhost ~]# blkid /dev/sdb1

/dev/sdb1: UUID="46ff014e-bb84-4d45-8c1f-a578e41cdea7" TYPE="ext4"

 

[root@localhost ~]# mount UUID="46ff014e-bb84-4d45-8c1f-a578e41cdea7" /mnt

[root@localhost ~]# mount /dev/sdb1 /mnt/  //挂载

[root@localhost ~]# df -h

文件系统        容量  已用  可用 已用% 挂载点

/dev/sda3        11G  916M  9.8G    9% /

devtmpfs        260M     0  260M    0% /dev

tmpfs           265M     0  265M    0% /dev/shm

tmpfs           265M  4.4M  261M    2% /run

tmpfs           265M     0  265M    0% /sys/fs/cgroup

/dev/sda1       197M   75M  123M   38% /boot

/dev/sdb1       2.9G  9.0M  2.8G    1% /mnt

 

[root@localhost ~]# mount

/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)

/dev/sdb1 on /mnt type ext4 (rw,relatime,data=ordered)

 

[root@localhost mnt]# umount -l /dev/sdb1  //懒人卸载

 

Mount常用选项:不加选项默认defaults

Use  default  options: rw, suid, dev, exec, auto, nouser,and async.    

Rw:可读写、

Suid:可设置uid权限、      

Dev:省略

Exec:可执行权限

Auto:自动挂载

Nouser:不允许普通用户挂载

Async:不会实时同步

 

[root@localhost ~]# vi /etc/fstab //设置之后开机自动挂载

# /etc/fstab

# Created by anaconda on Sun Oct 15 14:36:08 2017

#

# 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

#//第五列是否备份 0不备份 1备份   第六列设置自检 0不检测 1/2检测12优先级高些,1检测完在检测2

UUID=c54d7936-0b37-40bc-980f-7a4469bbe822 /                       xfs     defaults        1 1

UUID=540025a9-8958-498f-98d6-35ac2a63b730 /boot                   xfs     defaults        1 2

UUID=ca3fdb3f-6a65-4a04-ba4f-7e4c35c724c3 swap                    swap    defaults        0 0

/dev/sdb1                                 /mnt                    ext4    defaults        

 

[root@localhost ~]# man fstab

 

4.9 手动增加swap空间

dd操作磁盘的命令 if指定从哪里读 /dev/zero造零器  of将这些零写入到哪里去 count执行多少次

[root@localhost ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=100

记录了100+0 的读入

记录了100+0 的写出

104857600字节(105 MB)已复制,5.9509 秒,17.6 MB/

[root@localhost ~]# du -sh /tmp/newdisk

100M/tmp/newdisk

[root@localhost ~]# mkswap -f /tmp/newdisk //格式化

正在设置交换空间版本 1,大小 = 102396 KiB

无标签,UUID=01555cf3-52eb-4aaf-afb4-5b5a0b88fcd9

[root@localhost ~]# free -m

             total       used       free     shared    buffers     cached

Mem:           529        306        223          4          0        173

-/+ buffers/cache:        131        397

Swap:         1199          0       1199

[root@localhost ~]# swapon /tmp/newdisk //挂载

[root@localhost ~]# free -m

             total       used       free     shared    buffers     cached

Mem:           529        306        223          4          0        173

-/+ buffers/cache:        131        397

Swap:         1299          0       1299

[root@localhost ~]# chmod 0600 /tmp/newdisk

 

[root@localhost ~]# swapoff /tmp/newdisk  //卸载

[root@localhost ~]# free -m

             total       used       free     shared    buffers     cached

Mem:           529        306        223          4          0        173

-/+ buffers/cache:        131        397

Swap:         1199          0       1199


本文出自 “帕多克的痴迷” 博客,请务必保留此出处http://lsxme.blog.51cto.com/12400127/1978645

格式化、挂载、手动增加swap

标签:格式化 挂载 swap

原文地址:http://lsxme.blog.51cto.com/12400127/1978645

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!