Quickly restore all previously installed/removed packages

After having spent some time installing packages and removing unwanted packages, I find I’m going to have to reinstall to fix a basic configuration error with my partitioning/encryption setup. Is there a way to generate a list of all currently installed packages, then upon reinstall have the system purge any packages not on that list as well as install any missing packages?

are you sure you need to reinstall? Can’t you change the settings to your partitioning/encryption now? I doubt it. I would give more details of the problem so maybe someone could help you and if not you could always get back to reinstall.

Well, I encrypted my entire home partition rather than just a directory under home. So the ‘fix’ would be something like

  1. back up home, reboot into single user mode, format partition, check uuid of reformatted partition, edit fstab to mount home there, copy home dir back
  2. ???
  3. Profit.

What I think is going to happen is that I’ll reboot at step two, and find that the system is looking for an encrypted partition and it will just fail. So, I’m guessing I’m missing steps on editing the boot parameters maybe, or perhaps the initrd (or whatever suse uses) needs to be rebuilt. My concern is that I don’t even know what I don’t know I’m missing with step 2.

That will work.

You can probably do it all without even rebooting. Just use CTRL-ALT-F1 to get a virtual console, and login as root there. Make sure nobody is logged in, other than root (the home for root is not in “/home” so that is safe. Then, after the backup,

umount /home
cryptsetup luksClose cr_home ## check that name with what is in crypttab

Your home directory is probably mounted from “/dev/mapper/cr_home” or something similar.

The actual partition device can be found in “/etc/crypttab”. If the entry from “/etc/crypttab” is a “/dev/disk/by-id/…” then you can just use that device name in the updated “fstab”. If you are set for using UUID, then you will have to get the UUID. If you know the device name, then “blkid” can be used to find the UUID.

After a “mkfs” to format the partition, “mount /home” will get it mounted if you edited “fstab” correctly. And then restore from the backup.

I quess that regardless if you will solve your present problem with a reinstall or in another way, you original question might still be relevant to you.

This is not a ready to run solution, but you can make a list of installed packages with a command like

' | sort 

You will understand that this is just an example on what can be done using the rpm -q command. See

man rpm

on how you can variate on this.

I don’t work with encrypted partitions but if there is sufficient free space (make some termporarily if possible) isn’t it possible to simply

  • Copy the entire contents of your encrypted partition to an unencrypted partition
  • Modify fstab to mount your new, unencrypted partition as /home

Alternatively, if you don’t have enough space to permanently point your /home to the new, unencrypted partition immediately

  • Copy the contents of the encrypted partition to an external drive
  • Boot to an alternative OS (eg LiveCD)
  • Delete encrypted partition
  • Copy contents from removable drive to your on-board disk system replacing the encrypted partition
  • Modify your fstab so it points to your new unencrypted /home

No app remove/install/re-install needed.
This might be possible only because it’s the /home partition. If dealing with encypted system mounts, this might not be possible.


@nrickert - good point about not rebooting, and thanks for the luks close command, I wouldn’t have thought to do that.

@hcvv - thanks for that. I’ll do that as a back up plan in case my attempts at salvage go bad. plus. I think I see a way to make that work with the diff command to achieve what I originally asked about. I don’t know the exact commands yet, but basically use your command to get list of installed packages (list 1). Then do a re-install and take another list of all installed packages (list 2). Then run a diff between list 1 and 2, just showing items that ARE on list 1 but not list 2, and install those. Then do a second diff between list 1 and 2, just showing items that ARE on list 2 but not list 1, and remove those packages. cheers!

@tsu2 I think that’s the way I’m going on this, but I don’t have free space on the drive to do it all in place then work on resizing and such, so I’ve got to take a but more of a risky approach. I have an external USB drive though, and everything backed up with dropbox if things go horridly wrong. And I’m going to try doing it with the running system as opposed to a live cd, in fact without even rebooting as per nrickert suggestion above.