Linux磁盘分区介绍
2017-04-22 10:24
351 查看
查看磁盘使用情况
[root@VM_176_224_centos ~]# fdisk -l #查看磁盘使用情况 Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x0005fc9a Device Boot Start End Blocks Id System /dev/vda1 * 2048 41943039 20970496 83 Linux Disk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 sectors 看到有一个/dev/vdb磁盘 Units = sectors of 1 * 512 = 512 bytes 是没有使用的 Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes [root@VM_176_224_centos ~]# fdisk /dev/vdb 对/dev/vdb划分分区 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 1表示这是第一个分区 First sector (2048-167772159, default 2048): 起始大小,默认 Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-167772159, default 167772159): +20G Partition 1 of type Linux and of size 20 GiB is set 创建20G的一个分区 Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): 2 表示这是第二个分区 First sector (41945088-167772159, default 41945088): Using default value 41945088 Last sector, +sectors or +size{K,M,G} (41945088-167772159, default 167772159): 这里默认回车Using default value 167772159 表示所有的空间全分出去 Partition 2 of type Linux and of size 60 GiB is set Command (m for help): w 把所做的修改保存 [root@VM_176_224_centos ~]# fdisk -l 查看自己是否创建了两个分区 Disk /dev/vdb: 85.9 GB, 85899345920 bytes, 167772160 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: 0x67b29857 Device Boot Start End Blocks Id System /dev/vdb1 2048 41945087 20971520 83 Linux /dev/vdb2 41945088 167772159 62913536 83 Linux
格式化磁盘
[root@VM_176_224_centos ~]# mkfs.ext4 /dev/vdb1 对分区/dev/vdb1格式化成ext4 [root@VM_176_224_centos ~]# mkfs.ext4 /dev/vdb2
挂载磁盘到指定目录
[root@VM_176_224_centos ~]# mount /dev/vdb1 /data 把分区/dev/vdb1挂在到/data下 [root@VM_176_224_centos ~]# mkdir /root/software [root@VM_176_224_centos ~]# mount /dev/vdb2 /root/software [root@VM_176_224_centos ~]# unmount /root/software;//卸载/root/software挂载目录
查看是否挂载成功
[root@VM_176_224_centos ~]# df -h 查看是否挂在成功 Filesystem Size Used Avail Use% Mounted on /dev/vdb1 20G 45M 19G 1% /data /dev/vdb2 59G 53M 56G 1% /root/software
设置开机自动挂载
[root@VM_176_224_centos ~]# vim /etc/fstab 设置开机自动挂载 /dev/vdb1 /data ext4 defaults 0 0 /dev/vdb2 /root/software ext4 defaults 0 0
创建swap分区步骤
1. free -m (目前没有swap分区)[root@_224_centos ~]# free total used free shared buffers cached Mem: 16332028 6526084 9805944 176 302608 1812816 -/+ buffers/cache: 4410660 11921368 Swap: 0 0 0
2.dd if=/dev/zero of=./swap bs=1M count=10000
在当前目录创建1个10G的swap文件
[root@VM_30_103_centos ~]# dd if=/dev/zero of=./swap bs=1M count=10000 记录了1024+0 的读入 记录了1024+0 的写出 524288字节(524 kB)已复制,0.00233599 秒,224 MB/秒
3.mkswap ./swap (创建交换区)
[root@VM_30_103_centos /]# mkswap -f /swap Setting up swapspace version 1, size = 508 KiB no label, UUID=f6d806e4-ffd4-4c20-bd81-bf0b7194b38d
4.swapon ./swap(启用swap)
swapon ./swap
5.free -m (再次查看内存,这时多了1个10G的swap分区)
[root@VM_30_103_centos /]# free -m total used free shared buffers cached Mem: 32108 23582 8525 30 499 16842 -/+ buffers/cache: 6240 25867 Swap: 9999 0 9999
6.vim /etc/fstab (开机启动自动加载)
/dev/vda1 / ext3 noatime,acl,user_xattr 1 1 proc /proc proc defaults 0 0 sysfs /sys sysfs noauto 0 0 debugfs /sys/kernel/debug debugfs noauto 0 0 devpts /dev/pts devpts mode=0620,gid=5 0 0 /dev/vdb1 /root/data ext4 defaults 0 0 UUID=e7caca55-82c7-4600-a89e-07a475bc45c4 swap swap defaults 0 0
swap常用命令介绍
cat /proc/sys/vm/swappiness;查看swap配置使用多大比例内存之后开始使用swap swapon -s ;swap当前使用情况 cat /proc/swaps;swap当前使用情况 swapon ./swap;启用swap分区 swapoff /swap;删除swap分区http://blog.csdn.net/tianlesoftware/article/details/8741873
相关文章推荐
- linux磁盘分区与系统目录介绍
- Linux磁盘分区介绍
- 开源软件授权方式介绍
- LDAP介绍(三)
- 剧情介绍:“美丽心灵”
- cpp类库介绍
- Linux 查看磁盘分区、文件系统、使用情况的命令和相关工具介绍
- QQ桌球瞄准器开发(1)桌球瞄准器介绍与使用方法
- 数字证书常见格式与协议介绍
- GCD介绍(四): 完结
- IOS编程教程:回到基础,介绍面向对象编程
- Intent-filter的介绍
- 今天同事给介绍了一个LINQ的工具,LINQPad
- java中Executor、ExecutorService、ThreadPoolExecutor介绍
- Android四大基本组件介绍与生命周期
- Gentoo/Funtoo USE标记介绍
- FineReport图表综合介绍
- Swift中的指针操作和使用详细介绍
- php exit、return、break、continue之间的差别,具体介绍
- 性能分析工具gprof介绍