20180926 磁盤格式化、磁盤掛載、增長swap空間

磁盤格式化

查看當前操做系統支持的文件系統格式 :node

[root@centos01 ~]# cat /etc/filesystems 
ext4
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus

磁盤格式化centos

# mkfs.ext4 等價於 mke2fs -t ext4
[root@centos01 ~]# mke2fs -t xfs -b 2048 /dev/sdb1  
mke2fs 1.42.9 (28-Dec-2013)

Your mke2fs.conf file does not define the xfs filesystem type.
Aborting...
# 使用mke2fs格式化爲xfs不行,能夠換爲mkfs.xfs命令

[root@centos01 ~]# mkfs.xfs  /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=524288, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@centos01 ~]# blkid /dev/sdb1  # 查看未掛載的分區的文件系統類型
/dev/sdb1: UUID="ae4a7961-3080-4625-bf79-f9d422aaa147" TYPE="xfs"

[root@centos01 ~]# mke2fs -t ext4 /dev/sdb1 # 格式化爲ext4文件類型
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

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

[root@centos01 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="aeeab36c-5a73-4942-b7ae-a466934c649c" TYPE="ext4"

[root@centos01 ~]# mke2fs -b 8192 /dev/sdb1 # -b 設置塊大小
Warning: blocksize 8192 not usable on most systems.
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: 8192-byte blocks too big for system (max 4096)
Proceed anyway? (y,n) n
# 超過系統最大塊大小時會提示 

[root@centos01 ~]# mke2fs -m 4 /dev/sdb1 # -m 設置root用戶的block百分比
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072 inodes, 524288 blocks
20971 blocks (4.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

# -i 多少字節對應一個inode,最小是一個塊大小
[root@centos01 ~]# mke2fs -i 8192 -t ext4 /dev/sdb1 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
262144 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

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

磁盤掛載

[root@centos01 ~]# mount /dev/sdb /mnt/  # 把/dev/sdb分區掛載到/mnt/目錄
[root@centos01 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        26G  862M   25G   4% /
devtmpfs        489M     0  489M   0% /dev
tmpfs           494M     0  494M   0% /dev/shm
tmpfs           494M  6.7M  487M   2% /run
tmpfs           494M     0  494M   0% /sys/fs/cgroup
/dev/sda1       197M   75M  123M  38% /boot
/dev/sdb        5.0G   33M  5.0G   1% /mnt

經過分區UUID掛載ide

[root@centos01 /]# blkid /dev/sdb
/dev/sdb: UUID="d259e6a3-dd14-4bab-91ac-3a5c54314782" TYPE="xfs"
[root@centos01 /]# cd
[root@centos01 ~]# mount UUID="d259e6a3-dd14-4bab-91ac-3a5c54314782" /mnt  .
[root@centos01 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        26G  862M   25G   4% /
devtmpfs        489M     0  489M   0% /dev
tmpfs           494M     0  494M   0% /dev/shm
tmpfs           494M  6.7M  487M   2% /run
tmpfs           494M     0  494M   0% /sys/fs/cgroup
/dev/sda1       197M   75M  123M  38% /boot
/dev/sdb        5.0G   33M  5.0G   1% /mnt

umount 掛載點或分區 # 卸載掛載 umount /mnt 或 umount /dev/sdbspa

[root@centos01 ~]# mount /dev/sdb /mnt
[root@centos01 ~]# cd /mnt/
[root@centos01 mnt]# ls
# 若是在/mnt裏,卸載時會有提示,此時要麼從/mnt目錄退出或者加-l
[root@centos01 mnt]# umount /dev/sdb
umount: /mnt: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@centos01 mnt]# cd ..
[root@centos01 /]# umount /dev/sdb

[root@centos01 mnt]# umount /dev/sdb
umount: /mnt: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@centos01 mnt]# umount /mnt/
umount: /mnt: target is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@centos01 mnt]# umount -l /dev/sdb

/etc/fstab 配置文件配置系統啓動時須要掛載的各個分區操作系統

第1列是分區的標識,能夠寫分區的LABEL、分區的UUID、分區名(/dev/sda1)
第2列是掛載點
第3列是分區格式
第4列是mount的一些掛載參數
第5列表示是否被dump備份。1表示備份,0表示不備份 第6列表示開機時是否自檢磁盤,1和2都表示檢測,0表示不檢測。自檢時,1比2優先級高,先檢測1,再檢測2code

手動增長swap

步驟爲: 創建swapfile → 格式化爲swap格式 →啓用該虛擬磁盤
創建swapfileorm

[root@centos01 ~]# dd if=/dev/zero of=/tmp/newdisk bs=1M count=128
128+0 records in
128+0 records out
134217728 bytes (134 MB) copied, 5.06216 s, 26.5 MB/s

格式化爲swap格式ip

[root@centos01 ~]# mkswap -f /tmp/newdisk
Setting up swapspace version 1, size = 131068 KiB
no label, UUID=abb8af33-f7d9-49bc-9ef9-87aa17fa4b7f
[root@centos01 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           987        373        613          6          0        212
-/+ buffers/cache:        160        827
Swap:         4095          0       4095

啓用與卸載ci

[root@centos01 ~]# swapon /tmp/newdisk # 啓用
swapon: /tmp/newdisk: insecure permissions 0644, 0600 suggested.
[root@centos01 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:           987        373        613          6          0        212
-/+ buffers/cache:        160        827
Swap:         4223          0       4223
[root@centos01 ~]# swapoff /tmp/newdisk # 卸載
相關文章
相關標籤/搜索