fdisk 磁盘分区

fdisk磁盘分区

fdisk适用于小于2T的硬盘

parted适用于大于2T的硬盘

n   创建分区 add a new partition

d    删除分区 delete a partition
p  显示分区的信息  print the partition table
q  退出不保存  quit without saving changes
w  退出并保存  write table to disk and exit

测试:

100M

30M的主分区  30M的逻辑分区

给/dev/sdb硬盘只创建一个分区,把他挂载到/mnt 上面

Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-208895, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895):
Using default value 208895
Partition 1 of type Linux and of size 101 MiB is set

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes, 208896 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: 0xfe0725f2

Device Boot Start End Blocks Id System
/dev/sdb1 2048 208895 103424 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

##通知系统·/dev/sdb硬盘的磁盘分区变化了

partprobe /dev/sdb
[root@docker ~]# mkfs.ext4 /dev/sdb1
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
25896 inodes, 103424 blocks
5171 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1992 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

##关闭磁盘的自动检测功能

tune2fs -c 0 -i 0 /dev/sdb1

#-c 0  关闭每挂载多少次进行磁盘检测功能 (count)

#-i     0  关闭每隔180天进行磁盘检查功能  (inlerval)

##格式化创建文件系统

mkfs.ext4 /dev/sdb1

##进行磁盘分区挂载

mount /dev/sdb1   /mnt

#进行永久挂载(开机自动挂载)

方法1:

将mount  /dev/sdb1    /mnt 放到 /etc/rc.local

方法2:

在/etc/fstab添加挂载内容

###partcd

print    显示磁盘分区表信息

mklabel   创建磁盘分区表

GPT(支持zb级别)

msdos(mbr)

mkpart  创建分区

rm    删除分区

q     退出

创建 30M     30M

(parted) mkpart primary 0 30
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel?
Ignore/Cancel? I

(parted) P
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 107MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number Start End Size File system Name Flags
1 17.4kB 30.0MB 30.0MB primary

###企业案例:java环境内存不够导致swap

创建一个文件让文件(文件块)成为swap

dd if=/dev/zero of=/tmp/100m bs=1M  count=100

 [root@docker ~]# file /tmp/100m

/tmp/100m: data

##变成swap

mkswap  /tmp/100m

[root@docker ~]# mkswap /tmp/100m
Setting up swapspace version 1, size = 102396 KiB
no label, UUID=07da83d5-d706-473c-beac-c6b2efeadfd2
[root@docker ~]# file /tmp/100m
/tmp/100m: Linux/i386 swap file (new style), version 1 (4K pages), size 25599 pages, no label, UUID=07da83d5-d706-473c-beac-c6b2efeadfd2

##3.swap生效

[root@docker ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 2.2G 571M 49M 904M 1.1G
Swap: 2.0G 520K 2.0G
[root@docker ~]# swapon /tmp/100m
swapon: /tmp/100m: insecure permissions 0644, 0600 suggested.
[root@docker ~]# free -h
total used free shared buff/cache available
Mem: 3.7G 2.2G 610M 49M 905M 1.1G
Swap: 2.1G 520K 2.1G

##4.swap永久生效

方法1

将swapon   /tmp/100m放在/etc/rc.local

方法2

编辑/etc/fstab

/tmp/100m  swap    swap    defaults  0  0

##Linux特点会把使用过的命令和数据零时存放在内存中 cache和butter 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值