linux挂载硬盘的分区创建,Linux 新增硬盘、新建分区、格式化硬盘、挂载硬盘的操作...
今天學(xué)校有一臺(tái)機(jī)器發(fā)現(xiàn)有塊硬盤沒有掛載,然后叫我掛載一下,這里記錄一下 Linux 下新增硬盤分區(qū)、格式化硬盤、掛載硬盤的操作。
查看當(dāng)前硬盤
首先我們查看一下當(dāng)前的硬盤配置。使用命令
sudo fdisk -l
就可以看到目前的硬盤了。可以看到有塊空的 sda(這里忘了復(fù)制輸出了,大家可以看到自己的硬盤就對(duì)了)。
新增硬盤,新建分區(qū)
下面我們將使用 fdisk 命令來(lái)創(chuàng)建新的分區(qū)。首先進(jìn)入我們需要操作的硬盤:
$ 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 來(lái)查看一下幫助信息。
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
接下來(lái),由于我這里的硬盤大于 2TB,所以不能直接新建分區(qū),需要先增加一個(gè) GPT 標(biāo)簽。小于 2TB 的硬盤不需要這個(gè)操作。輸入命令 g 回車。
Command (m for help): g
Created a new GPT disklabel (GUID: B5039588-BAAA-4FA9-8537-35E03F40E7FD).
然后我們看一下當(dāng)前沒有被分區(qū)的空間,輸入 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 沒有被分區(qū)。輸入 n 新建一個(gè)分區(qū)。這里開始和結(jié)束都使用默認(rèn)的即可,這樣整塊硬盤都會(huì)被分進(jì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 查看一下,發(fā)現(xiàn)已經(jīng)全都被分區(qū)了。
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 確認(rèn)一下,沒有錯(cuò)誤。
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)).
如果沒有錯(cuò)誤,就可以輸入 w 保存了。
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
至此分區(qū)結(jié)束。
格式化硬盤
新增分區(qū)后,需要格式化一下硬盤。首先我們還是查看一下當(dāng)前的硬盤信息。使用 df -h 發(fā)現(xiàn)還是看不到剛剛新增的分區(qū),很正常,因?yàn)檫€沒有掛載。
$ 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
再次查看所有硬盤,會(huì)看到已經(jīng)有一個(gè) 7.3TB 的分區(qū)。
$ 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
格式化的時(shí)間比較長(zhǎng),耐心等待,直到它全部 done 即可。
掛載分區(qū)
格式化完成后,就可以掛載分區(qū)了。
$ sudo mount /dev/sda1 /home
sudo: unable to resolve host csc-server-0-2
[sudo] password for we:
這里需要輸入一下 sudo 密碼。然后我們?cè)俨榭匆幌庐?dāng)前的硬盤:
$ 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 的硬盤已經(jīng)成功掛載到 /home 目錄了。
最后我們需要添加一下開機(jī)自動(dòng)掛載。
編輯 /etc/fstab 這個(gè)文件,然后加入:
UUID=785af015-7752-4f93-b314-ecb112757e7d /home ext4 defaults 0 2
其中,UUID 是之前格式化硬盤的時(shí)候顯示的,大家可以往上翻看一看。/home 就是掛載點(diǎn)。 ext4 是文件格式, defaults 不需要修改。最后 0 2,建議也不修改。最后的 2 是針對(duì)所有非 boot 硬盤的,設(shè)置成 0 也可以,這樣就是開機(jī)時(shí)候不檢查這塊硬盤。
結(jié)語(yǔ)
至此,我們完成了在 Linux 上新增硬盤、新建分區(qū)、格式化硬盤、掛載分區(qū)等一系列的操作。
總結(jié)
以上是生活随笔為你收集整理的linux挂载硬盘的分区创建,Linux 新增硬盘、新建分区、格式化硬盘、挂载硬盘的操作...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vip会员管理系统c语言,路西牌会员管理
- 下一篇: adaptivitypara设置选0还是