Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partitions are changed after deploying the custom image #219

Open
ajay-sudosu opened this issue Mar 12, 2024 · 9 comments
Open

Partitions are changed after deploying the custom image #219

ajay-sudosu opened this issue Mar 12, 2024 · 9 comments
Labels
invalid This doesn't seem right triaged Triaged to be addressed in a given cycle

Comments

@ajay-sudosu
Copy link

ajay-sudosu commented Mar 12, 2024

Creating a custom Ubuntu image using packer and deploying it on a server machine. Before deploying this custom image lets say I have a partitions on dev/sda and dev/sdb/test but after deploying this custom image my partitions are changed as below:
sda 8:0 0 36.4T 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 6.5G 0 part
└─ubuntu--vg-ubuntu--lv 253:0 0 6.5G 0 lvm /

It is providing 6.5G to root I dont why deployment is changing my partitions.
I am using the packer repo at: https://github.com/canonical/packer-maas.

@alexsander-souza
Copy link
Contributor

we have 3 templates for Ubuntu, two produce raw images (flat, LVM) and the other one (cloudimg) gives you a TGZ image. Raw images have a fixed partition table defined in the template, so you probably should use the cloudimg template.

@alexsander-souza alexsander-souza added the triaged Triaged to be addressed in a given cycle label Mar 12, 2024
@ajay-sudosu
Copy link
Author

ajay-sudosu commented Mar 13, 2024

Ok so cloudimg template worked fine now partitions are as it is, but is there a way I can manage it with .iso format because I have my own downloaded iso image?
I dont see any fixed partition table defined in the template for LVM?

This is the lvm template:

source "qemu" "lvm" {
boot_command = ["e", "", "autoinstall ---"]
boot_wait = "2s"
cpus = 2
disk_size = "8G"
format = "raw"
headless = var.headless
http_directory = var.http_directory
iso_checksum = "file:http://releases.ubuntu.com/${var.ubuntu_series}/SHA256SUMS"
iso_target_path = "packer_cache/${var.ubuntu_series}.iso"
iso_url = "https://releases.ubuntu.com/${var.ubuntu_series}/${var.ubuntu_lvm_iso}"
memory = 2048
qemuargs = [
["-vga", "qxl"],
["-device", "virtio-blk-pci,drive=drive0,bootindex=0"],
["-device", "virtio-blk-pci,drive=cdrom0,bootindex=1"],
["-device", "virtio-blk-pci,drive=drive1,bootindex=2"],
["-drive", "if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE.fd"],
["-drive", "if=pflash,format=raw,file=OVMF_VARS.fd"],
["-drive", "file=output-lvm/packer-lvm,if=none,id=drive0,cache=writeback,discard=ignore,format=raw"],
["-drive", "file=seeds-lvm.iso,format=raw,cache=none,if=none,id=drive1,readonly=on"],
["-drive", "file=packer_cache/${var.ubuntu_series}.iso,if=none,id=cdrom0,media=cdrom"]
]
shutdown_command = "sudo -S shutdown -P now"
ssh_handshake_attempts = 500
ssh_password = var.ssh_ubuntu_password
ssh_timeout = "45m"
ssh_username = "ubuntu"
ssh_wait_timeout = "45m"
}

build {
sources = ["source.qemu.lvm"]

provisioner "file" {
destination = "/tmp/curtin-hooks"
source = "${path.root}/scripts/curtin-hooks"
}

provisioner "shell" {
environment_vars = ["HOME_DIR=/home/ubuntu", "http_proxy=${var.http_proxy}", "https_proxy=${var.https_proxy}", "no_proxy=${var.no_proxy}"]
execute_command = "echo 'ubuntu' | {{ .Vars }} sudo -S -E sh -eux '{{ .Path }}'"
expect_disconnect = true
scripts = ["${path.root}/scripts/curtin.sh", "${path.root}/scripts/networking.sh", "${path.root}/scripts/cleanup.sh"]
}

post-processor "compress" {
output = "custom-ubuntu-lvm.dd.gz"
}
}

@alexsander-souza
Copy link
Contributor

No, you cannot use an ISO, the cloudimg template requires a pre-installed image.

In the lvm template, the storage layout is defined in ubuntu/user-data-lvm. Currently we set the layout to lvm and let Subiquity (the Ubuntu installer) to do auto-partition of the disk, but you can change this (see docs)

@ajay-sudosu
Copy link
Author

Can I forbid the subiquity not to change the existing paritititons of the machine?

This is the user-data-lvm:
#cloud-config
autoinstall:
version: 1
identity:
hostname: ubuntu
username: ubuntu
password: "$6$canonical.$0zWaW71A9ke9ASsaOcFTdQ2tx1gSmLxMPrsH0rF0Yb.2AEKNPV1lrF94n6YuPJmnUy2K2/JSDtxuiBDey6Lpa/"
keyboard:
layout: us
variant: ''
ssh:
install-server: true
storage:
grub:
update_nvram: true
swap:
size: 0
layout:
name: lvm
late-commands:
- echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' > /target/etc/sudoers.d/ubuntu
package_update: true
package_upgrade: true

Now, if I am changing the format of layout from lvm to direct , packer is not able to create image. I just don't want the partitions to change after I deploy the image created by packer.

@alexsander-souza
Copy link
Contributor

use the flat template instead, the result is a tgz-image that should work for you

@ajay-sudosu
Copy link
Author

ajay-sudosu commented Mar 19, 2024

Tried with flat file also. Actually while deploying the Custom ubuntu OS at the time of installing os I ssh into the machine and I saw my partitons were as it is like below:
sda 8:0 0 36.4T 0 disk
├─sda1 8:1 0 512M 0 part /tmp/tmpfobid504/target/boot/efi
└─sda2 8:2 0 36.4T 0 part /tmp/tmpfobid504/target
sdb 8:16 0 18.2T 0 disk
└─sdb1 8:17 0 300G 0 part /tmp/tmpfobid504/target/var/test

But when system reboots this is all gone.

Could there be an issue of cloud config that is auto configure partitions after reboot?

In tha above case I created a partition as /var/test in 'sdb' block of size 300Gb:

@alexsander-souza
Copy link
Contributor

I think there's a misconception about how disk partitioning works. MAAS won't leave the disk as they were, it will either apply the Storage Layout configured for this machine or use the partitioning defined by the image (in case you use a raw image)

@ajay-sudosu
Copy link
Author

I am confused how MAAS Ubuntu image is doing the same, MAAS provided Ubuntu image is not changing any configurations of the machines.
Can you please brief about how MAAS provided Ubuntu image was created like the way Custom image is being created using packer.

@alexsander-souza
Copy link
Contributor

Official Ubuntu images are not built using packer, but the install process is roughly the same:

  1. MAAS power on the machine
  2. machine net-boots using a ephemeral OS provided by MAAS
  3. Curtin partition the disks using MAAS-supplied storage layout
  4. Curtin mounts the disks
  5. Curtin extracts the Image into the mounted disks
  6. Curtin setups network, etc

For non-raw images (flat, cloudimg), the final disk layout should be what you see in the machines's Storage tab in MAAS, not what existed before. Please check if MAAS has the desired layout, and file a bug for MAAS if the end result is not what you set there.

@alexsander-souza alexsander-souza added the invalid This doesn't seem right label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right triaged Triaged to be addressed in a given cycle
Projects
None yet
Development

No branches or pull requests

2 participants