云主机初始化swap与数据盘
背景 当前市面上大部分的云服务器产品,在购买Linux服务器并启动后,通常只帮我们挂载了系统盘到/目录。我们所购买的数据盘并没有帮我们挂载到系统。查看内存配置,一般swap也为0。 这里我们可以利用购买的数据盘来创建swap分区与数据分区,并将他们挂载到系统中去。 操作 1,查看当前的磁盘,如下,/dev/vda为系统盘,/dev/vdb为数据盘: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 #fdisk-l Disk /dev/vda :53.7GB,53687091200bytes,104857600sectors Units=sectorsof1*512=512bytes Sectorsize(logical /physical ):512bytes/512bytes I /O size(minimum /optimal ):512bytes/512bytes Disklabel type :dos Diskidentifier:0x0008e9bc DeviceBootStartEndBlocksIdSystem /dev/vda1 *20482099199104857683Linux /dev/vda2 209920010485756651379183+83Linux Disk /dev/vdb :429.5GB,429496729600bytes,838860800sectors Units=sectorsof1*512=512bytes Sectorsize(logical /physical ):512bytes/512bytes I /O size(minimum /optimal ):512bytes/512bytes 2,对/dev/vdb进行分区操作,分割16G空间做swap,剩余空间做数据盘。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #fdisk/dev/vdb Welcometo fdisk (util-linux2.23.2). Changeswillremain in memoryonly, until youdecidetowritethem. Becarefulbeforeusingthewrite command . Devicedoesnotcontainarecognizedpartitiontable BuildinganewDOSdisklabelwithdiskidentifier0xb07be21f. Command(m for help):n Partition type : pprimary(0primary,0extended,4 free ) eextended Select(defaultp):p Partitionnumber(1-4,default1): Firstsector(2048-838860799,default2048): Usingdefaultvalue2048 Lastsector,+sectorsor+size{K,M,G}(2048-838860799,default838860799):+16G Partition1of type Linuxandofsize16GiBis set Command(m for help):n Partition type : pprimary(1primary,0extended,3 free ) eextended Select(defaultp):p Partitionnumber(2-4,default2): Firstsector(33556480-838860799,default33556480): Usingdefaultvalue33556480 Lastsector,+sectorsor+size{K,M,G}(33556480-838860799,default838860799): Usingdefaultvalue838860799 Partition2of type Linuxandofsize384GiBis set Command(m for help):w Thepartitiontablehasbeenaltered! Callingioctl()tore- read partitiontable. Syncingdisks. #fdisk-l Disk /dev/vda :53.7GB,53687091200bytes,104857600sectors Units=sectorsof1*512=512bytes Sectorsize(logical /physical ):512bytes/512bytes I /O size(minimum /optimal ):512bytes/512bytes Disklabel type :dos Diskidentifier:0x0008e9bc DeviceBootStartEndBlocksIdSystem /dev/vda1 *20482099199104857683Linux /dev/vda2 209920010485756651379183+83Linux Disk /dev/vdb :429.5GB,429496729600bytes,838860800sectors Units=sectorsof1*512=512bytes Sectorsize(logical /physical ):512bytes/512bytes I /O size(minimum /optimal ):512bytes/512bytes Disklabel type :dos Diskidentifier:0x53b4d701 DeviceBootStartEndBlocksIdSystem /dev/vdb1 2048335564791677721683Linux /dev/vdb2 3355648083886079940265216083Linux 可以看到创建了2个分区/dev/vdb1,/dev/vdb2。 3,创建swap分区,并启用: 1 2 #mkswap/dev/vdb1 #swapon/dev/vdb1 4,把/dev/vdb2格式化,并挂载到/data目录下:(这里格式成xfs文件系统) 1 2 3 #mkdir-p/data #mkfs.xfs/dev/vdb2 #mount/dev/vdb2/data 5,检查是否生效: 1 2 3 4 5 6 7 8 9 10 11 12 13 #df-kh FilesystemSizeUsedAvailUse%Mountedon /dev/vda2 49G1.7G45G4%/ devtmpfs7.8G07.8G0% /dev tmpfs7.8G07.8G0% /dev/shm tmpfs7.8G25M7.8G1% /run tmpfs7.8G07.8G0% /sys/fs/cgroup /dev/vda1 976M146M764M16% /boot tmpfs1.6G01.6G0% /run/user/0 /dev/vdb2 384G33M384G1% /data #free-m totalused free sharedbuff /cache available Mem:15885393146282486315158 6,把磁盘挂载信息写进fstab,使之开启自动挂载: 1 2 3 #vi/etc/fstab /dev/vdb1 swapswapdefaults00 /dev/vdb2 /data xfsdefaults00 本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/2065057,如需转载请自行联系原作者