1、加掛硬盤
- sudo hdparm -I /dev/sdb 硬盤硬件安裝后,此命令測試linux系統是否能找到掛載的未分區硬盤
sudo hdparm -I /dev/sdb 硬盤硬件安裝后,此命令測試linux系統是否能找到掛載的未分區硬盤
2、創建分區
- sudo fdisk /dev/sdb
sudo fdisk /dev/sdb
sda是第一塊SCSI硬盤,sdb第二塊,以此類推...物理分區使用a、b編號,每個物理硬盤最多有四個主邏輯分區(或擴展分區),所以自動分區中,擴展分區sda2下第一個邏輯分區編號從5開始
第一次執行sudo fdisk /dev/sdb,出現了Error: Unable to open /dev/sdb - unrecognised disk label. 提示找不到磁盤標簽,可以使用 parted 進行分區(sudo parted /dev/sdb )。
- Command (m for help):
- 這里按m獲得幫助
- a toggle a bootable flag 將分區設置為啟動區
- b edit bsd disklabel 編輯bsd的disklabel
- c toggle the dos compatibility flag 設置該分區為dos分區
- 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)
- Command (m for help):p //查看新硬盤的分區
- ********************************************************************
- Disk /dev/sdb: 1000204 MB, 1000202273280 bytes
- 255 heads, 63 sectors/track, 121601 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- ********************************************************************
- Command (m for help):n //創建新分區
- File system type (default ext2): ext3 //輸入想使用的分區格式
- Partition name: backup //輸入分區的名字
- First cylinder (default 0cyl): //第幾個柱面,我們按照默認
- Last cylinder or +size or +sizeMB or +sizeKB (default 0cyl):+1000000M //這里我們按大小輸入 即+1000000M (注意這個M為大寫)
- Warning: You requested a partition from 0cyl to 121576cyl.
- The closest location we can manage is 1cyl to 121575cyl. Is this still
- acceptable to you?
- y Yes
- n No
- 當然是y
- Command (m for help): p //查看新硬盤分區后的情況
- ********************************************************************
- Disk /dev/sdb: 1000 GB, 1000202273280 bytes
- 255 heads, 63 sectors/track, 121601 cylinders
- Units = cylinders of 16065 * 512 = 8225280 bytes
- Device Boot Start End Blocks Id System
- /dev/sdb1 2 121576 976559157 83 Linux
- ******************************************************************
- Command (m for help): w
- Information: Don't forget to update /etc/fstab, if necessary. //寫入硬盤分區屬性並結束
Command (m for help): 這里按m獲得幫助 a toggle a bootable flag 將分區設置為啟動區 b edit bsd disklabel 編輯bsd的disklabel c toggle the dos compatibility flag 設置該分區為dos分區 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) Command (m for help):p //查看新硬盤的分區 ******************************************************************** Disk /dev/sdb: 1000204 MB, 1000202273280 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System ******************************************************************** Command (m for help):n //創建新分區 File system type (default ext2): ext3 //輸入想使用的分區格式 Partition name: backup //輸入分區的名字 First cylinder (default 0cyl): //第幾個柱面,我們按照默認 Last cylinder or +size or +sizeMB or +sizeKB (default 0cyl):+1000000M //這里我們按大小輸入 即+1000000M (注意這個M為大寫) Warning: You requested a partition from 0cyl to 121576cyl. The closest location we can manage is 1cyl to 121575cyl. Is this still acceptable to you? y Yes n No 當然是y Command (m for help): p //查看新硬盤分區后的情況 ******************************************************************** Disk /dev/sdb: 1000 GB, 1000202273280 bytes 255 heads, 63 sectors/track, 121601 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 2 121576 976559157 83 Linux ****************************************************************** Command (m for help): w Information: Don't forget to update /etc/fstab, if necessary. //寫入硬盤分區屬性並結束
3、格式化硬盤
- sudo mkfs -t ext3 /dev/sdb1 //把上面創建的新硬盤分區格式化為ext3格式,這個要等一會才能自動結束
- ********************************************************************************
- mke2fs 1.40.8 (13-Mar-2008)
- Filesystem label=
- OS type: Linux
- Block size=4096 (log=2)
- Fragment size=4096 (log=2)
- 61038592 inodes, 244137796 blocks
- 12206889 blocks (5.00%) reserved for the super user
- First data block=0
- Maximum filesystem blocks=0
- 7451 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
- 102400000, 214990848
- Writing inode tables: done
- Creating journal (32768 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 37 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- ********************************************************************************
sudo mkfs -t ext3 /dev/sdb1 //把上面創建的新硬盤分區格式化為ext3格式,這個要等一會才能自動結束 ******************************************************************************** mke2fs 1.40.8 (13-Mar-2008) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 61038592 inodes, 244137796 blocks 12206889 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=0 7451 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, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 37 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. ********************************************************************************
4、設置sdb1的卷標
- sudo e2label /dev/sdb1 /backup //這里/backup 就是在/dev/sdb1根下起了個名字
sudo e2label /dev/sdb1 /backup //這里/backup 就是在/dev/sdb1根下起了個名字
5、設置掛載點
- sudo mkdir /backup //在根路徑下創建掛載點
sudo mkdir /backup //在根路徑下創建掛載點
6、設置開機自動掛載
- sudo vim /etc/fstab
sudo vim /etc/fstab
<file system> <mount point> <type> <options> <dump> <pass>
1 2 3 4 5 6 1 指代文件系統的設備名。最初,該字段只包含待掛載分區的設備名(如/dev/sda1)。現在,除設備名外,還可以包含LABEL或UUID 2 文件系統掛載點。文件系統包含掛載點下整個目錄樹結構里的所有數據,除非其中某個目錄又掛載了另一個文件系統 3 文件系統類型。下面是多數常見文件系統類型(ext3,tmpfs,devpts,sysfs,proc,swap,vfat) 4 mount命令選項。mount選項包括noauto(啟動時不掛載該文件系統)和ro(只讀方式掛載文件系統)等。在該字段里添加用戶或屬主選項,即可允許該用戶掛載文件系統。多個選項之間必須用逗號隔開。其他選項的相關信息可參看mount命令手冊頁(-o選項處) 5轉儲文件系統?該字段只在用dump備份時才有意義。數字1表示該文件系統需要轉儲,0表示不需要轉儲 6文件系統檢查?該字段里的數字表示文件系統是否需要用fsck檢查。0表示不必檢查該文件系統,數字1示意該文件系統需要先行檢查(用於根文件系統)。數字2則表示完成根文件系統檢查后,再檢查該文件系統
文件中增加如下配置信息
- LABEL=/backup /backup ext3 defaults 1 2
LABEL=/backup /backup ext3 defaults 1 2
掛載分區的卷標名稱 掛載點 掛載分區文件類型 掛載方式 略 略
或者
- /dev/sdb1 /backup ext3 defaults 1 2
/dev/sdb1 /backup ext3 defaults 1 2
或者在命令行手動掛載(每次重啟機器后都需要執行一次)
- mount -vl -t ext3 /dev/sdb1 /backup 掛載文件系統/顯示標簽
mount -vl -t ext3 /dev/sdb1 /backup 掛載文件系統/顯示標簽
7、重啟機器查看結果
- df -h //查看分區空間使用情況,就可以看到/backup已經自動掛載
- Filesystem Size Used Avail Use% Mounted on
- /dev/sda1 139G 121G 12G 92% /
- varrun 1.3G 68K 1.3G 1% /var/run
- varlock 1.3G 0 1.3G 0% /var/lock
- udev 1.3G 32K 1.3G 1% /dev
- devshm 1.3G 0 1.3G 0% /dev/shm
- /dev/sdb1 924G 11G 867G 2% /backup
df -h //查看分區空間使用情況,就可以看到/backup已經自動掛載 Filesystem Size Used Avail Use% Mounted on /dev/sda1 139G 121G 12G 92% / varrun 1.3G 68K 1.3G 1% /var/run varlock 1.3G 0 1.3G 0% /var/lock udev 1.3G 32K 1.3G 1% /dev devshm 1.3G 0 1.3G 0% /dev/shm /dev/sdb1 924G 11G 867G 2% /backup
成功了