文章目錄
- 實驗目標
- 實驗步驟
實驗目標
- 掛載一塊10G的硬盤
- 將硬盤分成1個3G的主分區、1個1G的swap分區和1個1G的擴展分區
- 將其中一個主分區和擴展分區分別格式化為ext4,並進行掛載
- 實現開機自動掛載
實驗步驟:
1、虛擬機添加硬盤
2、重啟服務器,並輸入lsblk查看服務器上的磁盤信息
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ... sdb 8:16 0 10G 0 disk sr0 11:0 1 1024M 0 rom
3、分區
fdisk /dev/sdb #對目標分區設備文件進行分區
[root@localhost nginx]# fdisk /dev/sdb 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 #新增一個3G的主分區 Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): 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): +3G Partition 1 of type Linux and of size 3 GiB is set Command (m for help): n #新增一個1G的swap分區 Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): p Partition number (2-4, default 2): First sector (6293504-20971519, default 6293504): Using default value 6293504 Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519): +1G Partition 2 of type Linux and of size 1 GiB is set Command (m for help): t #改變分區ID為82 Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to 'Linux swap / Solaris' Command (m for help): n #將剩余空間都給擴展分區 Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): e Partition number (3,4, default 3): First sector (8390656-20971519, default 8390656): Using default value 8390656 Last sector, +sectors or +size{K,M,G} (8390656-20971519, default 20971519): Using default value 20971519 Partition 3 of type Extended and of size 6 GiB is set Command (m for help): n #新增一個1G大小的邏輯分區 Partition type: p primary (2 primary, 1 extended, 1 free) l logical (numbered from 5) Select (default p): l Adding logical partition 5 First sector (8392704-20971519, default 8392704): Using default value 8392704 Last sector, +sectors or +size{K,M,G} (8392704-20971519, default 20971519): +1G #設置大小 Partition 5 of type Linux and of size 1 GiB is set Command (m for help): p Disk /dev/sdb: 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: 0xede96e76 Device Boot Start End Blocks Id System /dev/sdb1 2048 6293503 3145728 83 Linux /dev/sdb2 6293504 8390655 1048576 82 Linux swap / Solaris /dev/sdb3 8390656 20971519 6290432 5 Extended /dev/sdb5 8392704 10489855 1048576 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
4、格式化
# mkfs -t ext4 /dev/sdb1 #對主分區1以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 196608 inodes, 786432 blocks 39321 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=805306368 24 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
mkswap /dev/sdb2 #將分區格式化為swap分區
mkswap: /dev/sdb2: warning: don't erase bootbits sectors (dos partition table detected). Use -f to force. Setting up swapspace version 1, size = 1048572 KiB no label, UUID=6b5eee00-73a6-4d10-bc33-bfab0d6911b2
mkfs -t ext4 /dev/sdb5 #對邏輯分區進行格式化操作
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 65536 inodes, 262144 blocks 13107 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376 Allocating group tables: done Writing inode tables: done Creating journal (8192 blocks): done Writing superblocks and filesystem accounting information: done
5、使用分區【掛載】
- 臨時掛載
mount /dev/sdb1 /share_test/ #臨時掛載主分區
mount -o rw /dev/sdb5 /logical_test/ #以讀寫的方式掛載邏輯分區
swapon /dev/sdb2 #啟動新的swap分區
- 自動掛載
- 修改/etc/fstab文件,添加如下內容
/dev/sdb1 /share_test ext4 defaults 0 0 /devsdb5 /logical_test ext4 defaults 0 0 /dev/sdb2 swap swap defaults 0 0
2.使用mount -a命令自動掛載/etc/fstab中未掛載選項
mount -a #此命令會自動掛載/etc/fstab中未掛載項
6、停止掛載
[root@localhost nginx]# umount /dev/sdb1 #停止掛載/dev/sdb1 [root@localhost nginx]# umount /dev/sdb5 #停止掛載/dev/sdb5 [root@localhost nginx]# swapoff /dev/sdb2 #停止使用此swap分區
【注意】最后還需要把/etc/fstab中停止掛載的內容清除
