1. 程式人生 > 其它 >ubuntu server 14.04 新增新硬碟

ubuntu server 14.04 新增新硬碟

1 關機,安裝新硬碟, 然後上電開機。
2 檢查是否檢測到了新硬碟:
~$ ls -l /dev/sd* 
brw-rw---- 1 root disk 8,  0  5月 23 09:20 /dev/sda
brw-rw---- 1 root disk 8,  1  5月 23 09:20 /dev/sda1
brw-rw---- 1 root disk 8,  2  5月 23 09:20 /dev/sda2
brw-rw---- 1 root disk 8,  5  5月 23 09:20 /dev/sda5
brw-rw---- 1 root disk 8, 16  5月 23 09:20 /dev/sdb

看到了新增加的硬碟為 /dev/sdb

3 檢視新硬碟的引數:
~$ sudo hdparm -I /dev/sdb
/dev/sdb:

ATA device, with non-removable media
    Model Number:       ST2000DM006-2DM164                      
    Serial Number:      W4Z4HPJC
    Firmware Revision:  CC26    
    Transport:          Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
    Used: unknown (minor revision code 0x001f)
    Supported: 9 8 7 6 5
    Likely used: 9
Configuration:
    Logical        max    current
    cylinders    16383    16383
    heads        16    16
    sectors/track    63    63
    --
    CHS current addressable sectors:   16514064
    LBA    user addressable sectors:  268435455
    LBA48  user addressable sectors: 3907029168
    Logical  Sector size:                   512 bytes
    Physical Sector size:                  4096 bytes
    Logical Sector-0 offset:                  0 bytes
    device size with M = 1024*1024:     1907729 MBytes
    device size with M = 1000*1000:     2000398 MBytes (2000 GB)
    cache/buffer size  = unknown
    Form Factor: 3.5 inch
    Nominal Media Rotation Rate: 7200
Capabilities:
    LBA, IORDY(can be disabled)
    Queue depth: 32
    Standby timer values: spec'd by Standard, no device specific minimum
    R/W multiple sector transfer: Max = 16    Current = ?
    Advanced power management level: 254
    Recommended acoustic management value: 208, current value: 208
    DMA: mdma0 mdma1 mdma2 udma0 udma1 udma2 udma3 udma4 udma5 *udma6
         Cycle time: min=120ns recommended=120ns
    PIO: pio0 pio1 pio2 pio3 pio4
         Cycle time: no flow control=120ns  IORDY flow control=120ns
Commands/features:
    Enabled    Supported:
       *    SMART feature set
            Security Mode feature set
       *    Power Management feature set
       *    Write cache
       *    Look-ahead
       *    Host Protected Area feature set
       *    WRITE_BUFFER command
       *    READ_BUFFER command
       *    DOWNLOAD_MICROCODE
       *    Advanced Power Management feature set
            Power-Up In Standby feature set
       *    SET_FEATURES required to spinup after power up
            SET_MAX security extension
       *    48-bit Address feature set
       *    Device Configuration Overlay feature set
       *    Mandatory FLUSH_CACHE
       *    FLUSH_CACHE_EXT
       *    SMART error logging
       *    SMART self-test
       *    General Purpose Logging feature set
       *    WRITE_{DMA|MULTIPLE}_FUA_EXT
       *    64-bit World wide name
            Write-Read-Verify feature set
       *    WRITE_UNCORRECTABLE_EXT command
       *    {READ,WRITE}_DMA_EXT_GPL commands
       *    Segmented DOWNLOAD_MICROCODE
            unknown 119[6]
       *    Gen1 signaling speed (1.5Gb/s)
       *    Gen2 signaling speed (3.0Gb/s)
       *    Gen3 signaling speed (6.0Gb/s)
       *    Native Command Queueing (NCQ)
       *    Phy event counters
       *    READ_LOG_DMA_EXT equivalent to READ_LOG_EXT
       *    DMA Setup Auto-Activate optimization
            Device-initiated interface power management
       *    Software settings preservation
            unknown 78[7]
       *    SMART Command Transport (SCT) feature set
       *    SCT Write Same (AC2)
            unknown 206[7]
            unknown 206[12] (vendor specific)
Security:
    Master password revision code = 65534
        supported
    not    enabled
    not    locked
    not    frozen
    not    expired: security count
        supported: enhanced erase
    198min for SECURITY ERASE UNIT. 198min for ENHANCED SECURITY ERASE UNIT.
Logical Unit WWN Device Identifier: 5000c500a8ebeb68
    NAA        : 5
    IEEE OUI    : 000c50
    Unique ID    : 0a8ebeb68
Checksum: correct
4 進行分割槽,由於我要用這塊2T的希捷硬碟做資料盤,因此我將整塊硬碟分成一個主分割槽,不再細分成擴充套件分割槽,邏輯分割槽。現在的系統都是64位的,因此是可以支援2T的主分割槽。
~$ sudo fdisk /dev/sdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x1ab94f32.
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)

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help): m     #輸入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)

Command (m for help): p     #打印出硬碟資訊

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 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
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n       #選擇new一個分割槽
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):       #回車,預設p 主分割槽
Using default response p
Partition number (1-4, default 1): 1     # 輸入1,選擇第一個主分割槽
First sector (2048-3907029167, default 2048):    # 回車,預設起始扇區
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):   #回車,預設結束扇區
Using default value 3907029167

Command (m for help): p     #列印一下,檢視,沒有問題

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 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
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   83  Linux

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)

Command (m for help): w  #輸入w,寫入並退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
5 檢視一下所有的硬碟:
~$ sudo fdisk -l 
Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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
Disk identifier: 0x000b8bcb

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   454848511   227423232   83  Linux
/dev/sda2       454850558   488396799    16773121    5  Extended
/dev/sda5       454850560   488396799    16773120   82  Linux swap / Solaris

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 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
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   83  Linux
6 格式化硬碟,現在的Linux的檔案格式都是ext4的格式了,記得幾年前還有用ext3的格式。
~$ sudo mkfs -t ext4 /dev/sdb1 
mke2fs 1.42.9 (4-Feb-2014)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
122101760 inodes, 488378390 blocks
24418919 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
14905 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

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
7 給新硬碟寫個標籤。
~$ sudo e2label /dev/sdb1 /ext4-2T-disk-1 
8 給一個掛載點:
mkdir /home/yourname/dir 
9 編輯 /etc/fstab檔案:
gedit /etc/fstab 

or

sudo nano /etc/fstab 

在檔案的最後一行加入:

LABEL=/ext4-2T-disk-1    /home/yourname/dir    ext4    defaults    0    2
10 掛載
~$ sudo mount -a 
11 這時候,你會發現掛載的盤,普通使用者無法寫入,需要授權
~$ sudo chown -R $(whoami) /home/yourname/dir
12 擴充套件硬碟工作完成了
13 新硬碟上新建svn根目錄

/home/yourname/dir目錄下新建svn目錄,編輯 /etc/apache2/apache2.conf 新增如下內容後

<Location /svn2>                   ### need change here!!!
  DAV svn
  SVNPath /home/yourname/dir/svn   ### need change here!!!
  AuthType Basic
  AuthName "Subversion repository"
  AuthUserFile /home/svn_data/passwd
  Require valid-user
</Location>

重啟apache2伺服器

sudo service apache2 restart
14 新硬碟上新建ftp檔案共享目錄

/home/yourname/dir目錄下新建share目錄,編輯 /etc/samba/smb.conf,新增如下內容

[share_disk1]                        ### need change here!!!
    path = /home/yourname/dir/share  ### need change here!!!
    available = yes
    browseable = yes
    public = yes
    writable = yes

重啟smb伺服器

sudo service smbd restart
15 到此增加硬碟並做相關設定就結束了.

參考地址: https://blog.csdn.net/kangdehua/article/details/72637675