܍~cK( jUdZddlZddlZddlZddlmZddlmZddlm Z m Z ddl m Z ddl mZddlmZmZdd lmZdd lmZd Zd d dedegddgegdZeed<eeZdZdZdZdZdZdZdZdefdefdefdefdefd efgZ deiZ!d!Z"d"Z#d#e$d$ed%e d&ed'e%d(df d)Z&d*Z'dS)+z:Resizefs: cloud-config module which resizes the filesystemN)Logger)dedent)subputil)Cloud)Config) MetaSchema get_meta_doc) ALL_DISTROS) PER_ALWAYSnoblock cc_resizefsResizefszResize filesystema Resize a filesystem to use all avaliable space on partition. This module is useful along with ``cc_growpart`` and will ensure that if the root partition has been resized the root filesystem will be resized along with it. By default, ``cc_resizefs`` will resize the root partition and will block the boot process while the resize command is running. Optionally, the resize operation can be performed in the background while cloud-init continues running modules. This can be enabled by setting ``resize_rootfs`` to ``noblock``. This module can be disabled altogether by setting ``resize_rootfs`` to ``false``.z@resize_rootfs: false # disable root filesystem resize operationzAresize_rootfs: noblock # runs resize operation in the background)idnametitle descriptiondistrosexamples frequencyactivate_by_schema_keysmetactj|s,tjd|zr ddddd|zfSdddd|fS)Nz %s/.snapshotsbtrfs filesystemresizemax)rmount_is_read_writeospathisdir mount_pointdevpths >/usr/lib/python3/dist-packages/cloudinit/config/cc_resizefs.py _resize_btrfsr&6sk  #K 0 0 ERW]]+%66 E     k )   x DDc d|fS)N resize2fsr"s r% _resize_extr+Js   r'c d|fS)N xfs_growfsr*r"s r% _resize_xfsr.Ns + &&r'c dd|fS)Ngrowfsz-yr*r"s r% _resize_ufsr1Rs dK ((r'cddd||fS)Nzpoolonlinez-er*r"s r% _resize_zfsr5Vs Xt[& 99r'c dd|fS)Nhammer2r0r*r"s r%_resize_hammer2r8Zs x --r'cd}d} tjdd|gnB#tj$r0}|j|r||jvrYd}~dS|d}~wwxYwdS)Nzgrowfs: requested sizez.is not larger than the current filesystem sizer0z-NTF)rProcessExecutionErrorstderr startswith)r#r$ skip_start skip_containes r%_can_skip_resize_ufsr@^s*JCL 8T6*++++  % 8  z * * |qx/G/G44444G  5sA#AAArextxfsufszfsr7c|}tD](\}}||r|||cS)dS)NF)lowerRESIZE_FS_PRECHECK_CMDSitemsr<)fs_type resize_whatr$ fstype_lcifuncs r%can_skip_resizerNsf I*0022--4    " " -4 V,, , , , - 5r'cttj}|dkrutj|sV|sTtjtj}||ddS|d||dkr|d||dS| dr|d|S| d sPtj|s1d | d z}|d |||} tj |}nv#t$ri}|r-|j tjkr|d ||n/|j tjkr|d ||n|Yd}~dSd}~wwxYwtj|jsTtj|js;|r|d|d|n|d|d|dS|S)aReturn updated devpath if the devpath is a writable block device. @param devpath: Requested path to the root device we want to resize. @param info: String representing information about the requested device. @param log: Logger to which logs will be added upon error. @returns devpath or updated devpath per kernel commandline if the device path is a writable block device, returns None otherwise. z /dev/rootNz!Unable to find device '/dev/root'z.Converted /dev/root to '%s' per kernel cmdline overlayrootz)Not attempting to resize devpath '%s': %szgpt/z#We have a gpt label - just go aheadz/dev//z:'%s' doesn't appear to be a valid device path. Trying '%s'z9Device '%s' did not exist in container. cannot resize: %sz,Device '%s' did not exist. cannot resize: %szdevice 'z2' not a block device in container. cannot resize: z%' not a block device. cannot resize: )r is_containerrr existsrootdev_from_cmdline get_cmdlinewarningdebugr<lstripstatOSErrorerrnoENOENTS_ISBLKst_modeS_ISCHR)devpathinfolog container fulldevpathstatretexcs r%maybe_get_writable_device_pathrgs!##I ;w''  +D,<,>,>?? ? KK; < < <4 BGLLL- =wMMMt &!! 7888   g & &rw~~g/F/Fs 3 33  H     ''""      el22 IIK     Y%, & & KK>    Ittttt  < ( ( go1N1N    III(/7     KKK77DD"   t NsE GAGGrcfgcloudrbargsreturnct|dkr |d}ntj|dd}tj|tgs|d|dSd}tj||}|s|d|dS|\}} } | dkr5|dd} tj | }|sdS| }d |d | d |} |d | zt|| |}|sdSd} t| ||r|d | |dS| }tD]\}}||r|} n| s|d| |dS| ||}|d|| d||tkr0tjtj|jdt$||fn$tj|jdt$||fd}|tkrd}|d|| |dS)Nr resize_rootfsT)addonsz+Skipping module named %s, resizing disabledrQz)Could not determine filesystem type of %srDzdev=z mnt_point=z path=zresize_info: %sz%Skip resize filesystem type %s for %sz.Not resizing unknown filesystem type %s for %szResizing %s (%s) using %s zbackgrounded Resizing)logfuncmsgrMrjResizingResizedzResizing (via forking)z$%s root filesystem (type=%s, val=%s))lenrget_cfg_option_strtranslate_boolNOBLOCKrWget_mount_inforVsplitget_device_info_from_zpoolrgrNrFRESIZE_FS_PREFIXES_CMDSr<joinfork_cblog_time do_resize)rrhrirbrj resize_rootrJresultr$rIr#r3raresizerrKpfixroot_cmd resize_cmdactions r%handlers 4yyA~~1g -c?DII  {G9 = = = ?FFFK  c 2 2F  ?MMM%+"VWk% S!!!$077  F ,2FFKKK MDII$&''' +FD# > >F Gw V44 3Wk     I3x    % % G E   <     f--JII#['388J;O;Og MI'c"       Ic"     Fg)II.r'c tj|dS#tj$rtj|d|wxYw)Nz$Failed to resize filesystem (cmd=%s))rr:rlogexc)rrbs r%rr0sS *  % C?LLL s'?)(__doc__r[rrYloggingrtextwrapr cloudinitrrcloudinit.cloudrcloudinit.configrcloudinit.config.schemar r cloudinit.distrosr cloudinit.settingsr rwr__annotations__r&r+r.r1r5r8r@r{rGrNrgstrlistrrr*r'r%rssA@@  !!!!!!######<<<<<<<<))))))))))))    6 J  }JK!-j2 ,t  EEE(!!!'''))):::.... m K K K K !"67JJJZX XX#(X/5X=AX XXXXvr'