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

 

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