linux下掛在硬盤

1.首先把ubuntu shutdown.

2.在VMware裏點擊菜單VM——>Settings

3.在Hardware裏面單擊底下的Add按鈕,然後選擇Hard Disk——>Next——>Next——>Disk size(GB)是新增硬盤的大小——>Next——>Finish——>Ok. 這樣在VMware的Devices裏就多了一個Hard Disk 2。
  三,接下來就是進入ubuntu,把新的硬盤mount進去了。
  1.
  Disk /dev/sda: 17.1 GB, 17179869184 bytes
  255 heads, 63 sectors/track, 2088 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Disk identifier: 0x000af2a2
  Device Boot Start End Blocks Id System
  /dev/sda1 * 1 993 7976241 83 Linux
  /dev/sda2 994 1044 409657+ 5 Extended
  /dev/sda5 994 1044 409626 82 Linux swap / Solaris
  Disk /dev/sdb: 8589 MB, 8589934592 bytes
  255 heads, 63 sectors/track, 1044 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Disk identifier: 0x00000000
  Disk /dev/sdb doesn't contain a valid partition table
  可以看到多了一個 /dev/sdb
  2.
  下面是格式化成ext3文件系統
  mke2fs 1.40.8 (13-Mar-2008)
  /dev/sdb is entire device, not just one partition!
  Proceed anyway? (y,n) y //把整個新硬件格式化,不分區。
  Filesystem label=
  OS type: Linux
  Block size=4096 (log=2)
  Fragment size=4096 (log=2)
  524288 inodes, 2097152 blocks
  104857 blocks (5.00%) reserved for the super user
  First data block=0
  Maximum filesystem blocks=2147483648
  64 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
  Writing inode tables: done
  Creating journal (32768 blocks): done
  Writing superblocks and filesystem accounting information: done
  This filesystem will be automatically checked every 26 mounts or
  180 days, whichever comes first. Use tune2fs -c or -i to override.
  3.
  lost+found
  4.
  用df命令查看一下掛載情況
  Filesystem 1K-blocks Used Available Use% Mounted on
  /dev/sda1 7913216 7803524 0 100% /
  varrun 257788 240 257548 1% /var/run
  varlock 257788 0 257788 0% /var/lock
  udev 257788 48 257740 1% /dev
  devshm 257788 44 257744 1% /dev/shm
  lrm 257788 39760 218028 16% /lib/modules/2.6.24-19-generic/volatile
  /dev/sdb 8322488 149632 7753428 2% /home/work
  gvfs-fuse-daemon 7913216 7803524 0 100% /root/.gvfs
  看到/dev/sdb 8322488 149632 7753428 2% /home/work
  一項, 可見成功了。
  5.實現啓動自動掛載。
  根據下面的格式
  # <file system> <mount point> <type> <options> <dump> <pass>
  我們自己添加:
  /dev/sdb /home/work ext3 defaults 0 0
