每天进步一点点:在Amazon AWS的EBS卷上使用GPT分区方案
hive-105017·@oflyhigh·
0.000 HBD每天进步一点点:在Amazon AWS的EBS卷上使用GPT分区方案
因为工作关系,需要在Amazon AWS的EBS卷上使用GPT分区方案,最初我想的比较简单,以为直接把MBR转换成GPT就中了。结果在测试机上一试,擦,连系统带数据都搞没了。  (图源 :[pixabay](https://pixabay.com/)) 接下来就试了几种办法,无一例外的失败,最后想到的方案就是使用两个EBS卷:一个用作系统继续用MBR方案,另外一个做数据盘使用GPT方案。这样比直接使用一个EBS卷更加灵活方便,毕竟不用考虑启动分区等诸多问题。 首先创建个EC2实例,这个按自己的需求来就可以,使用的EBS卷不用很大,能装系统就行,唯一需要注意的就是要记录或者选择一下区域,新的EBS卷要建到同一个区域下。 # 附加GPT分区方案的EBS卷 接下来创建一个新的EBS卷,注意一下空间和区域: > 创建完之后,我们就会多出来一个可用的EBS卷: > 然后将其挂载到之前建立的EC2实例上: > 之后使用`sudo fdisk -l`就会发现我们新挂载的EBS卷: > 接下来我使用`sudo fdisk /dev/xvdf`的`g`指令来创建GPT分区表: > 用`w`写入,看起来一切正常,再使用`sudo fdisk -l`查看实例上的两个EBS卷: > 再用`fdisk`创建个新的分区并写入,之后是这个样子: > 如果这时我们尝试将其mount到目录上: >`sudo mkdir /home2` `sudo mount /dev/xvdf1 /home2` 就会出类似如下错误: >mount: /home2: wrong fs type, bad option, bad superblock on /dev/xvdf1, missing codepage or helper program, or other error. 原因是我们有磁盘有分区,但是分区上还没有文件系统呢(相当于Windows的还没格式化)。 # 创建文件系统 & 自动mount 解决之前的问题很简单,使用`sudo mkfs.ext4 /dev/xvdf1`创建文件系统后一切正常。 > 记录一下文件系统的UUID(如若忘记,可用使用`sudo blkid`找回。 然后为了避免我们每次都需要手工挂载,我们编辑一下`fstab`文件实现自动挂载: >`sudo vi /etc/fstab` 添加如下内容: >`UUID=6e3fc6a2-b24c-43d6-befc-0b92a4297bfe /backup ext4 defaults 0 0` 这样就一切OK啦。 # 扩容 在EBS上将空间调整喂100G以后,回到系统中,出现`GPT PMBR size mismatch`的问题: > 使用`w`指令写入后,出现如下错误: >`fdisk: failed to write disklabel: Invalid argument` 使用`sudo gdisk /dev/xvdf`解决,早知如此,早使用`gdisk`就好了,哎: > 然后扩容分区空间: >`sudo growpart /dev/xvdf 1` 提示如下: >CHANGED: partition=1 start=2048 old: size=20969439 end=20971487 new: size=209713119,end=209715167 再扩容文件系统: >`sudo resize2fs /dev/xvdf1` 再使用`df -lh`查看文件系统空间占用: > 虽然搞不懂那5G空间哪里去了,不过貌似这样已经很完美了。 # 相关链接 * [Extending a Linux file system after resizing a volume](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/recognize-expanded-volume-linux.html) * [How do I convert my EC2 Ubuntu instance's default MBR partitioning scheme to GPT in order to bypass the 2 TiB limit for MBR partitions on my EBS volume?](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-ubuntu-convert-mbr-to-gpt/) * [How to correct GPT table and GPT PMBR](https://ubuntuforums.org/showthread.php?t=2277232)
👍 eval, laissez-faire, freedomteam2019, crokkon, curx, boneym, funnyman, eliel, alphacore, furious-one, gniksivart, codingdefined, stinawog, ernick, accelerator, adityajainxds, ofildutemps, sustainablelivin, steem.services, darthgexe, vcs, infinite-love, ajks, comunidadactiva, intacto, megalithic, bert0, ebargains, frankk, sidwrites, rycharde, giftgiver, improv, sam99, glastar, smileyboy, visionaer3003, hatschi0773, dagobert007, rishi556, deathwing, edicted, cadawg, foxon, mehmetfix, equeqtra, self-help.dev, hextech, wlslink, raven.icu, hivecur2, privex, gerber, nealmcspadden, polish.hive, dcityrewards, ezzy, exyle, someguy123, emrebeyler, steem.leo, mice-k, hivecur, daan, iansart, shitsignals, felander, roleerob, purefood, pkocjan, bestboom, freddio, themightyvolcano, swisswitness, dalz, dlike, engrave, bobby.madagascar, ldp, permaculturedude, mfblack, threejay, shimozurdo, milu-the-dog, asteroids, maxuvd, curamax, netaterra, dune69, followjohngalt, cakemonster, samsemilia7, triplea.bot, beta500, joele, caladan, ladysalsa, goodcontentbot, firefuture, ribary, benedict08, dine77, jimcustodio, sweetkathy, miketr, mafia.wallet, vxc, gerbo, berthold, investyourvote, usainvote, abitcoinskeptic, deanliu, gringalicious, girolamomarotta, soufianechakrouf, thenightflier, fullofhope, hymanadkins, steempostitalia, heidi71, zaragast, marcolino76, kytka, icon123456, nautilus-up, nextgen622, ew-and-patterns, travelgirl, competeapp, unpopular, kimzwarch, japanguide, stupid, justinashby, jywahaha, discohedge, ffcrossculture, itchyfeetdonica, voxmortis, pet.society, suonghuynh, smartvote, freakeao, ioioioioi, sudefteri, thegames, dailyke20, tmps, arcange, exec, upfundme, laoyao, blackbunny, lingfei, kahvesizlik, vida-blanca, somebody, midnightoil, bidnat, yulan, helene, fengchao, xiaohui, oflyhigh, ethansteem, rasalom, steemaction, policewala, digital-wisdom, mark-waser, aafeng, ethical-ai, jwaser, bwaser, ellepdub, herpetologyguy, morgan.waser, strong-ai, technoprogressiv, botante, steemitboard, lemooljiang, fjcalduch, roberto58, skysunny, timool, carrotliu, cn-book, cn-movie, steemjiang, starnote, moochain.net, lucknie, dumping, metten, vivia, xiaoli, altonos, moochain.com, liebin, bettyliu, lemool, younggle, dinggle, moocer, steem-zh, youngoole, imooc, openbazzar, hive-224466, annabellenoelle, coursechain, wikicoin, starchain, steemzh, steemipfs, raphaelle, andrewnoel, cn-malaysia, pollygonewild, jacktan, yumisee, pizzapai, liewsc, tanzy, sunai, bobdavids, jacoblai, foodblogresteem, iipoh06, yikloongye, yethui, moleah, joeliew, riczlook, hkit98, watersoo, vamos-amigo, elvinmas001, livingfree, created, forykw, hiveyoda, hive-108278, beerlotto, chocolatelover, goodcontentbot1, alinakot, chenlocus, bergelmirsenpai, stevenmosoes, payroll, lizachong, seikatsumkt, winniex, logic, steemcleaners, ahlawat, jingjing1616, drag33, lovequeen, joythewanderer, etherpunk, investegg, processieruben, susanli3769, oldman28, ipfsxiaoma, evahe, da-dawn, ace108, sanjeev021, sweetsssj, abit, portraits, akhyar23, wallytiteuf, rivalhw, cn-reader, fundurian, adm,