linux系统硬盘分区

时间:2022-04-01 06:54:01

linux系统硬盘分区

linux分区最大支持16个分区


1.MBR 主引导分区    446字节   2.MPT 主分区表        64字节

3.分区大小为16字节,故有4个分区,其中3个主分区,1个扩展分区,扩展分区中成为逻辑分区

4.注意:MBR分区最大只能分2TB,可识别的分区总数为16,可用的为14.


 

1.分区划分

fdisk /dev/vdb

elcome 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.

 

 

Command (m for help): N 新建分区

   d   delete a partition           删除分区

   l   list known partition types      列出系统可用的分区类型

   n   add a new partition      新建分区

   p   print the partition table      显示分区

   q   quit without saving changes 推出

   t   change a partition's system id 修改分区功能id

   w   write table to disk and exit 保存更改到分区表中

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): 1      主分区id

First sector (2048-20971519, default 2048):     此分区起始位置

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M  分区大小

Partition 1 of type Linux and of size 100 MiB is set 

Command (m for help): p

 

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x193488c3

 

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048      206847      102400   83  Linux

 

Command (m for help): wq 保存推出,如果安q表示放弃更改退出

 

[root@localhost mnt]# partprobe 同步分区表

cat /proc/partitions 查看系统识别的分区信息

 

 

 mkfs.xfs  /dev/vdb1 格式化

mount /dev/vdb5  /mnt 临时挂载

 

vim /etc/fstab      永久挂载

devic mountpoint ftype defaults(mountpoint) 0 0

/dev/vdb1 /mnt xfs defaults 0 0

 mount -a          使/etc/fstab中记录的挂载策略生效

 

设定分区方式为gpt

 

[root@server0 ~] parted /dev/vdb

GNU Parted 3.1

Using /dev/vdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

(parted) mklabel                                                          

                                                               

(parted) quit                                                             

 

 

 

 

 

2.swap

1.fdisk /dev/vdb 分区

2.fdisk            中修改swap分区标识

gpt 14

doc 82

3.

mkswap /dev/vdbn

4.

swapon -a /dev/vdbn

5.

vim /etc/fstab

/dev/vdbn swap swap defaults,pri=1 0 0

6.

swapoff /dev/vdbn

 

 

3. 磁盘加密

 

fdisk  /dev/vdb

cryptsetup luksFormat /dev/vdb1

cryptsetup open /dev/vdb1 westos

mkfs.xfs  /dev/mapper/westos

mount /dev/mapper/westos  /mnt/

umount /mnt/

cryptsetup close westos

 

2.加密磁盘的永久挂载

vim /etc/crypttab

解密后设备管理文件 设备 加密字符存放文件

redhat /dev/vdb1 /root/lukspsfile

vim /root/lukspsfile

 

chmod 600 /root/lukspsfile

 cryptsetup luksAddKey /dev/vdb1  /root/lukspsfile

vim /etc/fstab

/dev/mapper/redhat /mnt xfs defaults 0 0

reboot

 

3.加密清除

vim /etc/fstab

> /etc/crypttab

rm -fr /root/lukspsfile

umount /mnt/

cryptsetup close redhat

mkfs.xfs  /dev/vdb1

 

4.磁盘阵列

fdisk  /dev/vdb

mdadm  -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}

mkfs.xfs  /dev/md0

mount /dev/md0  /mnt/

watch -n 1 cat /proc/mdstat

 

 

mdadm -f /dev/md0  /dev/vdb1

mdadm -D /dev/md0

mdadm -r /dev/md0  /dev/vdb1

mdadm -a /dev/md0 /dev/vdb1

umount /mnt/

mdadm  -S /dev/md0

 

5.配额

mount -o usrquota /dev/vdb1 /pub

quotaon -uv /dev/vdb1

edquota -u student

Disk quotas for user student (uid 1000):

  Filesystem                   blocks       soft       hard     inodes     soft     hard

  /dev/vdb1                    102400          0       40000       1        0        0

su - student

dd if=/dev/zero of=/pub/file bs=1M count=500

dd: error writing ‘/pub/file’: Disk quota exceeded

101+0 records in

100+0 records out

104857600 bytes (105 MB) copied, 0.0916726 s, 1.1 GB/s

 

quota

Disk quotas for user student (uid 1000):

     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace

      /dev/vdb1  102400*      0  102400               1       0       0