为系统扩充磁盘存储容量是一件非常常见的事情,特别是现在在云平台中。不像windows系统,当我们在系统中添加一块硬盘时,系统有界面提示有新硬件,你可以直接在新硬件上右键,然后格式化之后就能用了。但在linux系统中,如果你没有安装桌面系统,要能把新的硬盘使用起来还是要做一些配置的。
这里我介绍一下在云主机ubuntu系统中如何处理新加的硬盘的,具体来说分为以下6步:
1)找到新添加的硬盘设备,这个需要从系统的log里找。
[html] view plain copy
stack@ubunt:~$ dmesg |grep vd [ 0.949797] vda: vda1 vda2 [ 0.959385] vdb: unknown partition table [ 1.159555] systemd-udevd[119]: starting version 204 [ 1.442816] ext4-fs (vda1): mounted filesystem with ordered data mode. opts: (null) [ 2.189858] adding 1046524k swap on /dev/vda5. priority:-1 extents:1 across:1046524k fs [ 2.416559] ext4-fs (vda1): re-mounted. opts: errors=remount-ro [ 4.663330] systemd-udevd[361]: starting version 204
因为我这里使用的时虚拟的硬盘所以设备名是以“vd”开头的,如果你添加的是ide接口的硬盘你可以grep “hd,如果是sata/sas等scsi的硬盘,可以grep “sd。
2)使用fdisk在硬盘上创建分区。
[html] view plain copy
stack@ubunt:~$ fdisk /dev/vdb fdisk: unable to open /dev/vdb: permission denied stack@ubunt:~$ sudo fdisk /dev/vdb sudo: unable to resolve host ubunt device contains neither a valid dos partition table, nor sun, sgi or osf disklabel building a new dos disklabel with disk identifier 0x6e850859. 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) command (m for help): n partition type: p primary (0 primary, 0 extended, 4 free) e extended select (default p): p partition number (1-4, default 1): 1 first sector (2048-209715199, default 2048): 'using default value 2048 last sector, +sectors or +size{k,m,g} (2048-209715199, default 209715199): last sector, +sectors or +size{k,m,g} (2048-209715199, default 209715199): using default value 209715199 command (m for help): w the partition table has been altered! calling ioctl() to re-read partition table. syncing disks.
n表示新建一个分区,p表示创建一个主分区,“1”表示只创建一个分区,“w“表示保存分区信息。在输入分区个数之后,系统会让你配置分区的大小,直接回车选择默认的数字就行。
3)时新建的分区在系统中生效。
stack@ubunt:~$ partprobe
4)格式化新建的分区。
[html] view plain copy
stack@ubunt:~$ sudo mkfs.ext4 /dev/vdb1 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 6553600 inodes, 26214144 blocks 1310707 blocks (5.00%) reserved for the super user first data block=0 maximum filesystem blocks=4294967296 800 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 allocating group tables: done writing inode tables: done creating journal (32768 blocks): done writing superblocks and filesystem accounting information: done
5)创建硬盘挂载点,修改/etc/fstab使得硬盘能够一直挂载在系统中。
在新版本的ubuntu系统中/etc/fstab推荐使用分区的uuid来定义分区的挂载点,所以需要首先得到磁盘的uuid,这可以通过blkid命令得到。
[html] view plain copy
stack@ubunt:~$ sudo blkid -p /dev/vdb1 /dev/vdb1: uuid=7689119f-9ad7-4cf8-a7c5-0589147b3566 version=1.0 type=ext4 usage=filesystem part_entry_scheme=dos part_entry_type=0x83 part_entry_number=1 part_entry_offset=2048 part_entry_size=209713152 part_entry_disk=253:16
然后在/etc/fstab中加入下面的配置后保存,退出。
[html] view plain copy
uuid=7689119f-9ad7-4cf8-a7c5-0589147b3566 /usr/localext4 ext4 defaults 0 0
6)重启系统,然后通过df命令确认。
[html] view plain copy
stack@ubunt:~$ df /dev/vdb1 filesystem 1k-blocks used available use% mounted on /dev/vdb1 103080224 61044 97759968 1% /usr/localext4 stack@ubunt:~$ cd /usr/localext4/ stack@ubunt:/usr/localext4$ ls lost+found stack@ubunt:/usr/localext4$ touch testfile touch: cannot touch ‘testfile’: permission denied stack@ubunt:/usr/localext4$ sudo touch testfile stack@ubunt:/usr/localext4$ ls -la total 24 drwxr-xr-x 3 root root 4096 apr 15 22:53 . drwxr-xr-x 11 root root 4096 apr 15 22:03 .. drwx------ 2 root root 16384 apr 15 21:56 lost+found -rw-r--r-- 1 root root 0 apr 15 22:53 testfile
bingo!完成!
STC12C2052AD单片机控制的改进型调压电路
氢能爆发前夜:连接器新能源领域的未来较量
Laravel 5如何在中间件中获取路由参数?
RJ45以太网接口的EMC设计
创基Type-C集线器外观精巧实用性强
Ubuntu中添加新硬盘
万万没想到!白客、韩乔生、王涛、刘语熙竟然在海信成团出道
基于AT89S52单片机的简易数字示波器设计[图]
国产8k30 2x2拼接器方案(HDMI/DP/MIPI/LVDS)
如何避免门罗币Monero不会受到51%的攻击
如何自制PCB电路板,自制PCB电路板的四个步骤
AI新算法可用出租车监测城市空气污染
埃森哲携手码隆科技战略布局人工智能
电机的几个计算公式
时隔三年回归的小米平板5系列值得买吗
武汉成立一联合实验室,居然让30家传感器企业有了“最强外脑”?
博世暂时放弃生产电芯,与新势力造车企业进行积极合作
全数字计算机智能监控系统在娱乐场所的应用分析
固态电容器未来发展方向
现在手机芯片是几nm 5nm的手机有哪些