目標:將一個新硬盤能夠掛載到linux 系統上(開機自動掛載)
第一步:查看當前系統磁盤掛載
查看系統硬盤掛載情況: lsblk -f (老師不離開)
sda
├─sda1 ext4 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]
sda : 表示當前系統有一個物理磁盤 sda
sda1 :第一個物理硬盤的第一個分區
ext4:這個分區的格式(linux 常用的格式)
7cc94e03-8b1a-4845-97fb-49a2c39afd8c:表示這個分區的唯一標識(唯一ID)
/boot:表示這個分區掛在的目錄
[SWAP] :交換分區
交換分區:當有大量數據需要寫入內存,但內存不足時,剩餘的數據將寫入交換分區
交換分區的說明:在大數據集羣中安裝集羣之前將交換分區關閉掉。
fdisk -l
[root@node01 ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00040944
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris
第二部:爲虛擬機添加新的硬盤
在 vm 虛擬機,右鍵-》設置 -》 硬盤-》添加 -》下一步。。。。
重啓linux 系統
重新查看磁盤掛載情況
[root@node01 ~]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00040944
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 2637 20971520 83 Linux
/dev/sda3 2637 3681 8386560 83 Linux
/dev/sda4 3681 5222 12379136 5 Extended
/dev/sda5 3681 4700 8183808 83 Linux
/dev/sda6 4700 5222 4193280 82 Linux swap / Solaris
/dev/sdb:表示全新的硬件(沒有sdb1 sdb2,沒有分區沒有格式化)
第三步:對磁盤進行分區並格式化
查看新添加的分區
[root@node01 ~]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
對新磁盤進行分區
fdisk /dev/sdb
[root@node01 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x7a1242ed.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won’t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).
Command (m for help): m(幫助)(n : 添加一個分區,d : 刪除分區 w: 保存寫入)
Command (m for help): n(添加分區)
Command action
e extended
p primary partition (1-4)
p(設置分區的類型)
Partition number (1-4): 1(第一個分區)
First cylinder (1-1305, default 1): 1(第一個分區的起始位置)
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): 650(第一個分區的結束位置)
Command (m for help): n(添加分區)
Command action
e extended
p primary partition (1-4)
p(設置分區的類型)
Partition number (1-4): 2(第二個分區)
First cylinder (651-1305, default 651): (第二個分區的起始位置)
Using default value 651
Last cylinder, +cylinders or +size{K,M,G} (651-1305, default 1305): (第二個分區的結束位置)
Using default value 1305
Command (m for help): w(保存)
The partition table has been altered!
查看新分區
[root@node01 ~]# fdisk -l
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a1242ed
Device Boot Start End Blocks Id System
/dev/sdb1 1 650 5221093+ 83 Linux
/dev/sdb2 651 1305 5261287+ 83 Linux
對新分區進行格式化
mkfs -t ext4 /dev/sdb1
[root@node01 ~]# mkfs -t ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
文件系統標籤=
操作系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
326400 inodes, 1305273 blocks
65263 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=1337982976
40 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 38 mounts or
格式完畢後 磁盤會分配UUID
[root@node01 ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 10023089-17e3-4dbf-af6a-447b7e2011d2
└─sdb2
第四步:硬盤的掛載
前提:掛載的目錄必須已經存在
mkdir /mnt/disk3
mkdir /mnt/disk4
掛載磁盤方法1
mount /dev/sdb1 /mnt/disk3
mount /dev/sdb2 /mnt/disk4
取消掛載:umount /mnt/disk4
[root@node01 mnt]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sdb
├─sdb1 ext4 10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3
└─sdb2 ext4 21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4
sda
├─sda1 ext4 7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot
├─sda2 ext4 fe1d0eea-50ea-4d44-853b-1c39e5129021 /
├─sda3 ext4 df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1
├─sda4
├─sda5 ext4 ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2
└─sda6 swap f306ece0-a790-41d7-b685-63585b8534e4 [SWAP]
或者
[root@node01 mnt]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4
掛載磁盤方法2
開機自動掛載
修改/etc/fstab 文件,在文件中添加自動掛載配置
UUID=fe1d0eea-50ea-4d44-853b-1c39e5129021 / ext4 defaults 1 1
UUID=7cc94e03-8b1a-4845-97fb-49a2c39afd8c /boot ext4 defaults 1 2
UUID=df147f0a-efbd-4370-8e69-471b81a6ee7c /mnt/disk1 ext4 defaults 1 2
UUID=ea0d589d-a329-4bfc-a00b-11c00351765a /mnt/disk2 ext4 defaults 1 2
UUID=10023089-17e3-4dbf-af6a-447b7e2011d2 /mnt/disk3 ext4 defaults 1 2
UUID=21d817f4-a13d-42dd-992b-591bc8ea1994 /mnt/disk4 ext4 defaults 1 2
UUID=f306ece0-a790-41d7-b685-63585b8534e4 swap swap defaults 0 0
保存退出
重新掛載系統內所有的硬盤
mount -a
[root@node01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 20G 2.1G 17G 12% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 40M 141M 22% /boot
/dev/sda3 7.8G 18M 7.4G 1% /mnt/disk1
/dev/sda5 7.6G 18M 7.2G 1% /mnt/disk2
/dev/sdb1 4.8G 10M 4.6G 1% /mnt/disk3
/dev/sdb2 4.9G 11M 4.6G 1% /mnt/disk4