linux挂载硬盘的分区创建,Linux 新增硬盘、新建分区、格式化硬盘、挂载硬盘的操作...
今天學校有一臺機器發現有塊硬盤沒有掛載,然后叫我掛載一下,這里記錄一下 Linux 下新增硬盤分區、格式化硬盤、掛載硬盤的操作。
查看當前硬盤
首先我們查看一下當前的硬盤配置。使用命令
sudo fdisk -l
就可以看到目前的硬盤了。可以看到有塊空的 sda(這里忘了復制輸出了,大家可以看到自己的硬盤就對了)。
新增硬盤,新建分區
下面我們將使用 fdisk 命令來創建新的分區。首先進入我們需要操作的硬盤:
$ sudo fdisk /dev/sda
sudo: unable to resolve host csc-server-0-2
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
The size of this disk is 7.3 TiB (7999376588800 bytes). DOS partition table format can not be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
Created a new DOS disklabel with disk identifier 0xcb6595dd.
然后我們可以輸入 m 來查看一下幫助信息。
Command (m for help): m
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
接下來,由于我這里的硬盤大于 2TB,所以不能直接新建分區,需要先增加一個 GPT 標簽。小于 2TB 的硬盤不需要這個操作。輸入命令 g 回車。
Command (m for help): g
Created a new GPT disklabel (GUID: B5039588-BAAA-4FA9-8537-35E03F40E7FD).
然后我們看一下當前沒有被分區的空間,輸入 F 回車:
Command (m for help): F
Unpartitioned space /dev/sda: 7.3 TiB, 7999375523328 bytes, 15623780319 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
Start End Sectors Size
2048 15623782366 15623780319 7.3T
可以看到目前有 7.3TB 沒有被分區。輸入 n 新建一個分區。這里開始和結束都使用默認的即可,這樣整塊硬盤都會被分進去,如果想自己定義大小,那么自己輸入大小即可。
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-15623782366, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-15623782366, default 15623782366):
Created a new partition 1 of type 'Linux filesystem' and of size 7.3 TiB.
再次輸入 F 查看一下,發現已經全都被分區了。
Command (m for help): F
Unpartitioned space /dev/sda: 0 B, 0 bytes, 0 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
然后我們輸入 v 確認一下,沒有錯誤。
Command (m for help): v
No errors detected.
Header version: 1.0
Using 1 out of 128 partitions.
A total of 0 free sectors is available in 0 segments (the largest is (null)).
如果沒有錯誤,就可以輸入 w 保存了。
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
至此分區結束。
格式化硬盤
新增分區后,需要格式化一下硬盤。首先我們還是查看一下當前的硬盤信息。使用 df -h 發現還是看不到剛剛新增的分區,很正常,因為還沒有掛載。
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 63G 0 63G 0% /dev
tmpfs 13G 35M 13G 1% /run
/dev/sdb2 343G 326G 0 100% /
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/sdb1 511M 3.4M 508M 1% /boot/efi
tmpfs 13G 16K 13G 1% /run/user/1003
tmpfs 13G 0 13G 0% /run/user/1001
tmpfs 13G 0 13G 0% /run/user/1002
tmpfs 13G 0 13G 0% /run/user/1000
再次查看所有硬盤,會看到已經有一個 7.3TB 的分區。
$ sudo fdisk -l
sudo: unable to resolve host csc-server-0-2
Disk /dev/sda: 7.3 TiB, 7999376588800 bytes, 15623782400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: B5039588-BAAA-4FA9-8537-35E03F40E7FD
Device Start End Sectors Size Type
/dev/sda1 2048 15623782366 15623780319 7.3T Linux filesystem
Disk /dev/sdb: 477 GiB, 512110190592 bytes, 1000215216 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
Disklabel type: gpt
Disk identifier: 8D6EC320-DBA6-4239-9C96-EEBBD4E51C84
Device Start End Sectors Size Type
/dev/sdb1 2048 1050623 1048576 512M EFI System
/dev/sdb2 1050624 732002303 730951680 348.6G Linux filesystem
/dev/sdb3 732002304 1000214527 268212224 127.9G Linux swap
然后我們開始格式化。
$ sudo mkfs.ext4 /dev/sda1
sudo: unable to resolve host csc-server-0-2
mke2fs 1.42.13 (17-May-2015)
/dev/sda1 contains a ext3 file system
last mounted on Tue Dec 19 11:09:41 2017
Proceed anyway? (y,n) y
Creating filesystem with 1952972539 4k blocks and 244121600 inodes
Filesystem UUID: 785af015-7752-4f93-b314-ecb112757e7d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
格式化的時間比較長,耐心等待,直到它全部 done 即可。
掛載分區
格式化完成后,就可以掛載分區了。
$ sudo mount /dev/sda1 /home
sudo: unable to resolve host csc-server-0-2
[sudo] password for we:
這里需要輸入一下 sudo 密碼。然后我們再查看一下當前的硬盤:
$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 63G 0 63G 0% /dev
tmpfs 13G 35M 13G 1% /run
/dev/sdb2 343G 326G 0 100% /
tmpfs 63G 0 63G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 63G 0 63G 0% /sys/fs/cgroup
/dev/sdb1 511M 3.4M 508M 1% /boot/efi
tmpfs 13G 16K 13G 1% /run/user/1003
tmpfs 13G 0 13G 0% /run/user/1001
tmpfs 13G 0 13G 0% /run/user/1000
/dev/sda1 7.3T 51M 6.9T 1% /home
可以看到,這塊 7.3TB 的硬盤已經成功掛載到 /home 目錄了。
最后我們需要添加一下開機自動掛載。
編輯 /etc/fstab 這個文件,然后加入:
UUID=785af015-7752-4f93-b314-ecb112757e7d /home ext4 defaults 0 2
其中,UUID 是之前格式化硬盤的時候顯示的,大家可以往上翻看一看。/home 就是掛載點。 ext4 是文件格式, defaults 不需要修改。最后 0 2,建議也不修改。最后的 2 是針對所有非 boot 硬盤的,設置成 0 也可以,這樣就是開機時候不檢查這塊硬盤。
結語
至此,我們完成了在 Linux 上新增硬盤、新建分區、格式化硬盤、掛載分區等一系列的操作。
總結
以上是生活随笔為你收集整理的linux挂载硬盘的分区创建,Linux 新增硬盘、新建分区、格式化硬盘、挂载硬盘的操作...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vip会员管理系统c语言,路西牌会员管理
- 下一篇: linux 其他常用命令