重啓,這樣就完成了增加硬盤的全部步驟了。
3、新磁盤分區。
1)、fdisk命令:fdisk –l
打印當前的磁盤分區表,這時我們可以看到磁盤的總量的確增加到4GB了,但是分區只有以前的那幾個原有的分區。
2)、鍵入命令:fdisk /dev/sda
sda就是經過擴容的硬盤,爲SCSI硬盤,IDE類型硬盤對應爲hda,是對該硬盤進行操作”
鍵入 : m
列出fdisk的幫助
3)、我們在這裏是要添加一個新分區,即將擴容出來的那部分做成一個新分區,這樣才能被操作系統掛載識別。
鍵入: n
命令n用於添加新分區
4)、此時,fdisk會讓你選擇添加爲邏輯分區呢(編號從5開始)還是主分區(編號1到4)。選擇主分區吧,則鍵入p;選擇邏輯分區鍵入l。我們選擇主分區於是:
鍵入: p
選擇創建主分區
5)、此時,fdisk會讓你選擇主分區的編號,如果已經有了主分區sda1,sda2,那麼編號就選3,即要創建的該分區爲sda3.
鍵入: 3
6)、此時,fdisk又會讓你選擇該分區的開始值這個就是分區的Start值(start cylinder);這裏最好直接按回車,如果您輸入了一個非默認的數字,會造成空間浪費。
此時鍵入:w
保存所有並退出,分區劃分完畢
4、現在還不能使用該磁盤,要格式化一下。
格式化該新添加的分區:
鍵入:mkfs-t ext3 /dev/sda3
或者 mkfs.ext3 /dev/sda3格式化指定的分區,依次類推,現在的系統大部分都是ext3格式,如果你需要其它的,可以查看mkfs的幫助
5、掛載該分區:
手動掛載,則鍵入:mount /dev/sda3 /home/work/
表示將該新分區掛載到/home/work/這個目錄下面"
開機自動掛載,則修改/etc/fstab文件,在這個文件裏面添加一行:
/dev/sda3 /home/work ext3 defaults, 0 1
關於該文件的格式,以後寫文章討論
以後每次開機都會將該分區掛在大work目錄下面了。
到這裏就可以使用該新加分區啦 。
fdisk分區示例
fdisk是linux下的磁盤分區工具,能劃分磁盤成爲若干個區,同時也能爲每個分區指定文件系統,比如linux、fat32、linux、linux swap、fat16格式等;
當然我們用fdisk對磁盤分區後,還要使用mkfs命令對分區進行格式化才能掛載使用。
硬盤分區的表示:
在Linux是通過hd*x或sd*x表示的,其中“*”表示的是a、b、c等等;x表示的數字1、2、3等等;hd是IDE硬盤;sd是SCSI或移動存儲。
Start
表示的一個分區從X cylinder(磁柱)開始;
End
表示一個分區到Y cylinder(磁柱)結束;
id,System
表示分區類型,分區時通過指定id來確認分區類型,fdisk中通過t指定。
Blocks
分區的容量。
fdisk -l
# fdisk -l
Disk/dev/hda:120.0GB, 120034123776 bytes
255heads,63sectors/track,14593cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 829 6658911 b W95 FAT32
/dev/hda2 830 14593 110559330 f W95 Ext'd (LBA)
/dev/hda5 830 3506 21502971 7 HPFS/NTFS
/dev/hda6 3507 4811 10482381 83 Linux
/dev/hda7 4812 4942 1052226 82 Linux swap
/dev/hda8 4943 6217 10241406 83 Linux
… …
通過“fdisk –l”可以查看機器所掛硬盤及分區情況。這個硬盤是120G的,有255個磁面;63個扇區;9729個柱面;每個cylinder(柱面)的容量是8225280 bytes。hda有兩個主分區(包括擴展分區),分別是主分區hda1和hda2(擴展分區);hda5以後是邏輯分區。硬盤總容量爲主分區(包括擴展分區)總容量,而擴展分區爲邏輯分區總容量之和。因此,通過上面的例子,我們可以得知hda=hda1+hda2,其中hda3=hda5+hda6+hda7+hda8+... ...。
fdisk交互式分區操作
我們以/dev/sda設備爲例,來講解如何用fdisk來操作添加、刪除分區等動作。
#fdisk /dev/sda
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 //列出分區類型
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) //擴展功能
【例】對sda添加兩個200M的主分區,其它爲擴展分區,在擴展分區中添加兩個200M的邏輯分區;
Command (m for help): n
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-125, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-125, default 125):+200M
Command (m for help):n
e extended
p primary partition (1-4)
p
Partition number (1-4):2
First cylinder (26-125, default 26):
Using default value 26
Last cylinder or +size or +sizeM or +sizeK (26-125, default 125):+200M
Command (m for help):n
e extended
p primary partition (1-4)
e
Partition number (1-4):3
First cylinder (51-125, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125):
Using default value 125
Command (m for help):n
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (51-125, default 51):
Using default value 51
Last cylinder or +size or +sizeM or +sizeK (51-125, default 125):+200M
Command (m for help):n
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (76-125, default 76):
Using default value 76
Last cylinder or +size or +sizeM or +sizeK (76-125, default 125):+200M
Command (m for help):p
Disk /dev/sda: 1035 MB, 1035730944 bytes
256 heads, 63 sectors/track, 125 cylinders
Units = cylinders of 16128 * 512 = 8257536 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 25 201568+ 83 Linux
/dev/sda2 26 50 201600 83 Linux
/dev/sda3 51 125 604800 5 Extended
/dev/sda5 51 75 201568+ 83 Linux
/dev/sda6 76 100 201568+ 83 Linux
然後根據t指令來改變分區類型,最後w保存退出。
 
 
分區的過程正常:
[root@db1 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 841 1534207+ 82 Linux swap / Solaris
[root@db1 /]# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (842-2610, default 842):
Using default value 842
Last cylinder or +size or +sizeM or +sizeK (842-2610, default 2610):
Using default value 2610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
再次查看,分區已經劃好:
[root@db1 /]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 650 5116702+ 83 Linux
/dev/sda3 651 841 1534207+ 82 Linux swap / Solaris
/dev/sda4 842 2610 14209492+ 83 Linux
但是格式化的時候,報錯:
[root@db1 /]# mkfs -t ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
Could not stat /dev/sda4 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
解決方法:執行下partprobe 命令
    partprobe包含在parted的rpm軟件包中。partprobe可以修改kernel中分區表,使kernel重新讀取分區表。 因此,使用該命令就可以創建分區並且在不重新啓動機器的情況下系統能夠識別這些分區。
查看是否安裝該命令:
[root@db1 dev]# rpm -q parted
parted-1.8.1-23.el5
我們執行一下該命令:
[root@db1 dev]# partprobe
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been opened read-only.
然後在格式化,就ok了:
[root@db1 dev]# mkfs -t ext3 /dev/sda4
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1778880 inodes, 3552373 blocks
177618 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=3640655872
109 block groups
32768 blocks per group, 32768 fragments per group
16320 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
關於Linux 掛盤,參考Blog:
linux Header V3 DSA signature: NOKEY, key ID 錯誤解決方法從 RPM 版本 4.1 開始,在安裝或升級軟件包時會檢查軟件包的簽名。如果簽名校驗失敗,你就會看到如下所示的錯誤消息:
error: V3 DSA signature: BAD, key ID 0352860f
如果它是新的、只針對文件頭的簽名,你會看到如下所示的錯誤消息:
error: Header V3 DSA signature: BAD, key ID 0352860f
如果你沒有安裝合適的鑰匙來校驗簽名,消息中就會包含 NOKEY ,如:
warning: V3 DSA signature: NOKEY, key ID 0352860f
在CentOS下有的時候用yum安裝軟件的時候最後會提示:
引用
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID*****
這是由於yum安裝了舊版本的GPG keys造成的,解決辦法就是
引用
rpm --import /etc/pki/rpm-gpg/RPM*
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章