linux命令行掛載硬盤 命令行掛載磁盤

Linux掛載命令

在linux當(dāng)中所有的存儲(chǔ)設(shè)備如u盤、光盤、硬盤等,都必須掛載之后才能正常使用。

公司主營(yíng)業(yè)務(wù):網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)公司是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來驚喜。成都創(chuàng)新互聯(lián)公司推出棗陽免費(fèi)做網(wǎng)站回饋大家。

其實(shí)掛載可以理解為windows當(dāng)中的分配盤符,只不過windows當(dāng)中是以英文字母ABCD等作為盤符,而linux是拿系統(tǒng)目錄作為盤符,當(dāng)然linux當(dāng)中也不叫盤符,而是稱為掛載點(diǎn),而把為分區(qū)或者光盤等存儲(chǔ)設(shè)備分配一個(gè)掛載點(diǎn)的過程稱為掛載。

在安裝linux系統(tǒng)時(shí)設(shè)立的各個(gè)分區(qū),如根分區(qū)、/boot分區(qū)等都是自動(dòng)掛載的,也就是說不需要我們?nèi)藶椴僮?,開機(jī)就會(huì)自動(dòng)掛載。但是光盤、u盤等存儲(chǔ)設(shè)備如果需要使用,就必須人為的進(jìn)行掛載。其實(shí)我們?cè)趙indows下插入U(xiǎn)盤也是需要掛載(分配盤符)的,只不過windows下分配盤符是自動(dòng)的。

mount #查詢系統(tǒng)中已經(jīng)掛載的設(shè)備

mount -a #依據(jù)配置文件/etc/fstab的內(nèi)容,進(jìn)行自動(dòng)掛載

了解即可,不熟悉建議不要隨意修改,使用默認(rèn)值。

演示 exec 選項(xiàng)的作用,重新掛載 /home 分區(qū),并設(shè)置不允許執(zhí)行可執(zhí)行文件

使用完光盤等存儲(chǔ)設(shè)備后必須卸載,執(zhí)行卸載命令時(shí)必須保證不在設(shè)備掛載的目錄下,否則會(huì)提示設(shè)備正在使用。

umount 設(shè)備文件名或掛載點(diǎn) #卸載命令

umount /mnt/cdrom #卸載光盤

因?yàn)閡盤在linux中被當(dāng)成硬盤看待,一般來說插入u盤后它的設(shè)備文件名應(yīng)該是sdb1,但是這個(gè)也不是一定的,有可能系統(tǒng)不止一塊硬盤,所以最好使用命令查看以下。

注意:linux默認(rèn)是不支持NTFS文件系統(tǒng)的,vfat(相當(dāng)于windows下的fat32),如果想要支持可以安裝 ntfs -3g 這個(gè)軟件。掛載U盤了解即可,實(shí)際很少使用。

在真實(shí)機(jī)中插入U(xiǎn)盤后,可以在虛擬機(jī) --可移動(dòng)設(shè)備 --選擇u盤 --連接

linux磁盤重新掛載?

linux 重新掛載需要先卸載再重新掛載,如果要一條命令可以通過符號(hào)將兩個(gè)命令組合到一個(gè)命令里,例如:

umount -l /mnt/test mount -o ro /dev/hda1? /mnt/test

linux中掛載命令是mount,卸載是umount,在命令行中使用可以將多條命令組合成一條命令并順序執(zhí)行,以達(dá)到快速執(zhí)行的目的。

擴(kuò)展資料

linux掛載命令mount的用法介紹:

1、語法

mount [-fnrsvw] [-t vfstype] [-o options] device dir

2、參數(shù)說明:

-V:顯示程序版本

-h:顯示輔助訊息

-v:顯示較訊息,通常和 -f 用來除錯(cuò)。

-a:將 /etc/fstab 中定義的所有檔案系統(tǒng)掛上。

-F:這個(gè)命令通常和 -a 一起使用,它會(huì)為每一個(gè) mount 的動(dòng)作產(chǎn)生一個(gè)行程負(fù)責(zé)執(zhí)行。在系統(tǒng)需要掛上大量 NFS 檔案系統(tǒng)時(shí)可以加快掛上的動(dòng)作。

-f:通常用在除錯(cuò)的用途。它會(huì)使 mount 并不執(zhí)行實(shí)際掛上的動(dòng)作,而是模擬整個(gè)掛上的過程。通常會(huì)和 -v 一起使用。

