重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
Linux 將一塊硬盤進行掛載到任意目錄下的方法如下:
專注于為中小企業提供成都做網站、網站制作、成都外貿網站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業晉中免費做網站提供優質的服務。我們立足成都,凝聚了一批互聯網行業人才,有力地推動了成百上千家企業的穩健成長,幫助中小企業通過網站建設實現規模擴充和轉變。
掛載目錄是任意的,由你自己決定。
1、首先先在虛擬機上添加一塊硬盤,打開虛擬機收輸入fdisk -l 將,系統中所有的分區都列出來;
2、當輸入fdisk -l 顯示的結果為如下圖所示的時候;
3、輸入fdisk /dev/sdb :對已經選中的硬盤進行編輯。選中硬盤時候輸入n(增加一個新的分區),之后輸入選輸入p(選則為主分區),其次在輸入1,最后輸入“w”保存退出;
4、之后輸入fdisk -l ,再次查看分區是否完成分配。紅框中的表示分配成功;
5、格式化新加的分區表 mkfs -t ext3(表示格式化后的文件系統) /dev/sdb1;
6、指令:vim /etc/fstab ,仿照上面的內容進行仿寫從而實現開機掛載。
拓展資料:
Linux是一套免費使用和自由傳播的類Unix操作系統,是一個基于POSIX和UNIX的多用戶、多任務、支持多線程和多CPU的操作系統。
嚴格來講,Linux這個詞本身只表示Linux內核,但實際上人們已經習慣了用Linux來形容整個基于Linux內核,并且使用GNU 工程各種工具和數據庫的操作系統。
1.插入新硬盤,啟動Linux服務器,使用fdisk -l 查看硬盤
#fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
2.格式化硬盤
#mkfs -t ext4 /dev/sdb
3.掛載硬盤
#mount 硬盤地址 要掛載的地址
#mount /dev/sdb /media/imgs
4.實現系統重啟后自動掛載該分區
#vi /etc/fstab
在最后一行添加
/dev/sdb /media/imgs ext4 defaults 1 2
一、添加磁盤
添加加新硬盤重啟服務器
添加完之后就可以重啟機器了,如果你機器是開啟的,進入系統并不能看見你剛添加的那塊磁盤,只有等系統重啟,重新加載之后才會顯示安裝的那塊磁盤
二、進入系統
使用root用戶進入系統
三、 查看硬盤信息
[root@localhost ~]# fdisk -l ? //磁盤命令
1
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x000c4cb5
Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System
/dev/sda1 ? * ? ? ? ? ? 1 ? ? ? ? ?64 ? ? ?512000 ? 83 ?Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 ? ? ? ? ? ? ?64 ? ? ? ?2611 ? ?20458496 ? 8e ?Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0xd0f5c869
Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System
/dev/sdb1 ? ? ? ? ? ? ? 1 ? ? ? ?2610 ? ?20964793+ ?83 ?Linux
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
可以看到這臺機器加載了三個磁盤sda、sdb、sdc
其中sda是初始磁盤,sdb已經初始化且經過使用,sdc是剛剛加載的,未格式化的新磁盤
四、創建新硬盤分區
[root@localhost ~]# fdisk /dev/sdc #進入磁盤
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45a3cadb.
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
Command action
a ? toggle a bootable flag ? ? ?#設定可啟動標記
b ? edit bsd disklabel
c ? toggle the dos compatibility flag
d ? delete a partition ? ? ? ? ?#刪除一個分區
l ? list known partition types ?#各分區類型所對應的ID
m ? print this menu ? ? ? ? ? ? #菜單
n ? add a new partition ? ? ? ? #添加一個分區
o ? create a new empty DOS partition table
p ? print the partition table ? #顯示該磁盤下的當前分區信息
q ? quit without saving changes #不保存退出
s ? create a new empty Sun disklabel
t ? change a partition's system id
u ? change display/entry units
v ? verify the partition table
w ? write table to disk and exit #保存退出
x ? extra functionality (experts only)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
知道命令之后就可以進行分區了
Command (m for help): p //打印分區信息,可以看到當前并沒有分區
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x45a3cadb
Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System
Command (m for help): n //創建一個新的分區
Command action
e ? extended//輸入e為創建擴展分區
p ? primary partition (1-4) //輸入p為創建邏輯分區
p
Partition number (1-4): 1//劃分邏輯分區
First cylinder (1-2610, default 1): //我這里直接回車,是不想把該磁盤分成多個分區,把整個磁盤作為1個分區
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): p //再次查看可以看到該磁盤已經有1個分區了
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x45a3cadb
Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System
/dev/sdc1 ? ? ? ? ? ? ? 1 ? ? ? ?2610 ? ?20964793+ ?83 ?Linux
Command (m for help): w //保存分區
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
再次使用”fdisk -l”命令查看磁盤信息
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x406a4c58
Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System
/dev/sdc1 ? ? ? ? ? ? ? 1 ? ? ? ?2610 ? ?20964793+ ?83 ?Linux
1
2
3
4
5
6
7
8
9
第三塊磁盤/dev/sdc已經分區好了
五、格式化分區
[root@localhost ~]# mkfs.ext3 /dev/sdc1
//將/dev/sdc1格式化為ext3類型,好像大部分的磁盤都是格式化為ext3類型,具體為什么沒有深入研究,暫時不清楚,想了解的朋友可以自己查一下
1
2
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
文件系統標簽=
操作系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
正在寫入inode表: 完成 ? ? ? ? ? ? ? ? ? ? ? ? ?
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. ?Use tune2fs -c or -i to override.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
格式化完畢,此時就可以使用“mount”命令掛載分區了,然后使用這個磁盤空間了
六、掛載分區以及開機自動掛載
[root@localhost ~]# df -h //此時只有sda1和sdb1兩個磁盤掛載
Filesystem ? ? ? ? ? ? ? ? ? ?Size ?Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ? 18G ? 15G ?1.5G ?92% /
tmpfs ? ? ? ? ? ? ? ? ? ? ? ? 932M ? 76K ?932M ? 1% /dev/shm
/dev/sda1 ? ? ? ? ? ? ? ? ? ? 485M ? 40M ?421M ? 9% /boot
/dev/sdb1 ? ? ? ? ? ? ? ? ? ? ?20G ?1.2G ? 18G ? 7% /disk/diskone
/dev/sr0 ? ? ? ? ? ? ? ? ? ? ?4.2G ?4.2G ? ? 0 100% /media/CentOS_6.5_Final
[root@localhost /]# cd /disk/
[root@localhost disk]# ll
總用量 4
drwxr-xr-x. 4 root root 4096 7月 ?28 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
總用量 20
drwx------. 2 root root 16384 7月 ?28 16:12 lost+found
drwxr-xr-x. 2 root root ?4096 7月 ?28 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //創建被掛載的路徑
[root@localhost disk]# ll
總用量 8
drwxr-xr-x. 4 root root 4096 7月 ?28 17:04 diskone
drwxr-xr-x. 2 r
linux 重新掛載需要先卸載再重新掛載,如果要一條命令可以通過符號將兩個命令組合到一個命令里,例如:
umount -l /mnt/test mount -o ro /dev/hda1? /mnt/test
linux中掛載命令是mount,卸載是umount,在命令行中使用可以將多條命令組合成一條命令并順序執行,以達到快速執行的目的。
擴展資料
linux掛載命令mount的用法介紹:
1、語法
mount [-fnrsvw] [-t vfstype] [-o options] device dir
2、參數說明:
-V:顯示程序版本
-h:顯示輔助訊息
-v:顯示較訊息,通常和 -f 用來除錯。
-a:將 /etc/fstab 中定義的所有檔案系統掛上。
-F:這個命令通常和 -a 一起使用,它會為每一個 mount 的動作產生一個行程負責執行。在系統需要掛上大量 NFS 檔案系統時可以加快掛上的動作。
-f:通常用在除錯的用途。它會使 mount 并不執行實際掛上的動作,而是模擬整個掛上的過程。通常會和 -v 一起使用。
-n:一般而言,mount 在掛上后會在 /etc/mtab 中寫入一筆資料。但在系統中沒有可寫入檔案系統存在的情況下可以用這個選項取消這個動作。