I am trying to format some EBS volumes on an AWS EC2 instance by supplying user data to the cloud-init program. I would prefer to use the shell script format, not the YAML-based cloud config format. Here is my current user data script:
#!/bin/bash
# Format EBS volumes
yum install -y xfsprogs
parted /dev/sdb mktable gpt
parted -a optimal /dev/sdb mkpart primary xfs 0% 100%
parted /dev/sdb name 1 p4db
mkfs -t xfs /dev/sdb1
xfs_admin -L p4db /dev/sdb1
where /dev/sdb refers to an EBS volume attached using the launch wizard. Here is the log output from /var/log/cloud-init-output.log:
Information: You may need to update /etc/fstab.
Information: You may need to update /etc/fstab.
/dev/sdb1: No such file or directory
Usage: mkfs.xfs
/* blocksize */ [-b log=n|size=num]
/* metadata */ [-m crc=0|1,finobt=0|1]
/* data subvol */ [-d agcount=n,agsize=n,file,name=xxx,size=num,
(sunit=value,swidth=value|su=num,sw=num|noalign),
sectlog=n|sectsize=num
/* force overwrite */ [-f]
/* inode size */ [-i log=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
projid32bit=0|1]
/* no discard */ [-K]
/* log subvol */ [-l agnum=n,internal,size=num,logdev=xxx,version=n
sunit=value|su=num,sectlog=n|sectsize=num,
lazy-count=0|1]
/* label */ [-L label (maximum 12 characters)]
/* naming */ [-n log=n|size=num,version=2|ci,ftype=0|1]
/* no-op info only */ [-N]
/* prototype file */ [-p fname]
/* quiet */ [-q]
/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */ [-s log=n|size=num]
/* version */ [-V]
devicename
<devicename> is required unless -d name=xxx is given.
<num> is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxx KiB),
xxxm (xxx MiB), xxxg (xxx GiB), xxxt (xxx TiB) or xxxp (xxx PiB).
<value> is xxx (512 byte blocks).
/dev/sdb1: No such file or directory
fatal error -- couldn't initialize XFS library
Sep 09 18:40:58 cloud-init[2518]: util.py[WARNING]: Failed running /var/lib/cloud/instance/scripts/part-001 [1]
Sep 09 18:40:58 cloud-init[2518]: cc_scripts_user.py[WARNING]: Failed to run module scripts-user (scripts in /var/lib/cloud/instance/scripts)
Sep 09 18:40:58 cloud-init[2518]: util.py[WARNING]: Running module scripts-user (<module 'cloudinit.config.cc_scripts_user' from '/usr/lib/python2.7/dist-packages/cloudinit/config/cc_scripts_user.pyc'>) failed
Cloud-init v. 0.7.6 finished at Fri, 09 Sep 2016 18:40:58 +0000. Datasource DataSourceEc2. Up 145.89 seconds
So apparently, all of the calls to parted
are working just fine, but the calls to mkfs
( mkfs.xfs
) and xfs_admin
are not. How is parted
able to format my /dev/sdb drive without issue but the XFS programs think that it doesn't exist? How can I correctly partition and format a drive using the cloud init shell format? Any insights are much appreciated!
Thanks to @Vorsprung's comment, I realized that the issue was in the calls to parted
). This command was expecting user feedback, which of course is not allowed during cloud-init. By adding the -s
option to my parted
calls, everything works fine :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.