-n:一般而言,mount 在掛上后會(huì)在 /etc/mtab 中寫入一筆資料。但在系統(tǒng)中沒有可寫入檔案系統(tǒng)存在的情況下可以用這個(gè)選項(xiàng)取消這個(gè)動(dòng)作。

linux下如何掛載硬盤?

1.插入新硬盤,啟動(dòng)Linux服務(wù)器,使用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.實(shí)現(xiàn)系統(tǒng)重啟后自動(dòng)掛載該分區(qū)

#vi /etc/fstab

在最后一行添加

/dev/sdb /media/imgs ext4 defaults 1 2

一、添加磁盤

添加加新硬盤重啟服務(wù)器

添加完之后就可以重啟機(jī)器了,如果你機(jī)器是開啟的,進(jìn)入系統(tǒng)并不能看見你剛添加的那塊磁盤,只有等系統(tǒng)重啟,重新加載之后才會(huì)顯示安裝的那塊磁盤

二、進(jìn)入系統(tǒng)

使用root用戶進(jìn)入系統(tǒng)

三、 查看硬盤信息

[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

可以看到這臺(tái)機(jī)器加載了三個(gè)磁盤sda、sdb、sdc

其中sda是初始磁盤,sdb已經(jīng)初始化且經(jīng)過使用,sdc是剛剛加載的,未格式化的新磁盤

四、創(chuàng)建新硬盤分區(qū)

[root@localhost ~]# fdisk /dev/sdc #進(jìn)入磁盤

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 ? ? ?#設(shè)定可啟動(dòng)標(biāo)記

b ? edit bsd disklabel

c ? toggle the dos compatibility flag

d ? delete a partition ? ? ? ? ?#刪除一個(gè)分區(qū)

l ? list known partition types ?#各分區(qū)類型所對(duì)應(yīng)的ID

m ? print this menu ? ? ? ? ? ? #菜單

n ? add a new partition ? ? ? ? #添加一個(gè)分區(qū)

o ? create a new empty DOS partition table

p ? print the partition table ? #顯示該磁盤下的當(dāng)前分區(qū)信息

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

知道命令之后就可以進(jìn)行分區(qū)了

Command (m for help): p //打印分區(qū)信息,可以看到當(dāng)前并沒有分區(qū)

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 //創(chuàng)建一個(gè)新的分區(qū)

Command action

e ? extended//輸入e為創(chuàng)建擴(kuò)展分區(qū)

p ? primary partition (1-4) //輸入p為創(chuàng)建邏輯分區(qū)

p

Partition number (1-4): 1//劃分邏輯分區(qū)

First cylinder (1-2610, default 1): //我這里直接回車,是不想把該磁盤分成多個(gè)分區(qū),把整個(gè)磁盤作為1個(gè)分區(qū)

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 //再次查看可以看到該磁盤已經(jīng)有1個(gè)分區(qū)了

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 //保存分區(qū)

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已經(jīng)分區(qū)好了

五、格式化分區(qū)

[root@localhost ~]# mkfs.ext3 /dev/sdc1

//將/dev/sdc1格式化為ext3類型,好像大部分的磁盤都是格式化為ext3類型,具體為什么沒有深入研究,暫時(shí)不清楚,想了解的朋友可以自己查一下

1

2

[root@localhost ~]# mkfs.ext3 /dev/sdc1

mke2fs 1.41.12 (17-May-2010)

文件系統(tǒng)標(biāo)簽=

操作系統(tǒng):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

第一個(gè)數(shù)據(jù)塊=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

格式化完畢,此時(shí)就可以使用“mount”命令掛載分區(qū)了,然后使用這個(gè)磁盤空間了

六、掛載分區(qū)以及開機(jī)自動(dòng)掛載

[root@localhost ~]# df -h //此時(shí)只有sda1和sdb1兩個(gè)磁盤掛載

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 //創(chuàng)建被掛載的路徑

[root@localhost disk]# ll

總用量 8

drwxr-xr-x. 4 root root 4096 7月 ?28 17:04 diskone

drwxr-xr-x. 2 r

當(dāng)前名稱:linux命令行掛載硬盤 命令行掛載磁盤
本文網(wǎng)址:http://muchs.cn/article46/docdceg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、云服務(wù)器Google、定制網(wǎng)站、商城網(wǎng)站服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)