Skip to content

Instantly share code, notes, and snippets.

@dshcherb
Created October 10, 2017 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dshcherb/223ee2d08f0a382856d52e041e5c2ef8 to your computer and use it in GitHub Desktop.
Save dshcherb/223ee2d08f0a382856d52e041e5c2ef8 to your computer and use it in GitHub Desktop.
A procedure to add a root password to maas-deployed cloud images for last-resort debugging.
https://gnu-linux.org/building-ubuntu-rootfs-for-arm.html
"2) Extract the downloaded image with ‘sudo’ to allow ‘mknod’ commands to work"
# get a cloud image from here
# https://cloud-images.ubuntu.com/daily/server/xenial/
# https://cloud-images.ubuntu.com/daily/server/xenial/current/
# based on https://bazaar.launchpad.net/~maas-images-maintainers/maas-images/maas-ephemerals/view/head:/bin/img2squashfs#L161
# extract a cloud image rootfs to a directory, sudo is needed for `mknod`s to work
# doesn't have to be .tar.gz - could well unsquashfs an existing squashfs
➜ maas-images git:(master) ✗ sudo tar -C xenial -xpSf xenial-server-cloudimg-amd64-root.tar.gz --numeric-owner --xattrs "--xattrs-include=*"
# https://www.gnu.org/software/tar/manual/html_node/Extended-File-Attributes.html
# generate a hashed password
➜ python -c 'import crypt; print crypt.crypt("ubuntu", "$6$saltsalt$")'
$6$saltsalt$.XeWDrCjouuYgs/UGMlCRi7DbQGo.D1eElJrsOdTTiB3cMADnjs1koQGbOqnqfjNvuX4oBtad6mDPQUgJiwjZ1
# modify a user's password which you would like to
# e.g. to this root:$6$saltsalt$.XeWDrCjouuYgs/UGMlCRi7DbQGo.D1eElJrsOdTTiB3cMADnjs1koQGbOqnqfjNvuX4oBtad6mDPQUgJiwjZ1:17445:0:99999:7:::
➜ maas-images git:(master) ✗ sudo vim xenial/etc/shadow
➜ maas-images git:(master) ✗ sudo mksquashfs xenial/ xenial-customized.squashfs -xattrs -comp xz
Parallel mksquashfs: Using 8 processors
Creating 4.0 filesystem on xenial-customized.squashfs, block size 131072.
[=====================================================================================================================================================================================================================/] 26932/26932 100%
Exportable Squashfs 4.0 filesystem, xz compressed, data block size 131072
compressed data, compressed metadata, compressed fragments, compressed xattrs
duplicates are removed
Filesystem size 159862.76 Kbytes (156.12 Mbytes)
28.41% of uncompressed filesystem size (562606.21 Kbytes)
Inode table size 269480 bytes (263.16 Kbytes)
25.33% of uncompressed inode table size (1063690 bytes)
Directory table size 268654 bytes (262.36 Kbytes)
39.68% of uncompressed directory table size (677044 bytes)
Number of duplicate files found 1192
Number of inodes 31483
Number of files 24124
Number of fragments 1433
Number of symbolic links 4387
Number of device nodes 79
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 2893
Number of ids (unique uids + gids) 22
Number of uids 8
root (0)
man (6)
daemon (1)
dnsmasq (111)
_apt (105)
messagebus (106)
syslog (104)
dima (1000)
Number of gids 19
root (0)
video (44)
audio (29)
tty (5)
kmem (15)
disk (6)
daemon (1)
shadow (42)
crontab (107)
rtkit (114)
utmp (43)
uuidd (113)
usermetrics (111)
staff (50)
nogroup (65534)
adm (4)
syslog (108)
mail (8)
dima (1000)
# take a look at the result
unsquashfs -l xenial-customized.squashfs | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment