ubuntu服務器創建用戶並且分配磁盤空間

創建用戶

sudo adduser test  //創建
sudo adduser test sudo //給與新創建用戶root權限(可選)
sudo smbpasswd –a test //創建samba用戶,可以方便windows訪問

爲用戶分配磁盤空間

利用fdisk命令進行磁盤分區,以下是相關參數:

Options:
 -b, --sector-size <size>      physical and logical sector size
 -B, --protect-boot            don't erase bootbits when create a new label
 -c, --compatibility[=<mode>]  mode is 'dos' or 'nondos' (default)
 -L, --color[=<when>]          colorize output (auto, always or never)
                                 colors are enabled by default
 -l, --list                    display partitions end exit  //list當前系統中所有磁盤空間
 -o, --output <list>           output columns
 -t, --type <type>             recognize specified partition table type only
 -u, --units[=<unit>]          display units: 'cylinders' or 'sectors' (default)
 -s, --getsz                   display device size in 512-byte sectors [DEPRECATED]
     --bytes                   print SIZE in bytes rather than in human readable format

 -C, --cylinders <number>      specify the number of cylinders
 -H, --heads <number>          specify the number of heads
 -S, --sectors <number>        specify the number of sectors per track

 -h, --help     display this help and exit
 -V, --version  output version information and exit

1. 選擇需要分區的磁盤,李永命令sudo fdisk -l查看

這裏我們選擇磁盤/dev/sda分區,由上圖可知,該磁盤已分兩個分區。

2.磁盤分區

sudo fdisk /dev/sda

選擇參數n,新建一個分區

這裏,選擇合適的分區大小,這裏分爲40G,K爲KB,M爲MB,G爲GB,T爲TB,P爲PB。

3. 格式化分區

4. 掛載分區到用戶

sudo mount -t ext4 /dev/sda3/  /home/test

利用df -h命令查看掛載情況

最後,爲了在開機自動掛載分區,需要在/etc/fstab中添加掛載記錄

echo "/dev/sda3       /home/test       ext4     defaults      0        2 " >> /etc/fstab

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章