管理系統中的簡單分區和檔案系統
一.簡單分區和檔案系統
存儲是每個計算機系統的基本需求。 Red Hat EnterpriseLinux 提供了一些強大的工具 , 它們能在 大量的場景中管理多種類型的儲存設備
disk 是用于管理磁盤分區的實用程式。您可以通過選擇 -l選項和指定磁盤名稱 ( fdisk -cul/dev/vda) 運作該實用程式 , 以檢視磁盤及其分區。您可以通過互動式地運作該實用程式 , 并選擇相應的菜 單選項 ( fdisk -cu /dev/vda ) 進行更改。 -c 禁用舊的 DOS 相容模式 , -u 以扇區 ( 而不是柱 面已經過時 ) 的格式顯示輸出
二.檢視系統裝置資訊
fdisk -l
– 顯示系統中所有可以使用的裝置資訊
blkid
– 顯示系統正在使用的裝置 id
三.建立新分區
1.建立新分區
[root@localhost ~]# fdisk /dev/vdb ###建立分區指令
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.
Command (m for help): n ###m檢視幫助 n建立分區
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): ###p主邏輯卷 e擴充分區
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048): ###起始點
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M ##大小
Partition 1 of type Linux and of size 500 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: 0x4a3c53fa
Device Boot Start End Blocks Id System
/dev/vdb1 2048 1026047 512000 83 Linux
Command (m for help): wq ###儲存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# partprobe ###同步分區表
[root@localhost ~]# mkfs.xfs /dev/vdb1 ###格式化建立分區為xfs檔案系統
meta-data=/dev/vdb1 isize=256 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=128000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
<a href="https://s3.51cto.com/wyfs02/M01/92/39/wKiom1j9flfwBMXlAAzF66GbVbE360.png-wh_500x0-wm_3-wmp_4-s_1898241885.png" target="_blank"></a>
<a href="https://s1.51cto.com/wyfs02/M01/92/38/wKioL1j9fl-CH-LDAAzfjLtqm1s553.png-wh_500x0-wm_3-wmp_4-s_3422160208.png" target="_blank"></a>
2.挂載分區
<a href="https://s3.51cto.com/wyfs02/M00/92/38/wKioL1j9f7SAHv7YAAxQMcuB4sY287.png-wh_500x0-wm_3-wmp_4-s_2919595054.png" target="_blank"></a>
自動挂載
編輯配置檔案 /etc/fstab
<a href="https://s5.51cto.com/wyfs02/M01/92/3A/wKiom1j9guDRRt17AAxM3dZxm48638.png-wh_500x0-wm_3-wmp_4-s_2940868821.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M01/92/39/wKioL1j9gueCX0NfAAxA9HjtIi8717.png-wh_500x0-wm_3-wmp_4-s_1569924764.png" target="_blank"></a>
3.删除分區
解除安裝分區
umount /mnt
<a href="https://s2.51cto.com/wyfs02/M00/92/3A/wKiom1j9g63C981VAAy1PIO-OjU391.png-wh_500x0-wm_3-wmp_4-s_2962510688.png" target="_blank"></a>
删除分區
配置檔案/etc/fstab
[root@localhost ~]# fdisk /dev/vdb
Command (m for help): d
Selected partition 1
Partition 1 is deleted
Command (m for help): p
Command (m for help): wq
[root@localhost ~]# partprobe
<a href="https://s3.51cto.com/wyfs02/M00/92/39/wKioL1j9hFHiYNy1AAyc2iJb3g0139.png-wh_500x0-wm_3-wmp_4-s_3604827175.png" target="_blank"></a>
四.swap分區的管理
[root@localhost ~]# fdisk /dev/vdb
Command (m for help): n
Select (default p):
First sector (2048-20971519, default 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
p primary (1 primary, 0 extended, 3 free)
Partition number (2-4, default 2):
First sector (206848-20971519, default 206848):
Using default value 206848
Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M
Partition 2 of type Linux and of size 100 MiB is set
Command (m for help): t ###修改分區功能标簽
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): l ###列出所有分區功能标簽
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): t
Partition number (1,2, default 2):
/dev/vdb1 2048 206847 102400 82 Linux swap / Solaris
/dev/vdb2 206848 411647 102400 82 Linux swap / Solaris
<a href="https://s3.51cto.com/wyfs02/M00/92/3A/wKioL1j9jFXBBzMSAAzT1c6EYJg164.png-wh_500x0-wm_3-wmp_4-s_1929703630.png" target="_blank"></a>
格式化swap分區
mkswap /dev/vdb{1..2}
<a href="https://s3.51cto.com/wyfs02/M00/92/3B/wKiom1j9jTmRqiEtAAy9TNBz2Ds956.png-wh_500x0-wm_3-wmp_4-s_702842807.png" target="_blank"></a>
挂載swap分區
swapon -a /etc/vdb* ###激活swap分區
wapon -s ###檢視swap分區狀态
<a href="https://s5.51cto.com/wyfs02/M01/92/3B/wKiom1j9jdOyl0u7AAxJtVF6yTw966.png-wh_500x0-wm_3-wmp_4-s_2302937825.png" target="_blank"></a>
開機自動激活
配置/etc/fstab
<a href="https://s2.51cto.com/wyfs02/M02/92/3B/wKiom1j9jy3Bshn8AAxzwEuNyvs829.png-wh_500x0-wm_3-wmp_4-s_2749862788.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M01/92/3A/wKioL1j9jzSR79qiAAww1NQfCeY281.png-wh_500x0-wm_3-wmp_4-s_2426235121.png" target="_blank"></a>
優先級priority設定
1激活時加入參數-p num
swapon -a /dev/vdb1 -p num
2配置fstab
<a href="https://s1.51cto.com/wyfs02/M00/92/3B/wKiom1j9kLiwhh8eAAxl6N0tzWs452.png-wh_500x0-wm_3-wmp_4-s_3678054273.png" target="_blank"></a>
五.分區配額
分區并格式化
<a href="https://s1.51cto.com/wyfs02/M02/92/47/wKiom1j92SCRSNKYABJCeqkqw5o402.png-wh_500x0-wm_3-wmp_4-s_664601158.png" target="_blank"></a>
挂載并開啟quota
[root@localhost westos]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ###挂載時開啟quota
[root@localhost westos]# df -h ###檢視挂載狀态
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.1G 7.0G 31% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 80K 921M 1% /dev/shm
tmpfs 921M 21M 901M 3% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/vdb1 1014M 33M 982M 4% /pub
<a href="https://s2.51cto.com/wyfs02/M02/92/47/wKiom1j92X6hh8ryABKQez578Jo024.png-wh_500x0-wm_3-wmp_4-s_1192718360.png" target="_blank"></a>
設定使用者westos的限制
edquota -u westos
<a href="https://s2.51cto.com/wyfs02/M00/92/46/wKioL1j92eKwQBuYABLgqv90tTU789.png-wh_500x0-wm_3-wmp_4-s_2289315494.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M01/92/47/wKiom1j92e7xM5lOABHSbgFwG5M639.png-wh_500x0-wm_3-wmp_4-s_113370908.png" target="_blank"></a>
測試westos可使用的空間
[root@localhost westos]# su westos ###切換使用者
[westos@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=10000###截取1G到/pub
dd: error writing ‘/pub/file’: Disk quota exceeded
201+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 0.077746 s, 2.7 GB/s
[westos@localhost ~]$ du -sh /pub/ ###檢視/pub下檔案大小
200M /pub/
<a href="https://s2.51cto.com/wyfs02/M00/92/47/wKioL1j92vGSpf8hABIa4CCYajY297.png-wh_500x0-wm_3-wmp_4-s_433813224.png" target="_blank"></a>
六.磁盤陣列
建立raid功能的三個分區
[root@localhost westos]# fdisk /dev/vdb
No partition is defined yet!
[root@localhost westos]# partprobe
[root@localhost westos]# clear
[3;J
p primary (2 primary, 0 extended, 2 free)
Partition number (3,4, default 3):
First sector (411648-20971519, default 411648):
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +100M
Partition 3 of type Linux and of size 100 MiB is set
Partition number (1-3, default 3): 1
Hex code (type L to list all codes): l
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Partition number (1-3, default 3): 2
Partition number (1-3, default 3): 3
/dev/vdb1 2048 206847 102400 fd Linux raid autodetect
/dev/vdb2 206848 411647 102400 fd Linux raid autodetect
/dev/vdb3 411648 616447 102400 fd Linux raid autodetect
<a href="https://s4.51cto.com/wyfs02/M00/92/48/wKiom1j93Vnxe8UAABLZyFL7Ccc951.png-wh_500x0-wm_3-wmp_4-s_3903823083.png" target="_blank"></a>
建立raid分區
mdadm -C /dev/md0 -l 1 -n 2 -x 1 /dev/vdb{1..3}
<a href="https://s4.51cto.com/wyfs02/M01/92/47/wKioL1j931_ScJYXAA6IAHkp37s037.png-wh_500x0-wm_3-wmp_4-s_1417229621.png" target="_blank"></a>
<a href="https://s2.51cto.com/wyfs02/M02/92/48/wKiom1j932jQPFGcAA8bZ49L68E118.png-wh_500x0-wm_3-wmp_4-s_827810119.png" target="_blank"></a>
mdadm -D /dev/md0 ##裝置配置資訊
mdadm /dev/md0 -f /dev/vdb1 ##損壞裝置1
mdadm /dev/md0 -r /dev/vdb1 ##移除裝置1
mdadm /dev/md0 -a /dev/vdb1 ##恢複裝置1
mdadm -S /dev/md0 ##停止裝置
七.分區加密
[root@desktop ~]# cryptsetup luksFormat /dev/vdb1
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES ###是否加密
Enter passphrase: ###請輸入密碼
Verify passphrase: ###确認密碼
<a href="https://s3.51cto.com/wyfs02/M02/92/48/wKiom1j95ZWghueEABItgQKfNB8223.png-wh_500x0-wm_3-wmp_4-s_789412472.png" target="_blank"></a>
裝置解密
[root@desktop ~]# cryptsetup open /dev/vdb1 disk ###打開加密裝置
Enter passphrase for /dev/vdb1:
[root@desktop ~]# mkfs.xfs /dev/mapper/disk -f ###格式化裝置
meta-data=/dev/mapper/disk isize=256 agcount=4, agsize=6272 blks
data = bsize=4096 blocks=25088, imaxpct=25
[root@desktop ~]# mount /dev/mapper/disk /mnt/ ###挂載裝置
[root@desktop ~]# umount /mnt/ ###解除安裝裝置
[root@desktop ~]# cryptsetup close disk ###關閉裝置加密層
<a href="https://s5.51cto.com/wyfs02/M02/92/49/wKiom1j96HTikzE4ABNGmLCvIHo577.png-wh_500x0-wm_3-wmp_4-s_410858045.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M00/92/49/wKiom1j96IGhzESWABNMKpE07dQ190.png-wh_500x0-wm_3-wmp_4-s_4046056798.png" target="_blank"></a>
自動挂載加密裝置
設定開機解密
vim /etc/cryptab
<a href="https://s3.51cto.com/wyfs02/M00/92/49/wKiom1j96nyCDBqEABKOt6NHLuo576.png-wh_500x0-wm_3-wmp_4-s_2148897168.png" target="_blank"></a>
<a href="https://s4.51cto.com/wyfs02/M02/92/48/wKioL1j96t-i5BvdABLgD-hB8yE716.png-wh_500x0-wm_3-wmp_4-s_2976815359.png" target="_blank"></a>
寫密碼檔案
vim /root/passwd
<a href="https://s5.51cto.com/wyfs02/M00/92/49/wKiom1j96x_BbzlRABKAwwtZehU021.png-wh_500x0-wm_3-wmp_4-s_892889267.png" target="_blank"></a>
配置解密密碼
cryptsetup luksAddKey /dev/vdb1 /root/passwd
<a href="https://s2.51cto.com/wyfs02/M01/92/49/wKiom1j968yCNQKiABKQtuHDvxU932.png-wh_500x0-wm_3-wmp_4-s_593670479.png" target="_blank"></a>
本文轉自Super_MONKEY 51CTO部落格,原文連結:http://blog.51cto.com/supermk/1918981