1.磁盤格式化node
格式化就是安裝文件系統。Centos 7以XFS做爲默認的文件系統,能夠給它指定ext3或者ext4格式。linux
命令mke2fs、mkfs.ext二、mkfs.ext三、mkfs.ext四、和mkfs.xfs。安全
mke2fs經常使用命令bash
-b:表示分區時設定每一個數據區塊佔用的空間大小。每一個數據塊支持1024B、2048B、4096B.app
-i:表示設定inode的大小。async
-N:表示設定inode的數量。ide
-c:表示在格式化以前先檢測一下磁盤對否有問題。ui
-L:表示預設該分區的標籤(label)this
-j:表示創建ext3格式的分區=mkfs.ext3。spa
-t:用來指定文件系統的類型。示例命令以下:
[root@aminglinux-128 ~]# mke2fs -t ext4 /dev/sdb5 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤= OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 64000 inodes, 256000 blocks 12800 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=262144000 8 block groups 32768 blocks per group, 32768 fragments per group 8000 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (4096 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
命令mke2fs -t ext4 /dev/sdb5等同於mkfs.ex4 /dev/sdb5。mke2fs並不支持把分區格式化成XFS類型,而只能使用mkfs.xfs,示例命令以下:
[root@aminglinux-128 ~]# mke2fs -t xfs /dev/sdb6 mke2fs 1.42.9 (28-Dec-2013) Your mke2fs.conf file does not define the xfs filesystem type. Aborting...
[root@aminglinux-128 ~]# mke2fs.xfs /dev/sdb6 bash: mke2fs.xfs: 未找到命令... [root@aminglinux-128 ~]# mkfs.xfs /dev/sdb6 meta-data=/dev/sdb6 isize=512 agcount=4, agsize=64000 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=256000, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=855, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
磁盤在格式化化的時候,會預先規定好每個塊的大小,而後再把空間分割成一個一個的小塊。存數據時的時候,也是一個塊一個塊地寫入。若是磁盤裏存儲的都是特別小的文件,在格式化磁盤時指定塊數值小一點。
[root@aminglinux-128 ~]# mkfs.xfs -b size=8192 /dev/sdb6 mkfs.xfs: /dev/sdb6 appears to contain an existing filesystem (xfs). mkfs.xfs: Use the -f option to force overwrite. [root@aminglinux-128 ~]# mkfs.xfs -f -b size=8192 /dev/sdb6 meta-data=/dev/sdb6 isize=512 agcount=4, agsize=32000 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=8192 blocks=128000, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=8192 ascii-ci=0 ftype=1 log =internal log bsize=8192 blocks=559, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=8192 blocks=0, rtextents=0
上面實驗能夠發現,若是指定塊大小爲8192B,會提示塊值設置得太大了,能夠直接輸入y強制格式化。mkfs.xfs用法有點特殊,須要注意和mke2fs區分。能夠給分區指定標籤,示例以下:
[root@aminglinux-128 ~]# mke2fs -L TEST -t ext4 /dev/sdb5 mke2fs 1.42.9 (28-Dec-2013) 文件系統標籤=TEST OS type: Linux 塊大小=4096 (log=2) 分塊大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 64000 inodes, 256000 blocks 12800 blocks (5.00%) reserved for the super user 第一個數據塊=0 Maximum filesystem blocks=262144000 8 block groups 32768 blocks per group, 32768 fragments per group 8000 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: 完成 正在寫入inode表: 完成 Creating journal (4096 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
上例中使用-L選項來指定標籤。除非有特殊需求,不然不須要指定塊大小。
2.命令e2label
該命令用於查看或修改分區的標籤,它只支持ext格式的文件系統,而不支持XFS文件系統。示例以下:
[root@aminglinux-128 ~]# e2label /dev/sdb5 TEST [root@aminglinux-128 ~]# e2label /dev/sdb5 TEST123 [root@aminglinux-128 ~]# e2label /dev/sdb5 TEST123
3.掛載/卸載磁盤
格式化後的磁盤是一個塊設備文件,類型爲b。
在掛載某個分區前,須要先創建一個掛載點,這個掛載點是以目錄的形式出現的。一旦把某個分區掛載到這個掛載點(目錄)下,要往這個目錄寫數據時,就會寫到改分區中。因此,在掛載該分區前,掛載點(目錄)下必須是個空目錄。
4.命令mount
[root@aminglinux-128 ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) devtmpfs on /dev type devtmpfs (rw,nosuid,size=483152k,nr_inodes=120788,mode=755) securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755) tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755) cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd) pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime) cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
這個命令,能夠查看當前系統已經掛載的全部分區、分區文件類型、掛載點及一些選項等信息。未掛載的分區使用blkid命令查看。示例以下:
[root@aminglinux-128 ~]# mkdir /newdir [root@aminglinux-128 ~]# touch /newdir/newfile.txt [root@aminglinux-128 ~]# ls /newdir/ newfile.txt [root@aminglinux-128 ~]# mouunt /dev/sdb5 /newdir/ bash: mouunt: 未找到命令... 類似命令是: 'mount' [root@aminglinux-128 ~]# ls /newdir/ newfile.txt [root@aminglinux-128 ~]# df -h |grep -v tmpfs 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 76G 3.6G 73G 5% / /dev/sda1 197M 111M 86M 57% /boot [root@aminglinux-128 ~]# umount /newdir/ umount: /newdir/:未掛載 [root@aminglinux-128 ~]# df -h |grep tmpfs devtmpfs 472M 0 472M 0% /dev tmpfs 488M 0 488M 0% /dev/shm tmpfs 488M 8.1M 480M 2% /run tmpfs 488M 0 488M 0% /sys/fs/cgroup tmpfs 98M 0 98M 0% /run/user/0
/etc/fstab 配置文件
[root@aminglinux-128 ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed May 23 19:32:00 2018 # # 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 # UUID=23c138ca-3a70-447e-9028-e002f1d0dea9 / xfs defaults 0 0 UUID=28947ea8-fda8-4882-8f92-e0e192c7106c /boot xfs defaults 0 0 UUID=2b7f5930-1da9-42bd-817e-c675a5fe16ec swap swap defaults 0 0
這個文件中顯示了系統啓動時須要掛載的各個分區。
第4列經常使用選項
async/sync:async表示與磁盤和內存不一樣步。sync則會時時同步內存和磁盤中的數據。
auto/noauto:表示開機自動掛載/不自動掛載。
default:表示按照大多數永久文件系統的默認值設置掛載定義。
ro:表示按只讀權限掛載。
rw:表示按可讀可寫權限掛載。
exec/noexec:表示容許/不容許可執行文件執行。
user/nouser:表示容許/不容許root外的其它用戶掛載分區。
suid/nosuid:表示容許/不容許分區有suid屬性。
usrquota:表示啓動用戶的磁盤配額模式。
grquota:表示羣組的磁盤配額模式。
mount -a 把/etc/fstab中出現的全部磁盤分區掛載上。
-t:用來指定掛載的分區類型,默認不指定,會自動識別。
-o:用來指定掛載的分區有哪些特性,即/etc/fstab配置文件中第4列那些。(經常使用)示例以下:
[root@aminglinux-128 ~]# mkdir /newdir/dir1 [root@aminglinux-128 ~]# mount -o remount,ro,sync /dev/sdb5 /newdir/ [root@aminglinux-128 ~]# mkdir /newdir/dir2 mkdir: 沒法建立目錄"/newdir/dir2": 只讀文件系統
-o指定了ro參數,該分區只讀了。mount 命令能夠看到,/dev/sdb5也有ro參數。示例以下:
[root@aminglinux-128 ~]# mount |grep sdb5 /dev/sdb5 on /newdir type ext4 (ro,relatime,sync,data=ordered)
從新掛載,恢復讀寫。
[root@aminglinux-128 ~]# mount |grep sdb5 /dev/sdb5 on /newdir type ext4 (ro,relatime,sync,data=ordered) [root@aminglinux-128 ~]# mount -o remount /newdir [root@aminglinux-128 ~]# mkdir /newdir/dir2 [root@aminglinux-128 ~]# ls /newdir/ dir1 dir2 lost+found
5.命令blkid
獲取各分區的UUID。
[root@aminglinux-128 ~]# blkid /dev/sda1: UUID="28947ea8-fda8-4882-8f92-e0e192c7106c" TYPE="xfs" /dev/sda2: UUID="2b7f5930-1da9-42bd-817e-c675a5fe16ec" TYPE="swap" /dev/sda3: UUID="23c138ca-3a70-447e-9028-e002f1d0dea9" TYPE="xfs" /dev/sdb5: LABEL="TEST123" UUID="48d2ff4a-3de2-4644-a8c4-7a3165d9891a" TYPE="ext4" /dev/sdb6: UUID="842793ba-b318-4b84-bed9-e77c793492e1" TYPE="xfs" /dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
指定查詢哪一個分區,示例以下:
[root@aminglinux-128 ~]# blkid /dev/sdb5 /dev/sdb5: LABEL="TEST123" UUID="48d2ff4a-3de2-4644-a8c4-7a3165d9891a" TYPE="ext4"
分區在開機後自動掛載的兩個方法:一是在/etc/fstab中添加一行。二是把掛載命令寫到/etc/ec.d/rc.local文件中去(直接放到這個文件的最後),系統啓動後會執行這個文件中的命令。
[root@aminglinux-128 ~]# cat /etc/rc.d/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot.
/usr/bin/mount UUID="48d2ff4a-3de2-4644-a8c4-7a3165d9891a" /newdir
寫入到該文件的命令,要使用絕對路徑。
打開執行權限。
chmod a+x /etc/rc.d/rc.local
6.命令umount
umount這個命令能夠跟掛載點,分區名(/dev/sdb1),不能夠跟LABEL和UUID。
7.手動增長swap空間
創建swapfile-格式化-swap格式-啓用該虛擬磁盤
[root@aminglinux-128 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=1024 記錄了1024+0 的讀入 記錄了1024+0 的寫出 1073741824字節(1.1 GB)已複製,50.6039 秒,21.2 MB/秒
of指定目標文件,bs定義塊大小,count定義塊的數量。
格式化swap格式,命令以下:
[root@aminglinux-128 ~]# mkswap -f /tmp/newdisk 正在設置交換空間版本 1,大小 = 1048572 KiB 無標籤,UUID=8472ee9a-9c0f-44a4-8263-bf5e72a8ea36
掛載使用
[root@aminglinux-128 ~]# mkswap -f /tmp/newdisk 正在設置交換空間版本 1,大小 = 1048572 KiB 無標籤,UUID=8472ee9a-9c0f-44a4-8263-bf5e72a8ea36 [root@aminglinux-128 ~]# free -m total used free shared buff/cache available Mem: 974 177 70 8 726 602 Swap: 4095 0 4095 [root@aminglinux-128 ~]# swapon /tmp/newdisk swapon: /tmp/newdisk:不安全的權限 0644,建議使用 0600。 [root@aminglinux-128 ~]# free -m total used free shared buff/cache available Mem: 974 178 69 8 726 602 Swap: 5119 0 5119 [root@aminglinux-128 ~]#
free -m:表示以M